ref: 4d901d1e4165085cda5b574b44e1cc51be50abf8
parent: dd676b5a4fa19fcbe608598e73e3ee6b5bd5ad84
author: Ori Bernstein <[email protected]>
date: Mon Apr 17 17:11:47 EDT 2023
git/send: correctly delete branches with no local mirror
--- a/sys/src/cmd/git/proto.c
+++ b/sys/src/cmd/git/proto.c
@@ -58,8 +58,10 @@
char *e;
int n;
- if(readn(c->rfd, len, 4) != 4)
- sysfatal("pktline: short read from transport");
+ if(readn(c->rfd, len, 4) != 4){
+ werrstr("pktline: short read from transport");
+ return -1;
+ }
len[4] = 0;
n = strtol(len, &e, 16);
if(n == 0){
--- a/sys/src/cmd/git/ref.c
+++ b/sys/src/cmd/git/ref.c
@@ -125,6 +125,8 @@
nskip = 0;
for(i = 0; i < nhead; i++){
+ if(hasheq(&head[i], &Zhash))
+ continue;
if((o = readobject(head[i])) == nil){
fprint(2, "warning: %H does not point at commit\n", head[i]);
werrstr("read head %H: %r", head[i]);
@@ -140,6 +142,8 @@
unref(o);
}
for(i = 0; i < ntail; i++){
+ if(hasheq(&head[i], &Zhash))
+ continue;
if((o = readobject(tail[i])) == nil){
werrstr("read tail %H: %r", tail[i]);
return -1;
--- a/sys/src/cmd/git/send.c
+++ b/sys/src/cmd/git/send.c
@@ -75,9 +75,11 @@
sysfatal("smprint: %r");
if((idx = findref(ref, nu, r)) == -1)
idx = nu++;
+ else
+ free(ref[idx]);
assert(idx < nremoved + nbranch);
memcpy(&tail[idx], &Zhash, sizeof(Hash));
- free(r);
+ ref[idx] = r;
}
dprint(1, "nu: %d\n", nu);
for(i = 0; i < nu; i++)
@@ -184,7 +186,10 @@
p = nil;
if(a != nil && b != nil)
p = ancestor(a, b);
- if(!force && !hasheq(&m->theirs, &Zhash) && (a == nil || p != a)){
+ if(!force
+ && !hasheq(&m->theirs, &Zhash)
+ && !hasheq(&m->ours, &Zhash)
+ && (a == nil || p != a)){
fprint(2, "remote has diverged\n");
werrstr("remote diverged");
flushpkt(c);