From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 16903 invoked from network); 26 Jul 2021 00:29:41 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 26 Jul 2021 00:29:41 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 1ess; Sun Jul 25 20:23:52 -0400 2021 Received: from abbatoir.myfiosgateway.com (pool-74-108-56-225.nycmny.fios.verizon.net [74.108.56.225]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 9f0cd10d (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Sun, 25 Jul 2021 17:23:29 -0700 (PDT) Message-ID: <07AAA303A77F5CCCA03612746744A0DC@eigenstate.org> To: 9front@9front.org Date: Sun, 25 Jul 2021 20:23:28 -0400 From: ori@eigenstate.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: immutable realtime browser Subject: [9front] git/fetch: be more robust Reply-To: 9front@9front.org Precedence: bulk currently, git/fetch prints the refs to update before it fully fetches the pack files; this can lead to updates to the refs before we're 100% certain that the objects are present. This change prints the updates after the packfile has been successfully indexed. I've been running with this for a bit, and it passes the tests in gits://shithub.us/ori/regress so I'm reasonably confident it works, but considering that bugs in the past have caused major pain -- test reports wanted: --- //.git/fs/object/28f76455d39d990b47c6e46e18158f0a9ba09d25/tree/sys/src/cmd/git/fetch.c +++ sys/src/cmd/git/fetch.c @@ -181,7 +181,7 @@ fetchpack(Conn *c) { char buf[Pktmax], *sp[3]; - char *packtmp, *idxtmp; + char *packtmp, *idxtmp, **ref; Hash h, *have, *want; int nref, refsz, first; int i, n, req, pfd; @@ -193,6 +193,7 @@ first = 1; have = eamalloc(refsz, sizeof(have[0])); want = eamalloc(refsz, sizeof(want[0])); + ref = eamalloc(refsz, sizeof(ref[0])); while(1){ n = readpkt(c, buf, sizeof(buf)); if(n == -1) @@ -213,14 +214,15 @@ continue; if(refsz == nref + 1){ refsz *= 2; - have = erealloc(have, refsz * sizeof(have[0])); - want = erealloc(want, refsz * sizeof(want[0])); + have = earealloc(have, refsz, sizeof(have[0])); + want = earealloc(want, refsz, sizeof(want[0])); + ref = earealloc(ref, refsz, sizeof(ref[0])); } + ref[nref] = estrdup(sp[1]); if(hparse(&want[nref], sp[0]) == -1) sysfatal("invalid hash %s", sp[0]); - if (resolveremote(&have[nref], sp[1]) == -1) + if (resolveremote(&have[nref], ref[nref]) == -1) memset(&have[nref], 0, sizeof(have[nref])); - print("remote %s %H local %H\n", sp[1], want[nref], have[nref]); nref++; } if(listonly){ @@ -295,6 +297,14 @@ fail(packtmp, idxtmp, "could not index fetched pack: %r"); if(rename(packtmp, idxtmp, h) == -1) fail(packtmp, idxtmp, "could not rename indexed pack: %r"); + + for(i = 0; i < nref; i++){ + print("remote %s %H local %H\n", ref[i], want[i], have[i]); + free(ref[i]); + } + free(ref); + free(want); + free(have); return 0; }