mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
git: provide symref extension
This commit is contained in:
parent
703bcae2ed
commit
487c2dc215
2 changed files with 32 additions and 7 deletions
|
@ -386,8 +386,8 @@ readref(Hash *h, char *ref)
|
|||
return -1;
|
||||
|
||||
found:
|
||||
if(r == -1 && strstr(s, "ref: ") == s)
|
||||
r = readref(h, s + strlen("ref: "));
|
||||
if(r == -1 && strncmp(s, "ref: ", 5) == 0)
|
||||
r = readref(h, s + 5);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,20 +21,45 @@ fail(Conn *c, char *fmt, ...)
|
|||
sysfatal("%s", msg);
|
||||
}
|
||||
|
||||
char*
|
||||
gethead(Hash *h, char *ref, int nref)
|
||||
{
|
||||
int fd, n;
|
||||
char *s;
|
||||
|
||||
if((fd = open(".git/HEAD", OREAD)) == -1)
|
||||
return nil;
|
||||
if((n = readn(fd, ref, nref-1)) == -1)
|
||||
return nil;
|
||||
while(n > 0 && ref[n-1] == '\n' || ref[n-1] == '\t' || ref[n-1] == ' ')
|
||||
n--;
|
||||
if(strncmp(ref, "ref: ", 5) != 0)
|
||||
return nil;
|
||||
s = ref+5;
|
||||
if(resolveref(h, s) == -1)
|
||||
return nil;
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
showrefs(Conn *c)
|
||||
{
|
||||
int i, ret, nrefs;
|
||||
char **names, *s, buf[256];
|
||||
int i, r, ret, nrefs;
|
||||
Hash head, *refs;
|
||||
char **names;
|
||||
|
||||
ret = -1;
|
||||
nrefs = 0;
|
||||
refs = nil;
|
||||
names = nil;
|
||||
if(resolveref(&head, "HEAD") != -1)
|
||||
if(fmtpkt(c, "%H HEAD\n", head) == -1)
|
||||
goto error;
|
||||
|
||||
s = gethead(&head, buf, sizeof(buf));
|
||||
if(s != nil)
|
||||
r = fmtpkt(c, "%H HEAD%csymref=HEAD:%s\n", head, 0, s);
|
||||
else
|
||||
r = fmtpkt(c, "%H HEAD\n", head);
|
||||
if(r == -1)
|
||||
goto error;
|
||||
|
||||
if((nrefs = listrefs(&refs, &names)) == -1)
|
||||
fail(c, "listrefs: %r");
|
||||
|
|
Loading…
Reference in a new issue