8 nodepath(char *s, char *e, Revnode *nd)
10 static char *frogs[] = {
11 "con", "prn", "aux", "nul",
12 "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9",
13 "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9",
18 if(nd == nil || nd->name == nil)
21 s = seprint(nodepath(s, e, nd->up), e, "/");
24 for(i=0; i<nelem(frogs); i++)
25 if(strncmp(frogs[i], p, strlen(frogs[i])) == 0)
26 return seprint(s, e, "%.2s~%.2x%s", p, p[2], p+3);
28 for(; s+4 < e && *p; p++){
32 } else if(*p >= 'A' && *p <= 'Z'){
34 *s++ = 'a' + (*p - 'A');
35 } else if(*p >= 126 || strchr("\\:*?\"<>|", *p)){
37 s = seprint(s, e, "%.2x", *p);
47 mknode(char *name, uchar *hash, char mode)
52 d = malloc(sizeof(*d) + (hash ? HASHSZ : 0) + (name ? strlen(name)+1 : 0));
53 d->up = d->down = d->next = d->before = nil;
56 d->path = *((uvlong*)hash);
57 memmove(d->hash = (uchar*)s, hash, HASHSZ);
64 strcpy(d->name = s, name);
72 addnode(Revnode *d, char *path, uchar *hash, char mode)
78 if(slash = strchr(path, '/'))
81 for(c = d->down; c; p = c, c = c->next)
82 if(strcmp(c->name, path) == 0)
85 c = mknode(path, slash ? nil : hash, slash ? 0 : mode);
96 p->path = *((uvlong*)c->hash);
109 typedef struct Hashstr Hashstr;
133 loadmanifest(Revnode *root, int fd, Hashstr **ht, int nh)
135 char buf[BUFSZ], *p, *e, *x;
141 while((n = read(fd, p, e - p)) > 0){
143 while((p > buf) && (e = memchr(buf, '\n', p - buf))){
152 addnode(root, buf, hash, *x);
156 for(he = ht[hashstr(buf) % nh]; he; he = he->next){
157 if(strcmp(he->str, buf) == 0){
158 addnode(root, buf, hash, *x);
166 memmove(buf, e, p - buf);
174 loadtree(Revlog *manifest, Revinfo *ri, Hashstr **ht, int nh)
179 if((fd = revlogopentemp(manifest, hashrev(manifest, ri->mhash))) < 0)
182 t = malloc(sizeof(*t));
183 memset(t, 0, sizeof(*t));
185 t->root = mknode(nil, nil, 0);
186 if(loadmanifest(t->root, fd, ht, nh) < 0){
197 loadfilestree(Revlog *, Revlog *manifest, Revinfo *ri)
199 return loadtree(manifest, ri, nil, 0);
203 loadchangestree(Revlog *changelog, Revlog *manifest, Revinfo *ri)
205 char buf[BUFSZ], *p, *e;
206 Hashstr *ht[256], *he, **hp;
211 if((fd = revlogopentemp(changelog, hashrev(changelog, ri->chash))) < 0)
214 off = seek(fd, ri->logoff, 0);
220 memset(ht, 0, sizeof(ht));
224 while((off - ri->logoff) < ri->loglen){
225 if((n = read(fd, p, e - p)) <= 0)
228 while((p > buf) && (e = memchr(buf, '\n', p - buf))){
231 he = malloc(sizeof(*he) + strlen(buf)+1);
232 hp = &ht[hashstr(strcpy(he->str, buf)) % nelem(ht)];
239 memmove(buf, e, p - buf);
246 t = loadtree(manifest, ri, ht, nelem(ht));
248 for(hp = ht; hp != &ht[nelem(ht)]; hp++){
259 freenode(Revnode *nd)
265 freenode(nd->before);
270 closerevtree(Revtree *t)
272 if(t == nil || decref(t))