ref: 76a97a83e75530676aeee41e1747724458038623
parent: ec28e68d5f5d72748d4b2d0be2861956b856ef4f
author: glenda <glenda@9front.local>
date: Sat Jun 29 21:33:11 EDT 2019
Improve the way that push works. Correctly keep the branches in the remote dir up to date, and don't fetch things we already have if the remote is behind us.
--- a/fetch.c
+++ b/fetch.c
@@ -39,7 +39,7 @@
if(r == -1 && strstr(buf, "ref:") == buf)
return resolveremote(h, buf + strlen("ref:"));
-
+ print("resolved remote: %s\n", ref);
return r;
}
@@ -138,13 +138,12 @@
int
fetchpack(int fd, int pfd, char *packtmp)
{
- char buf[65536];
- char idxtmp[256];
- char *sp[3];
+ char buf[65536], idxtmp[256], *sp[3];
Hash h, *have, *want;
int nref, refsz;
int i, n, req;
vlong packsz;
+ Object *o;
nref = 0;
refsz = 16;
@@ -180,6 +179,10 @@
for(i = 0; i < nref; i++){
if(memcmp(have[i].h, want[i].h, sizeof(have[i].h)) == 0)
continue;
+ if((o = readobject(want[i])) != nil){
+ unref(o);
+ continue;
+ }
n = snprint(buf, sizeof(buf), "want %H", want[i]);
print("want %H\n", want[i]);
if(writepkt(fd, buf, n) == -1)
--- a/proto.c
+++ b/proto.c
@@ -121,7 +121,6 @@
int pid, pfd[2];
char cmd[64];
- print("dialing via ssh %s...\n", host);
if(pipe(pfd) == -1)
sysfatal("unable to open pipe: %r");
pid = fork();
@@ -147,7 +146,6 @@
int fd, l;
ds = netmkaddr(host, "tcp", port);
- print("dialing %s...\n", ds);
fd = dial(ds, nil, nil, nil);
if(fd == -1)
return -1;
--- a/push
+++ b/push
@@ -2,6 +2,9 @@
rfork en
+nl='
+'
+
if(! cd `{git/conf -r})
exit 'not in git repository'
@@ -48,6 +51,23 @@
exit upstream
}
if(~ $sendall '')
- git/send -b $branch $remove $remote
+ updates=`$nl{git/send -b $branch $remove $remote}
if not
- git/send $remove -a $remote
+ updates=`$nl{git/send $remove -a $remote}
+if(! ~ $status '')
+ exit $status
+
+for(ln in $updates){
+ u=`{echo $ln}
+ refpath=`{echo $u(2) | sed 's@^refs/heads/@.git/refs/remotes/@g'}
+ switch($u(1)){
+ case update;
+ echo $u(4) > $refpath
+ echo $u(2)^':' $u(3) '=>' $u(4)
+ case delete;
+ echo $u(2)^': removed'
+ rm -f $refpath
+ case uptodate;
+ echo $u(2)^': up to date'
+ }
+}
--- a/send.c
+++ b/send.c
@@ -64,8 +64,6 @@
case GTree:
for(i = 0; i < o->tree->nent; i++){
e = &o->tree->ent[i];
- if(e->modref)
- print("wtf, a link? %s\n", e->name);
if ((s = readobject(e->h)) == nil)
sysfatal("could not read entry %H: %r", e->h);
pack(send, skip, s);
@@ -288,10 +286,9 @@
int
sendpack(int fd)
{
- char buf[65536];
- char *sp[3], *p;
+ int i, n, r, nupd, nsp, updating;
+ char buf[65536], *sp[3];
Update *upd, *u;
- int i, n, nupd, nsp, updating;
if((nupd = readours(&upd)) == -1)
sysfatal("read refs: %r");
@@ -322,14 +319,14 @@
break;
}
if(hasheq(&u->ours, &Zhash)){
- print("%s: deleting\n", u->ref);
+ print("removed %s\n", u->ref);
continue;
}
if(hasheq(&u->theirs, &u->ours)){
- print("%s: up to date\n", u->ref);
+ print("uptodate %s\n", u->ref);
continue;
}
- print("%s: %H => %H\n", u->ref, u->theirs, u->ours);
+ print("update %s %H %H\n", u->ref, u->theirs, u->ours);
n = snprint(buf, sizeof(buf), "%H %H %s", u->theirs, u->ours, u->ref);
/*
@@ -351,6 +348,7 @@
updating = 1;
}
flushpkt(fd);
+ r = 0;
if(updating){
if(writepack(fd, upd, nupd) == -1)
return -1;
@@ -363,15 +361,20 @@
continue;
if(nsp < 3)
sp[2] = "";
+ /*
+ * Only report errors; successes will be reported by
+ * surrounding scripts.
+ */
if(strcmp(sp[0], "unpack") == 0 && strcmp(sp[1], "ok") != 0)
fprint(2, "unpack %s\n", sp[1]);
- else if(strcmp(sp[0], "ok") == 0)
- fprint(2, "%s: updated\n", sp[1]);
else if(strcmp(sp[0], "ng") == 0)
fprint(2, "failed update: %s\n", sp[1]);
+ else
+ continue;
+ r = -1;
}
}
- return 0;
+ return r;
}
void