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++){
26 if((strncmp(frogs[i], p, l) == 0) && (p[l] == 0 || p[l] == '.'))
27 return seprint(s, e, "%.2s~%.2x%s", p, p[2], p+3);
29 for(; s+4 < e && *p; p++){
33 } else if(*p >= 'A' && *p <= 'Z'){
35 *s++ = 'a' + (*p - 'A');
36 } else if(*p >= 126 || strchr("\\:*?\"<>|", *p)){
38 s = seprint(s, e, "%.2x", *p);
48 mknode(char *name, uchar *hash, char mode)
53 d = malloc(sizeof(*d) + (hash ? HASHSZ : 0) + (name ? strlen(name)+1 : 0));
54 memset(d, 0, sizeof(*d));
57 d->path = *((uvlong*)hash);
58 memmove(d->hash = (uchar*)s, hash, HASHSZ);
63 strcpy(d->name = s, name);
69 addnode(Revnode *d, char *path, uchar *hash, char mode)
75 if(slash = strchr(path, '/'))
78 for(c = d->down; c; p = c, c = c->next)
79 if(strcmp(c->name, path) == 0)
82 c = mknode(path, slash ? nil : hash, slash ? 0 : mode);
93 p->path = *((uvlong*)c->hash);
106 typedef struct Hashstr Hashstr;
130 loadmanifest(Revnode *root, int fd, Hashstr **ht, int nh)
132 char buf[BUFSZ], *p, *e, *x;
138 while((n = read(fd, p, e - p)) > 0){
140 while((p > buf) && (e = memchr(buf, '\n', p - buf))){
149 addnode(root, buf, hash, *x);
153 for(he = ht[hashstr(buf) % nh]; he; he = he->next){
154 if(strcmp(he->str, buf) == 0){
155 addnode(root, buf, hash, *x);
163 memmove(buf, e, p - buf);
171 loadtree(Revlog *manifest, Revinfo *ri, Hashstr **ht, int nh)
176 if((fd = revlogopentemp(manifest, hashrev(manifest, ri->mhash))) < 0)
179 t = malloc(sizeof(*t));
180 memset(t, 0, sizeof(*t));
182 t->root = mknode(nil, nil, 0);
183 if(loadmanifest(t->root, fd, ht, nh) < 0){
194 loadfilestree(Revlog *, Revlog *manifest, Revinfo *ri)
196 return loadtree(manifest, ri, nil, 0);
200 loadchangestree(Revlog *changelog, Revlog *manifest, Revinfo *ri)
202 char buf[BUFSZ], *p, *e;
203 Hashstr *ht[256], *he, **hp;
208 if((fd = revlogopentemp(changelog, hashrev(changelog, ri->chash))) < 0)
211 off = seek(fd, ri->logoff, 0);
217 memset(ht, 0, sizeof(ht));
221 while((off - ri->logoff) < ri->loglen){
222 if((n = read(fd, p, e - p)) <= 0)
225 while((p > buf) && (e = memchr(buf, '\n', p - buf))){
228 he = malloc(sizeof(*he) + strlen(buf)+1);
229 hp = &ht[hashstr(strcpy(he->str, buf)) % nelem(ht)];
236 memmove(buf, e, p - buf);
243 t = loadtree(manifest, ri, ht, nelem(ht));
245 for(hp = ht; hp != &ht[nelem(ht)]; hp++){
256 freenode(Revnode *nd)
262 freenode(nd->before);
267 closerevtree(Revtree *t)
269 if(t == nil || decref(t))