summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2021-06-13 12:48:49 +0000
committerOri Bernstein <ori@eigenstate.org>2021-06-13 12:48:49 +0000
commit8ab397c23c2fdbbe64d10f756bb4eb15aab54075 (patch)
tree6630935ebe71b473a067408a48b31ad07216110b
parentc9bf96e3e04a46122ec33840d69ae2341cebd50c (diff)
downloadplan9front-8ab397c23c2fdbbe64d10f756bb4eb15aab54075.tar.xz
git/push, git/send: get better about erroring out early
git/push died within a subshell, which prevented the whole program from exiting, and lead to an incorrect ref update line that confused people. git/send would eventually error out, but would push all the data before that happened; this was annoying.
-rw-r--r--sys/src/cmd/git/pack.c39
-rwxr-xr-xsys/src/cmd/git/push2
2 files changed, 27 insertions, 14 deletions
diff --git a/sys/src/cmd/git/pack.c b/sys/src/cmd/git/pack.c
index 12215bdcd..50077ba27 100644
--- a/sys/src/cmd/git/pack.c
+++ b/sys/src/cmd/git/pack.c
@@ -1202,16 +1202,19 @@ indexpack(char *pack, char *idx, Hash ph)
while(c < nobj && (obj[c]->hash.h[0] & 0xff) <= i)
c++;
PUTBE32(buf, c);
- hwrite(f, buf, 4, &st);
+ if(hwrite(f, buf, 4, &st) == -1)
+ goto error;
}
for(i = 0; i < nobj; i++){
o = obj[i];
- hwrite(f, o->hash.h, sizeof(o->hash.h), &st);
+ if(hwrite(f, o->hash.h, sizeof(o->hash.h), &st) == -1)
+ goto error;
}
for(i = 0; i < nobj; i++){
PUTBE32(buf, obj[i]->crc);
- hwrite(f, buf, 4, &st);
+ if(hwrite(f, buf, 4, &st) == -1)
+ goto error;
}
nbig = 0;
@@ -1222,15 +1225,18 @@ indexpack(char *pack, char *idx, Hash ph)
PUTBE32(buf, (1ull << 31) | nbig);
nbig++;
}
- hwrite(f, buf, 4, &st);
+ if(hwrite(f, buf, 4, &st) == -1)
+ goto error;
}
for(i = 0; i < nobj; i++){
if(obj[i]->off >= (1ull<<31)){
PUTBE64(buf, obj[i]->off);
- hwrite(f, buf, 8, &st);
+ if(hwrite(f, buf, 8, &st) == -1)
+ goto error;
}
}
- hwrite(f, ph.h, sizeof(ph.h), &st);
+ if(hwrite(f, ph.h, sizeof(ph.h), &st) == -1)
+ goto error;
sha1(nil, 0, h.h, st);
Bwrite(f, h.h, sizeof(h.h));
@@ -1630,7 +1636,7 @@ genpack(int fd, Meta **meta, int nmeta, Hash *h, int odelta)
DigestState *st;
Biobuf *bfd;
Meta *m;
- Object *o, *b;
+ Object *o, *po, *b;
char *p, buf[32];
st = nil;
@@ -1655,27 +1661,34 @@ genpack(int fd, Meta **meta, int nmeta, Hash *h, int odelta)
for(i = 0; i < nmeta; i++){
pct = showprogress((i*100)/nmeta, pct);
m = meta[i];
- m->off = Boffset(bfd);
+ if((m->off = Boffset(bfd)) == -1)
+ goto error;
if((o = readobject(m->obj->hash)) == nil)
return -1;
if(m->delta == nil){
nh = packhdr(buf, o->type, o->size);
- hwrite(bfd, buf, nh, &st);
+ if(hwrite(bfd, buf, nh, &st) == -1)
+ goto error;
if(hcompress(bfd, o->data, o->size, &st) == -1)
goto error;
}else{
- b = readobject(m->prev->obj->hash);
+ if((b = readobject(m->prev->obj->hash)) == nil)
+ goto error;
nd = encodedelta(m, o, b, &p);
unref(b);
if(odelta && m->prev->off != 0){
nh = 0;
nh += packhdr(buf, GOdelta, nd);
nh += packoff(buf+nh, m->off - m->prev->off);
- hwrite(bfd, buf, nh, &st);
+ if(hwrite(bfd, buf, nh, &st) == -1)
+ goto error;
}else{
nh = packhdr(buf, GRdelta, nd);
- hwrite(bfd, buf, nh, &st);
- hwrite(bfd, m->prev->obj->hash.h, sizeof(m->prev->obj->hash.h), &st);
+ po = m->prev->obj;
+ if(hwrite(bfd, buf, nh, &st) == -1)
+ goto error;
+ if(hwrite(bfd, po->hash.h, sizeof(po->hash.h), &st) == -1)
+ goto error;
}
res = hcompress(bfd, p, nd, &st);
free(p);
diff --git a/sys/src/cmd/git/push b/sys/src/cmd/git/push
index b7a9564f4..ee05d952a 100755
--- a/sys/src/cmd/git/push
+++ b/sys/src/cmd/git/push
@@ -31,7 +31,7 @@ branch=-b^$branch
if(! ~ $#remove 0)
remove=-r^$remove
for(remote in $remotes){
- updates=`$nl{git/send $debug $force $branch $remove $remote || die $status}
+ updates=`$nl{git/send $debug $force $branch $remove $remote} || die $status
for(ln in $updates){
u=`{echo $ln}
refpath=`{echo $u(2) | subst '^refs/heads/' '.git/refs/remotes/'$upstream'/'}