mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
git: refactor capability parsing
this should be a nop, but set us up better for handling and exposing capabilities in git/serve.
This commit is contained in:
parent
e58df8173f
commit
e59b7e28cd
4 changed files with 52 additions and 64 deletions
|
@ -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");
|
||||
|
|
|
@ -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*);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue