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, char mode)
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);
65 memmove(c->hash = (uchar*)x, hash, HASHSZ);
71 strcpy(c->name = x, path);
84 p->path = *((uvlong*)c->hash);
97 typedef struct Hashstr Hashstr;
121 loadmanifest(Revnode *root, int fd, Hashstr **ht, int nh)
123 char buf[BUFSZ], *p, *e, *x;
129 while((n = read(fd, p, e - p)) > 0){
131 while((p > buf) && (e = memchr(buf, '\n', p - buf))){
140 addnode(root, buf, hash, *x);
144 for(he = ht[hashstr(buf) % nh]; he; he = he->next){
145 if(strcmp(he->str, buf) == 0){
146 addnode(root, buf, hash, *x);
154 memmove(buf, e, p - buf);
162 loadtree(Revlog *manifest, Revinfo *ri, Hashstr **ht, int nh)
167 if((fd = revlogopentemp(manifest, hashrev(manifest, ri->mhash))) < 0)
170 t = malloc(sizeof(*t));
171 memset(t, 0, sizeof(*t));
174 t->root = malloc(sizeof(Revnode));
182 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)
266 closerevtree(Revtree *t)
268 if(t == nil || decref(t))