--- /mnt/git/object/deb7402afe2b7b4a047760442e1cfe6d1891bf47/tree/git.h +++ git.h @@ -248,7 +248,7 @@ Object *clearedobject(Hash, int); void parseobject(Object *); int indexpack(char *, char *, Hash); -int writepack(int, Object **, int, Hash*); +int writepack(int, Hash*, int, Hash*, int, Hash*); int hasheq(Hash *, Hash *); Object *ref(Object *); void unref(Object *); --- /mnt/git/object/deb7402afe2b7b4a047760442e1cfe6d1891bf47/tree/pack.c +++ pack.c @@ -1171,6 +1171,8 @@ { Objmeta *m; + if(meta == nil) + return; m = emalloc(sizeof(Objmeta)); m->obj = o; m->path = estrdup(path); @@ -1243,23 +1245,32 @@ } static int -readmeta(Object **commits, int ncommits, Objmeta ***m) +readmeta(Hash *theirs, int ntheirs, Hash *ours, int nours, Objmeta ***m) { + Object **obj; Objset has; - int i, nm; + int i, nm, nobj; *m = nil; nm = 0; osinit(&has); - for(i = 0; i < ncommits; i++){ - dprint(2, "loading commit %H\n", commits[i]->hash); - if(loadcommit(m, &nm, &has, commits[i]->hash) == -1){ - free(*m); - return -1; - } - } + if(findtwixt(theirs, ntheirs, ours, nours, &obj, &nobj) == -1) + sysfatal("load twixt: %r"); + if(nobj == 0) + return 0; + for(i = 0; i < ntheirs; i++) + if(!hasheq(&theirs[i], &Zhash)) + if(loadcommit(m, &nm, &has, theirs[i]) == -1) + goto out; + for(i = 0; i < nobj; i++) + if(loadcommit(m, &nm, &has, obj[i]->hash) == -1) + goto out; osclear(&has); return nm; +out: + osclear(&has); + free(*m); + return -1; } static int @@ -1561,14 +1572,16 @@ } int -writepack(int fd, Object **obj, int nobj, Hash *h) +writepack(int fd, Hash *theirs, int ntheirs, Hash *ours, int nours, Hash *h) { Objmeta **meta; int i, r, nmeta; dprint(1, "reading meta\n"); - if((nmeta = readmeta(obj, nobj, &meta)) == -1) + if((nmeta = readmeta(theirs, ntheirs, ours, nours, &meta)) == -1) return -1; + if(nmeta == 0) + return 0; dprint(1, "picking deltas\n"); pickdeltas(meta, nmeta); dprint(1, "generating pack\n"); --- /mnt/git/object/deb7402afe2b7b4a047760442e1cfe6d1891bf47/tree/repack.c +++ repack.c @@ -47,9 +47,8 @@ main(int argc, char **argv) { char path[128], **names; - int fd, nobj, nrefs; + int fd, nrefs; Hash *refs, h; - Object **obj; Dir rn; ARGBEGIN{ @@ -64,13 +63,10 @@ refs = nil; if((nrefs = listrefs(&refs, &names)) == -1) sysfatal("load refs: %r"); - if(findtwixt(refs, nrefs, nil, 0, &obj, &nobj) == -1) - sysfatal("load twixt: %r"); if((fd = create(TMPPATH("pack.tmp"), OWRITE, 0644)) == -1) sysfatal("open %s: %r", TMPPATH("pack.tmp")); - if(writepack(fd, obj, nobj, &h) == -1) + if(writepack(fd, refs, nrefs, nil, 0, &h) == -1) sysfatal("writepack: %r"); - free(obj); if(indexpack(TMPPATH("pack.tmp"), TMPPATH("idx.tmp"), h) == -1) sysfatal("indexpack: %r"); close(fd); --- /mnt/git/object/deb7402afe2b7b4a047760442e1cfe6d1891bf47/tree/send.c +++ send.c @@ -99,10 +99,10 @@ int sendpack(Conn *c) { - int i, n, r, idx, nupd, nobj, nsp, send, first; + int i, n, r, idx, nupd, nsp, send, first; char buf[Pktmax], *sp[3]; Hash h, *theirs, *ours; - Object *a, *b, *p, **obj; + Object *a, *b, *p; char **refs; Capset cs; @@ -187,9 +187,7 @@ if(!send) print("nothing to send\n"); if(send){ - if(findtwixt(ours, nupd, theirs, nupd, &obj, &nobj) == -1) - return -1; - if(writepack(c->wfd, obj, nobj, &h) == -1) + if(writepack(c->wfd, ours, nupd, theirs, nupd, &h) == -1) return -1; if(cs.report && readphase(c) == -1) return -1; --- /mnt/git/object/deb7402afe2b7b4a047760442e1cfe6d1891bf47/tree/serve.c +++ serve.c @@ -138,17 +138,13 @@ servpack(Conn *c) { Hash *head, *tail, h; - Object **obj; - int nhead, ntail, nobj; + int nhead, ntail; dprint(1, "negotiating pack\n"); if(servnegotiate(c, &head, &nhead, &tail, &ntail) == -1) sysfatal("negotiate: %r"); - dprint(1, "finding twixt\n"); - if(findtwixt(head, nhead, tail, ntail, &obj, &nobj) == -1) - sysfatal("twixt: %r"); dprint(1, "writing pack\n"); - if(nobj > 0 && writepack(c->wfd, obj, nobj, &h) == -1) + if(writepack(c->wfd, head, nhead, tail, ntail, &h) == -1) sysfatal("send: %r"); return 0; }