From 0337805ec3fb1f1825dcd739f5065faf0855a40c Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Mon, 19 Jul 2021 16:15:53 +0000 Subject: [PATCH] sync with 9front --- export | 1 - fetch.c | 68 ++++++++++++++++++++++++++++++++++++++------------------- init | 2 +- mkfile | 6 +++++ pack.c | 17 +++++++-------- 5 files changed, 60 insertions(+), 34 deletions(-) diff --git a/export b/export index 145e625..1c062b9 100755 --- a/export +++ b/export @@ -41,7 +41,6 @@ for(c in $commits){ if(test -d $cp/tree) bind $cp/tree b - echo From $c echo From: `{cat $cp/author} echo Date: `{date -um `{mtime $cp/author | awk '{print $1}'}} <$cp/msg awk ' diff --git a/fetch.c b/fetch.c index 727cc3c..16b060d 100644 --- a/fetch.c +++ b/fetch.c @@ -5,7 +5,6 @@ char *fetchbranch; char *upstream = "origin"; -char *packtmp = ".git/objects/pack/fetch.tmp"; int listonly; int @@ -111,7 +110,7 @@ mkoutpath(char *path) for(p=strchr(s+1, '/'); p; p=strchr(p+1, '/')){ *p = 0; if(access(s, AEXIST) != 0){ - fd = create(s, OREAD, DMDIR | 0755); + fd = create(s, OREAD, DMDIR | 0775); if(fd == -1) return -1; close(fd); @@ -162,13 +161,30 @@ handlecaps(char *caps) } } +void +fail(char *pack, char *idx, char *msg, ...) +{ + char buf[ERRMAX]; + va_list ap; + + va_start(ap, msg); + snprint(buf, sizeof(buf), msg, ap); + va_end(ap); + + remove(pack); + remove(idx); + fprint(2, "%s", buf); + exits(buf); +} + int -fetchpack(Conn *c, int pfd, char *packtmp) +fetchpack(Conn *c) { - char buf[Pktmax], idxtmp[256], *sp[3]; + char buf[Pktmax], *sp[3]; + char *packtmp, *idxtmp, **ref; Hash h, *have, *want; int nref, refsz, first; - int i, n, req; + int i, n, req, pfd; vlong packsz; Object *o; @@ -177,6 +193,7 @@ fetchpack(Conn *c, int pfd, char *packtmp) 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) @@ -197,14 +214,15 @@ fetchpack(Conn *c, int pfd, char *packtmp) 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){ @@ -249,6 +267,15 @@ fetchpack(Conn *c, int pfd, char *packtmp) sysfatal("read: %r"); buf[n] = 0; + if((packtmp = smprint(".git/objects/pack/fetch.%d.pack", getpid())) == nil) + sysfatal("smprint: %r"); + if((idxtmp = smprint(".git/objects/pack/fetch.%d.idx", getpid())) == nil) + sysfatal("smprint: %r"); + if(mkoutpath(packtmp) == -1) + sysfatal("could not create %s: %r", packtmp); + if((pfd = create(packtmp, ORDWR, 0664)) == -1) + sysfatal("could not create %s: %r", packtmp); + fprint(2, "fetching...\n"); packsz = 0; while(1){ @@ -259,19 +286,20 @@ fetchpack(Conn *c, int pfd, char *packtmp) sysfatal("fetch packfile: %r"); packsz += n; } + closeconn(c); if(seek(pfd, 0, 0) == -1) - sysfatal("packfile seek: %r"); + fail(packtmp, idxtmp, "packfile seek: %r"); if(checkhash(pfd, packsz, &h) == -1) - sysfatal("corrupt packfile: %r"); + fail(packtmp, idxtmp, "corrupt packfile: %r"); close(pfd); - n = strlen(packtmp) - strlen(".tmp"); - memcpy(idxtmp, packtmp, n); - memcpy(idxtmp + n, ".idx", strlen(".idx") + 1); if(indexpack(packtmp, idxtmp, h) == -1) - sysfatal("could not index fetched pack: %r"); + fail(packtmp, idxtmp, "could not index fetched pack: %r"); if(rename(packtmp, idxtmp, h) == -1) - sysfatal("could not rename indexed pack: %r"); + 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]); return 0; } @@ -287,7 +315,6 @@ usage(void) void main(int argc, char **argv) { - int pfd; Conn c; ARGBEGIN{ @@ -302,14 +329,9 @@ main(int argc, char **argv) if(argc != 1) usage(); - if(mkoutpath(packtmp) == -1) - sysfatal("could not create %s: %r", packtmp); - if((pfd = create(packtmp, ORDWR, 0644)) == -1) - sysfatal("could not create %s: %r", packtmp); - if(gitconnect(&c, argv[0], "upload") == -1) sysfatal("could not dial %s: %r", argv[0]); - if(fetchpack(&c, pfd, packtmp) == -1) + if(fetchpack(&c) == -1) sysfatal("fetch failed: %r"); closeconn(&c); exits(nil); diff --git a/init b/init index 7eca4ce..50fa027 100755 --- a/init +++ b/init @@ -20,7 +20,7 @@ if(~ $#upstream 0){ } mkdir -p $dir/.git/refs/^(heads remotes) -mkdir -p $dir/.git/fs +mkdir -p $dir/.git/^(fs objects) >$dir/.git/config { echo '[core]' echo ' repositoryformatversion = p9.0' diff --git a/mkfile b/mkfile index 610d3af..891a2ae 100644 --- a/mkfile +++ b/mkfile @@ -51,6 +51,12 @@ install:V: mk $MKFLAGS $i.install for (i in $RC) mk $MKFLAGS $i.rcinstall + cp git.1.man /sys/man/1/git + cp gitfs.4.man /sys/man/4/gitfs + cp common.rc /sys/lib/git/common.rc + +uninstall:V: + rm -rf $BIN /sys/lib/git /sys/man/1/git /sys/man/4/gitfs %.rcinstall:V: cp $stem $BIN/$stem diff --git a/pack.c b/pack.c index 2ffcdec..c5519c7 100644 --- a/pack.c +++ b/pack.c @@ -197,23 +197,22 @@ loadpack(Packf *pf, char *name) } } if((ifd = open(buf, OREAD)) == -1) - goto error; - if((d = dirfstat(ifd)) == nil) - goto error; + return -1; + if((d = dirfstat(ifd)) == nil){ + close(ifd); + return -1; + } pf->nidx = d->length; pf->idx = emalloc(pf->nidx); if(readn(ifd, pf->idx, pf->nidx) != pf->nidx){ + close(ifd); free(pf->idx); free(d); - goto error; + return -1; } + close(ifd); free(d); return 0; - -error: - if(ifd != -1) - close(ifd); - return -1; } static void -- 2.45.2