git/serve: log correct error message
Sending the packet on failure could junk the errstr, so set it after we send the message.
This commit is contained in:
parent
dba98f649c
commit
7ab99af0ea
2 changed files with 12 additions and 12 deletions
|
@ -1036,7 +1036,6 @@ retry:
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
snprint(hbuf, sizeof(hbuf), "%H", h);
|
snprint(hbuf, sizeof(hbuf), "%H", h);
|
||||||
snprint(path, sizeof(path), ".git/objects/%c%c/%s", hbuf[0], hbuf[1], hbuf + 2);
|
snprint(path, sizeof(path), ".git/objects/%c%c/%s", hbuf[0], hbuf[1], hbuf + 2);
|
||||||
|
|
|
@ -362,7 +362,7 @@ lockrepo(void)
|
||||||
int
|
int
|
||||||
updaterefs(Conn *c, Hash *cur, Hash *upd, char **ref, int nupd)
|
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;
|
int i, newidx, hadref, fd, ret, lockfd;
|
||||||
vlong newtm;
|
vlong newtm;
|
||||||
Object *o;
|
Object *o;
|
||||||
|
@ -378,19 +378,19 @@ updaterefs(Conn *c, Hash *cur, Hash *upd, char **ref, int nupd)
|
||||||
*/
|
*/
|
||||||
newtm = -23811206400;
|
newtm = -23811206400;
|
||||||
if((lockfd = lockrepo()) == -1){
|
if((lockfd = lockrepo()) == -1){
|
||||||
werrstr("repo locked\n");
|
snprint(buf, sizeof(buf), "repo locked\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for(i = 0; i < nupd; i++){
|
for(i = 0; i < nupd; i++){
|
||||||
if(resolveref(&h, ref[i]) == 0){
|
if(resolveref(&h, ref[i]) == 0){
|
||||||
hadref = 1;
|
hadref = 1;
|
||||||
if(!hasheq(&h, &cur[i])){
|
if(!hasheq(&h, &cur[i])){
|
||||||
werrstr("old ref changed: %s", ref[i]);
|
snprint(buf, sizeof(buf), "old ref changed: %s", ref[i]);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(snprint(refpath, sizeof(refpath), ".git/%s", ref[i]) == sizeof(refpath)){
|
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;
|
goto error;
|
||||||
}
|
}
|
||||||
if(hasheq(&upd[i], &Zhash)){
|
if(hasheq(&upd[i], &Zhash)){
|
||||||
|
@ -398,11 +398,11 @@ updaterefs(Conn *c, Hash *cur, Hash *upd, char **ref, int nupd)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if((o = readobject(upd[i])) == nil){
|
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;
|
goto error;
|
||||||
}
|
}
|
||||||
if(o->type != GCommit){
|
if(o->type != GCommit){
|
||||||
werrstr("not commit: %H", upd[i]);
|
snprint(buf, sizeof(buf), "not commit: %H", upd[i]);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(o->commit->mtime > newtm){
|
if(o->commit->mtime > newtm){
|
||||||
|
@ -411,11 +411,11 @@ updaterefs(Conn *c, Hash *cur, Hash *upd, char **ref, int nupd)
|
||||||
}
|
}
|
||||||
unref(o);
|
unref(o);
|
||||||
if((fd = create(refpath, OWRITE|OTRUNC, 0644)) == -1){
|
if((fd = create(refpath, OWRITE|OTRUNC, 0644)) == -1){
|
||||||
werrstr("open ref: %r");
|
snprint(buf, sizeof(buf), "open ref: %r");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(fprint(fd, "%H", upd[i]) == -1){
|
if(fprint(fd, "%H", upd[i]) == -1){
|
||||||
werrstr("upate ref: %r");
|
snprint(buf, sizeof(buf), "upate ref: %r");
|
||||||
close(fd);
|
close(fd);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -436,19 +436,20 @@ updaterefs(Conn *c, Hash *cur, Hash *upd, char **ref, int nupd)
|
||||||
*/
|
*/
|
||||||
if(resolveref(&h, "HEAD") == -1 && hadref == 0 && newidx != -1){
|
if(resolveref(&h, "HEAD") == -1 && hadref == 0 && newidx != -1){
|
||||||
if((fd = create(".git/HEAD", OWRITE|OTRUNC, 0644)) == -1){
|
if((fd = create(".git/HEAD", OWRITE|OTRUNC, 0644)) == -1){
|
||||||
werrstr("open HEAD: %r");
|
snprint(buf, sizeof(buf), "open HEAD: %r");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(fprint(fd, "ref: %s", ref[0]) == -1){
|
if(fprint(fd, "ref: %s", ref[0]) == -1){
|
||||||
werrstr("write HEAD ref: %r");
|
snprint(buf, sizeof(buf), "write HEAD ref: %r");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
error:
|
error:
|
||||||
fmtpkt(c, "ERR %r");
|
fmtpkt(c, "ERR %s", buf);
|
||||||
close(lockfd);
|
close(lockfd);
|
||||||
|
werrstr(buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue