diff --git a/sys/src/cmd/git/get.c b/sys/src/cmd/git/get.c index e6457a920..aa40f7990 100644 --- a/sys/src/cmd/git/get.c +++ b/sys/src/cmd/git/get.c @@ -134,33 +134,6 @@ 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); - } - } - } -} - void fail(char *pack, char *idx, char *msg, ...) { @@ -202,6 +175,7 @@ fetchpack(Conn *c) int nref, refsz, first, nsent; int i, l, n, req, pfd; vlong packsz; + Capset cs; Objset hadobj; Object *o; Objq haveq; @@ -220,8 +194,11 @@ fetchpack(Conn *c) if(n == 0) break; - if(first && n > strlen(buf)) - handlecaps(buf + strlen(buf) + 1); + if(first && n > strlen(buf)){ + parsecaps(buf + strlen(buf) + 1, &cs); + if(cs.symfrom[0] != 0) + print("symref %s %s\n", cs.symfrom, cs.symto); + } first = 0; getfields(buf, sp, nelem(sp), 1, " \t\n\r"); diff --git a/sys/src/cmd/git/git.h b/sys/src/cmd/git/git.h index 19dba5c64..6bad7dff3 100644 --- a/sys/src/cmd/git/git.h +++ b/sys/src/cmd/git/git.h @@ -82,6 +82,14 @@ struct Hash { uchar h[20]; }; +struct Capset { + char symfrom[256]; + char symto[256]; + int sideband; + int sideband64k; + int report; +}; + struct Conn { int type; int rfd; @@ -330,6 +338,7 @@ int gitconnect(Conn *, char *, char *); int readphase(Conn *); int writephase(Conn *); void closeconn(Conn *); +void parsecaps(char *, Capset *); /* queues */ void qinit(Objq*); diff --git a/sys/src/cmd/git/proto.c b/sys/src/cmd/git/proto.c index a96a62402..44b34bdd8 100644 --- a/sys/src/cmd/git/proto.c +++ b/sys/src/cmd/git/proto.c @@ -17,6 +17,42 @@ enum { Nbranch = 32, }; +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 +parsecaps(char *caps, Capset *cs) +{ + char *p, *n, *c, *t; + + memset(cs, 0, sizeof(*cs)); + for(p = caps; p != nil; p = n){ + n = strchr(p, ' '); + if(n != nil) + *n++ = 0; + if(matchcap(p, "report-status", 1) != nil) + cs->report = 1; + else if(matchcap(p, "side-band", 1) != nil) + cs->sideband = 1; + else if(matchcap(p, "side-band-64k", 1) != nil) + cs->sideband64k = 1; + else if((c = matchcap(p, "symref=", 0)) != nil){ + if((t = strchr(c, ':')) == nil) + continue; + *t++ = '\0'; + snprint(cs->symfrom, sizeof(cs->symfrom), c); + snprint(cs->symto, sizeof(cs->symto), t); + } + } +} + + void tracepkt(int v, char *pfx, char *b, int n) { @@ -158,7 +194,7 @@ parseuri(char *uri, char *proto, char *host, char *port, char *path, char *repo) snprint(port, Nport, "80"); else if(strncmp(proto, "hjgit", 5) == 0) snprint(port, Nport, "17021"); - else if(strncmp(proto, "gits", 4) == 0) + else if(strncmp(proto, "gits", 5) == 0) snprint(port, Nport, "9419"); else hasport = 0; diff --git a/sys/src/cmd/git/send.c b/sys/src/cmd/git/send.c index a6f2c21b5..68ef97e56 100644 --- a/sys/src/cmd/git/send.c +++ b/sys/src/cmd/git/send.c @@ -3,15 +3,8 @@ #include "git.h" -typedef struct Capset Capset; typedef struct Map Map; -struct Capset { - int sideband; - int sideband64k; - int report; -}; - struct Map { char *ref; Hash ours; @@ -89,33 +82,6 @@ readours(Hash **tailp, char ***refp) return nu; } -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 -parsecaps(char *caps, Capset *cs) -{ - char *p, *n; - - for(p = caps; p != nil; p = n){ - n = strchr(p, ' '); - if(n != nil) - *n++ = 0; - if(matchcap(p, "report-status", 1) != nil) - cs->report = 1; - if(matchcap(p, "side-band", 1) != nil) - cs->sideband = 1; - if(matchcap(p, "side-band-64k", 1) != nil) - cs->sideband64k = 1; - } -} - int sendpack(Conn *c) {