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(strcmp(frogs[i], p) == 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 addnode(Revnode *d, char *path, uchar *hash)
53 if(slash = strchr(path, '/'))
56 for(c = d->down; c; p = c, c = c->next)
57 if(strcmp(c->name, path) == 0)
60 c = malloc(sizeof(*c) + (!slash ? HASHSZ : 0) + strlen(path)+1);
64 memmove(c->hash = (uchar*)x, hash, HASHSZ);
68 strcpy(c->name = x, path);
81 p->path = *((uvlong*)c->hash);
94 typedef struct Hashstr Hashstr;
118 loadmanifest(Revnode *root, int fd, Hashstr **ht, int nh)
120 char buf[BUFSZ], *p, *e;
126 while((n = read(fd, p, e - p)) > 0){
128 while((p > buf) && (e = memchr(buf, '\n', p - buf))){
131 strhash(buf + strlen(buf) + 1, hash);
133 addnode(root, buf, hash);
137 for(he = ht[hashstr(buf) % nh]; he; he = he->next){
138 if(strcmp(he->str, buf) == 0){
139 addnode(root, buf, hash);
147 memmove(buf, e, p - buf);
155 loadtree(Revlog *manifest, Revinfo *ri, Hashstr **ht, int nh)
160 if((fd = revlogopentemp(manifest, hashrev(manifest, ri->mhash))) < 0)
163 t = malloc(sizeof(*t));
164 memset(t, 0, sizeof(*t));
167 t->root = malloc(sizeof(Revnode));
175 if(loadmanifest(t->root, fd, ht, nh) < 0){
187 loadfilestree(Revlog *, Revlog *manifest, Revinfo *ri)
189 return loadtree(manifest, ri, nil, 0);
193 loadchangestree(Revlog *changelog, Revlog *manifest, Revinfo *ri)
195 char buf[BUFSZ], *p, *e;
196 Hashstr *ht[256], *he, **hp;
197 int fd, done, line, n;
200 if((fd = revlogopentemp(changelog, hashrev(changelog, ri->chash))) < 0)
205 memset(ht, 0, sizeof(ht));
209 while((n = read(fd, p, e - p)) > 0){
211 while((p > buf) && (e = memchr(buf, '\n', p - buf))){
220 he = malloc(sizeof(*he) + strlen(buf)+1);
221 hp = &ht[hashstr(strcpy(he->str, buf)) % nelem(ht)];
228 memmove(buf, e, p - buf);
236 t = loadtree(manifest, ri, ht, nelem(ht));
238 for(hp = ht; hp != &ht[nelem(ht)]; hp++){
249 freenode(Revnode *nd)
259 closerevtree(Revtree *t)
261 if(t == nil || decref(t))