Skip to content

Commit

Permalink
sync with 9front
Browse files Browse the repository at this point in the history
  • Loading branch information
oridb committed Feb 18, 2024
1 parent 8da1ef1 commit 45001b2
Show file tree
Hide file tree
Showing 14 changed files with 711 additions and 361 deletions.
4 changes: 2 additions & 2 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void
main(int argc, char **argv)
{
char repo[512], *p, *s;
int i, j;
int i, j, nrel;

ARGBEGIN{
case 'f': file[nfile++]=EARGF(usage()); break;
Expand All @@ -69,7 +69,7 @@ main(int argc, char **argv)
}ARGEND;

if(findroot){
if(findrepo(repo, sizeof(repo)) == -1)
if(findrepo(repo, sizeof(repo), &nrel) == -1)
sysfatal("%r");
print("%s\n", repo);
exits(nil);
Expand Down
17 changes: 12 additions & 5 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ char *qroot[] = {
};

#define Eperm "permission denied"
#define Eexist "does not exist"
#define Eexist "file does not exist"
#define E2long "path too long"
#define Enodir "not a directory"
#define Erepo "unable to read repo"
#define Eobject "invalid object"
#define Egreg "wat"
#define Ebadobj "invalid object"

Expand Down Expand Up @@ -305,6 +304,9 @@ gcommitgen(int i, Dir *d, void *p)
d->qid.path = qpath(c, i, o->id, Qauthor);
break;
default:
free(d->uid);
free(d->gid);
free(d->muid);
return -1;
}
return 0;
Expand Down Expand Up @@ -453,6 +455,9 @@ walklink(Gitaux *aux, char *link, int nlink, int ndotdot, int *mode)
break;
}
free(path);
for(i = 0; o != nil && i < aux->ncrumb; i++)
if(crumb(aux, i)->obj == o)
return nil;
return o;
}

Expand Down Expand Up @@ -482,7 +487,7 @@ objwalk1(Qid *q, Object *o, Crumb *p, Crumb *c, char *name, vlong qdir, Gitaux *
if(!w)
return Ebadobj;
q->type = (w->type == GTree) ? QTDIR : 0;
q->path = qpath(c, i, w->id, qdir);
q->path = qpath(p, i, w->id, qdir);
c->mode = m;
c->mode |= (w->type == GTree) ? DMDIR|0755 : 0644;
c->obj = w;
Expand Down Expand Up @@ -618,16 +623,18 @@ gitwalk1(Fid *fid, char *name, Qid *q)
q->path = qpath(o, Qbranch, c->obj->id, Qcommit);
else
e = Eexist;
if(d != nil)
c->mode = d->mode & ~0222;
free(d);
break;
case Qobject:
if(c->obj){
e = objwalk1(q, o->obj, o, c, name, Qobject, aux);
}else{
if(hparse(&h, name) == -1)
return Eobject;
return Ebadobj;
if((c->obj = readobject(h)) == nil)
return Eobject;
return Ebadobj;
if(c->obj->type == GBlob || c->obj->type == GTag){
c->mode = 0644;
q->type = 0;
Expand Down
2 changes: 1 addition & 1 deletion get.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fetchpack(Conn *c)
if(hasheq(&have[i], &Zhash) || oshas(&hadobj, have[i]))
continue;
if((o = readobject(have[i])) == nil)
sysfatal("missing object we should have: %H", have[i]);
sysfatal("missing exected object: %H", have[i]);
if(fmtpkt(c, "have %H", o->hash) == -1)
sysfatal("write: %r");
enqueueparent(&haveq, o);
Expand Down
25 changes: 24 additions & 1 deletion git.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ typedef struct Hash Hash;
typedef struct Delta Delta;
typedef struct Cinfo Cinfo;
typedef struct Tinfo Tinfo;
typedef struct Ginfo Ginfo;
typedef struct Object Object;
typedef struct Objset Objset;
typedef struct Pack Pack;
Expand All @@ -21,6 +22,7 @@ typedef struct Dtab Dtab;
typedef struct Dblock Dblock;
typedef struct Objq Objq;
typedef struct Qelt Qelt;
typedef struct Idxent Idxent;

enum {
Pathmax = 512,
Expand Down Expand Up @@ -128,6 +130,7 @@ struct Object {
union {
Cinfo *commit;
Tinfo *tree;
Ginfo *tag;
};
};

Expand All @@ -150,6 +153,18 @@ struct Cinfo {
vlong mtime;
};

struct Ginfo {
/* Tag */
Hash object;
char *tagger;
char *type;
char *tag;
char *msg;
int nmsg;
vlong ctime;
vlong mtime;
};

struct Objset {
Object **obj;
int nobj;
Expand Down Expand Up @@ -190,6 +205,13 @@ struct Delta {
int len;
};

struct Idxent {
char *path;
Qid qid;
int mode;
int order;
char state;
};

#define GETBE16(b)\
((((b)[0] & 0xFFul) << 8) | \
Expand Down Expand Up @@ -301,9 +323,10 @@ int hparse(Hash *, char *);
int hassuffix(char *, char *);
int swapsuffix(char *, int, char *, char *, char *);
char *strip(char *);
int findrepo(char *, int);
int findrepo(char *, int, int*);
int showprogress(int, int);
u64int murmurhash2(void*, usize);
Qid parseqid(char*);

/* packing */
void dtinit(Dtab *, Object*);
Expand Down
7 changes: 5 additions & 2 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ showcommits(char *c)
sysfatal("resolve %s: %r", c);
if((o = readobject(h)) == nil)
sysfatal("load %H: %r", h);
if(o->type != GCommit)
sysfatal("%s: not a commit", c);
qinit(&objq);
osinit(&done);
qput(&objq, o, 0);
Expand Down Expand Up @@ -239,7 +241,7 @@ void
main(int argc, char **argv)
{
char path[1024], repo[1024], *p, *r;
int i, nrepo;
int i, nrel, nrepo;

ARGBEGIN{
case 'e':
Expand All @@ -259,7 +261,7 @@ main(int argc, char **argv)
break;
}ARGEND;

if(findrepo(repo, sizeof(repo)) == -1)
if(findrepo(repo, sizeof(repo), &nrel) == -1)
sysfatal("find root: %r");
nrepo = strlen(repo);
if(argc != 0){
Expand Down Expand Up @@ -291,5 +293,6 @@ main(int argc, char **argv)
showquery(queryexpr);
else
showcommits(commitid);
Bterm(out);
exits(nil);
}
63 changes: 51 additions & 12 deletions pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Objset objcache;
Object *lruhead;
Object *lrutail;
vlong ncache;
vlong cachemax = 512*MiB;
vlong cachemax = 128*MiB;
Packf *packf;
int npackf;
int openpacks;
Expand Down Expand Up @@ -160,7 +160,7 @@ cache(Object *o)
ref(o);
ncache += o->size;
}
while(ncache > cachemax && lrutail != nil){
while(ncache > cachemax && lrutail != lruhead){
p = lrutail;
lrutail = p->prev;
if(lrutail != nil)
Expand Down Expand Up @@ -825,6 +825,7 @@ parseauthor(char **str, int *nstr, char **name, vlong *time)
{
char buf[128];
Resub m[4];
vlong tz;
char *p;
int n, nm;

Expand All @@ -845,10 +846,16 @@ parseauthor(char **str, int *nstr, char **name, vlong *time)
memcpy(*name, m[1].sp, nm);
buf[nm] = 0;

nm = m[3].ep - m[3].sp;
memcpy(buf, m[3].sp, nm);
buf[nm] = 0;
tz = atoll(buf);

nm = m[2].ep - m[2].sp;
memcpy(buf, m[2].sp, nm);
buf[nm] = 0;
*time = atoll(buf);
*time = atoll(buf) + 3600*(tz/100) + 60*(tz%100);

return 0;
}

Expand Down Expand Up @@ -900,6 +907,46 @@ parsecommit(Object *o)
o->commit->nmsg = np;
}

static void
parsetag(Object *o)
{
char *p, buf[128];
int np;

p = o->data;
np = o->size;
o->tag = emalloc(sizeof(Ginfo));
while(1){
if(scanword(&p, &np, buf, sizeof(buf)) == -1)
break;
if(strcmp(buf, "object") == 0){
if(scanword(&p, &np, buf, sizeof(buf)) == -1)
sysfatal("invalid commit: tree missing");
if(hparse(&o->tag->object, buf) == -1)
sysfatal("invalid commit: garbled tree");
}else if(strcmp(buf, "tagger") == 0){
parseauthor(&p, &np, &o->commit->author, &o->tag->mtime);
}else if(strcmp(buf, "type") == 0){
if(scanword(&p, &np, buf, sizeof(buf)) == -1)
sysfatal("bad tag type");
if((o->tag->type = strdup(buf)) == nil)
sysfatal("strdup: %r");
}else if(strcmp(buf, "tag") == 0){
if(scanword(&p, &np, buf, sizeof(buf)) == -1)
sysfatal("bad tag type");
if((o->tag->type = strdup(buf)) == nil)
sysfatal("strdup: %r");
}
nextline(&p, &np);
}
while (np && isspace(*p)) {
p++;
np--;
}
o->commit->msg = p;
o->commit->nmsg = np;
}

static void
parsetree(Object *o)
{
Expand Down Expand Up @@ -954,12 +1001,6 @@ parsetree(Object *o)
o->tree->ent = ent;
o->tree->nent = nent;
}

static void
parsetag(Object *)
{
}

void
parseobject(Object *o)
{
Expand Down Expand Up @@ -1210,10 +1251,8 @@ indexpack(char *pack, char *idx, Hash ph)
if(objectcrc(f, o) == -1)
return -1;
}
if(n == nvalid){
if(n == nvalid)
sysfatal("fix point reached too early: %d/%d: %r", nvalid, nobj);
goto error;
}
nvalid = n;
}
if(interactive)
Expand Down
6 changes: 4 additions & 2 deletions proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ readpkt(Conn *c, char *buf, int nbuf)
char *e;
int n;

if(readn(c->rfd, len, 4) != 4)
sysfatal("pktline: short read from transport");
if(readn(c->rfd, len, 4) != 4){
werrstr("pktline: short read from transport");
return -1;
}
len[4] = 0;
n = strtol(len, &e, 16);
if(n == 0){
Expand Down
29 changes: 15 additions & 14 deletions query.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ usage(void)
void
main(int argc, char **argv)
{
int i, j, n;
char *query, repo[512];
char *p, *e, *objpfx;
int i, j, n, nrel;
Hash *h;
char *p, *e, *s, *objpfx;
char query[2048], repo[512];

ARGBEGIN{
case 'd': chattygit++; break;
Expand All @@ -170,25 +170,26 @@ main(int argc, char **argv)

if(argc == 0)
usage();
if(findrepo(repo, sizeof(repo)) == -1)
if(findrepo(repo, sizeof(repo), &nrel) == -1)
sysfatal("find root: %r");
if(chdir(repo) == -1)
sysfatal("chdir: %r");
if((objpfx = smprint("%s/.git/fs/object/", repo)) == nil)
sysfatal("smprint: %r");
s = "";
for(i = 0, n = 0; i < argc; i++)
n += strlen(argv[i]) + 1;
query = emalloc(n+1);
p = query;
e = query + nelem(query);
for(i = 0; i < argc; i++){
p = seprint(p, e, "%s%s", s, argv[i]);
s = " ";
}
if((n = resolverefs(&h, query)) == -1)
e = query + n;
for(i = 0; i < argc; i++)
p = seprint(p, e, "%s ", argv[i]);
n = resolverefs(&h, query);
free(query);
if(n == -1)
sysfatal("resolve: %r");
if(changes){
if(n != 2)
sysfatal("diff: need 2 commits, got %d", n);
diffcommits(h[0], h[1]);
for(i = 1; i < n; i++)
diffcommits(h[0], h[i]);
}else{
p = (fullpath ? objpfx : "");
for(j = 0; j < n; j++)
Expand Down
Loading

0 comments on commit 45001b2

Please sign in to comment.