ref: 8319b750ea7780bc8452fdda078ecd17f0b3e81d
parent: 03e5d9e9e28894d534ad6a93361fa6cfae280cf8
author: Ori Bernstein <[email protected]>
date: Sat Apr 16 20:22:43 EDT 2022
git/serve: log correct error message Sending the packet on failure could junk the errstr, so set it after we send the message.
--- a/sys/src/cmd/git/pack.c
+++ b/sys/src/cmd/git/pack.c
@@ -1036,7 +1036,6 @@
return obj;
}
}
-
snprint(hbuf, sizeof(hbuf), "%H", h);
snprint(path, sizeof(path), ".git/objects/%c%c/%s", hbuf[0], hbuf[1], hbuf + 2);
--- a/sys/src/cmd/git/serve.c
+++ b/sys/src/cmd/git/serve.c
@@ -362,7 +362,7 @@
int
updaterefs(Conn *c, Hash *cur, Hash *upd, char **ref, int nupd)
{
- char refpath[512];
+ char refpath[512], buf[128];
int i, newidx, hadref, fd, ret, lockfd;
vlong newtm;
Object *o;
@@ -378,7 +378,7 @@
*/
newtm = -23811206400;
if((lockfd = lockrepo()) == -1){
- werrstr("repo locked\n");
+ snprint(buf, sizeof(buf), "repo locked\n");
return -1;
}
for(i = 0; i < nupd; i++){
@@ -385,12 +385,12 @@
if(resolveref(&h, ref[i]) == 0){
hadref = 1;
if(!hasheq(&h, &cur[i])){
- werrstr("old ref changed: %s", ref[i]);
+ snprint(buf, sizeof(buf), "old ref changed: %s", ref[i]);
goto error;
}
}
if(snprint(refpath, sizeof(refpath), ".git/%s", ref[i]) == sizeof(refpath)){
- werrstr("ref path too long: %s", ref[i]);
+ snprint(buf, sizeof(buf), "ref path too long: %s", ref[i]);
goto error;
}
if(hasheq(&upd[i], &Zhash)){
@@ -398,11 +398,11 @@
continue;
}
if((o = readobject(upd[i])) == nil){
- werrstr("update to nonexistent hash %H", upd[i]);
+ snprint(buf, sizeof(buf), "update to nonexistent hash %H", upd[i]);
goto error;
}
if(o->type != GCommit){
- werrstr("not commit: %H", upd[i]);
+ snprint(buf, sizeof(buf), "not commit: %H", upd[i]);
goto error;
}
if(o->commit->mtime > newtm){
@@ -411,11 +411,11 @@
}
unref(o);
if((fd = create(refpath, OWRITE|OTRUNC, 0644)) == -1){
- werrstr("open ref: %r");
+ snprint(buf, sizeof(buf), "open ref: %r");
goto error;
}
if(fprint(fd, "%H", upd[i]) == -1){
- werrstr("upate ref: %r");
+ snprint(buf, sizeof(buf), "upate ref: %r");
close(fd);
goto error;
}
@@ -436,11 +436,11 @@
*/
if(resolveref(&h, "HEAD") == -1 && hadref == 0 && newidx != -1){
if((fd = create(".git/HEAD", OWRITE|OTRUNC, 0644)) == -1){
- werrstr("open HEAD: %r");
+ snprint(buf, sizeof(buf), "open HEAD: %r");
goto error;
}
if(fprint(fd, "ref: %s", ref[0]) == -1){
- werrstr("write HEAD ref: %r");
+ snprint(buf, sizeof(buf), "write HEAD ref: %r");
goto error;
}
close(fd);
@@ -447,8 +447,9 @@
}
ret = 0;
error:
- fmtpkt(c, "ERR %r");
+ fmtpkt(c, "ERR %s", buf);
close(lockfd);
+ werrstr(buf);
return ret;
}