--- /mnt/git/object/b373c36d4caecfdbcd6d0833c11092893fcb770c/tree/./clone Fri Oct 9 08:48:32 2020 +++ ./clone Wed Oct 21 10:16:57 2020 @@ -33,13 +33,23 @@ fn clone{ echo ' fetch=+refs/heads/*:refs/remotes/origin/*' } {git/fetch $debug $remote >[2=3] | awk ' - /^remote/{ + BEGIN{ + headref="" + headhash="" + } + /^symref /{ + if($2 == "HEAD"){ + gsub("^refs/heads", "refs/remotes/origin", $3) + gsub("^refs/tags", "refs/remotes/origin/tags", $3) + headref=$3 + } + } + /^remote /{ if($2=="HEAD"){ headhash=$3 - headref="" - }else{ + }else if(match($2, "^refs/(heads|tags)/")){ gsub("^refs/heads", "refs/remotes/origin", $2) - if($2 == "refs/remotes/origin/master" || $3 == headhash) + if($2 == headref || (headref == "" && $3 == headhash)) headref=$2 outfile = ".git/" $2 outdir = outfile --- /mnt/git/object/b373c36d4caecfdbcd6d0833c11092893fcb770c/tree/./fetch.c Fri Oct 9 08:48:32 2020 +++ ./fetch.c Wed Oct 21 10:20:11 2020 @@ -135,18 +135,46 @@ branchmatch(char *br, char *pat) return strcmp(br, name) == 0; } +char * +matchcap(char *s, char *cap, int full) +{ + if(strncmp(s, cap, strlen(cap)) == 0) + if(!full || strlen(s) == strlen(cap)) + return s + strlen(cap); + return nil; +} + +void +handlecaps(char *caps) +{ + char *p, *n, *c, *r; + + for(p = caps; p != nil; p = n){ + n = strchr(p, ' '); + if(n != nil) + *n++ = 0; + if((c = matchcap(p, "symref=", 0)) != nil){ + if((r = strchr(c, ':')) != nil){ + *r++ = '\0'; + print("symref %s %s\n", c, r); + } + } + } +} + int fetchpack(Conn *c, int pfd, char *packtmp) { char buf[Pktmax], idxtmp[256], *sp[3]; Hash h, *have, *want; - int nref, refsz; + int nref, refsz, first; int i, n, req; vlong packsz; Object *o; nref = 0; refsz = 16; + first = 1; have = emalloc(refsz * sizeof(have[0])); want = emalloc(refsz * sizeof(want[0])); while(1){ @@ -157,6 +185,11 @@ fetchpack(Conn *c, int pfd, char *packtm break; if(strncmp(buf, "ERR ", 4) == 0) sysfatal("%s", buf + 4); + + if(first && n > strlen(buf)) + handlecaps(buf + strlen(buf) + 1); + first = 0; + getfields(buf, sp, nelem(sp), 1, " \t\n\r"); if(strstr(sp[1], "^{}")) continue;