hgfs: make qid generation machine independent

This commit is contained in:
cinap_lenrek 2011-07-01 08:31:29 +02:00
parent 2f59a5d392
commit 400e1b3643
5 changed files with 30 additions and 15 deletions

View file

@ -1,6 +1,7 @@
/* hash */
int Hfmt(Fmt *f);
int strhash(char *s, uchar *h);
int hex2hash(char *s, uchar *h);
uvlong hash2qid(uchar *h);
int fhash(int fd, uchar p1[], uchar p2[], uchar h[]);
/* patch */
@ -24,7 +25,7 @@ int revlogopentemp(Revlog *r, int rev);
Revinfo *loadrevinfo(Revlog *changelog, int rev);
/* tree */
char *nodepath(char *s, char *e, Revnode *nd);
char *nodepath(char *s, char *e, Revnode *nd, int mange);
Revnode *mknode(char *name, uchar *hash, char mode);
Revtree *loadfilestree(Revlog *changelog, Revlog *manifest, Revinfo *ri);
Revtree *loadchangestree(Revlog *changelog, Revlog *manifest, Revinfo *ri);

View file

@ -50,7 +50,8 @@ getrevlog(Revnode *nd)
char buf[MAXPATH];
Revlog *rl;
nodepath(seprint(buf, buf+sizeof(buf), "%s/store/data", dothg), buf+sizeof(buf), nd);
nodepath(seprint(buf, buf+sizeof(buf), "%s/store/data", dothg),
buf+sizeof(buf), nd, 1);
for(rl = revlogs; rl; rl = rl->next)
if(strcmp(buf, rl->path) == 0)
break;
@ -189,7 +190,7 @@ fsmkqid(Qid *q, int level, void *aux)
q->type = 0;
}
ri = aux;
q->path = *((uvlong*)ri->chash) + (level - Qrev);
q->path = hash2qid(ri->chash) + (level - Qrev);
q->vers = 0;
break;
case Qtree:
@ -368,7 +369,7 @@ findrev(Revlog *rl, char *name)
rev = -1;
if(s = strchr(name, '.'))
name = s+1;
if((n = strhash(name, hash)) > 0){
if((n = hex2hash(name, hash)) > 0){
for(i=0; i<rl->nmap; i++){
if(memcmp(rl->map[i].hash, hash, n) == 0){
if(rev < 0)

View file

@ -42,7 +42,7 @@ fhash(int fd, uchar p1[], uchar p2[], uchar h[])
}
int
strhash(char *s, uchar *h)
hex2hash(char *s, uchar *h)
{
uchar *b;
int n;
@ -67,3 +67,15 @@ strhash(char *s, uchar *h)
}
return h - b;
}
uvlong
hash2qid(uchar *h)
{
uvlong v;
int i;
v = 0;
for(i=0; i<8; i++)
v |= (uvlong)h[i]<<(56-8*i);
return v;
}

View file

@ -36,7 +36,7 @@ loadrevinfo(Revlog *changelog, int rev)
switch(line++){
case 0:
strhash(buf, ri->mhash);
hex2hash(buf, ri->mhash);
break;
case 1:
ri->who = strdup(buf);

View file

@ -5,7 +5,7 @@
#include "fns.h"
char*
nodepath(char *s, char *e, Revnode *nd)
nodepath(char *s, char *e, Revnode *nd, int mangle)
{
static char *frogs[] = {
"con", "prn", "aux", "nul",
@ -18,9 +18,11 @@ nodepath(char *s, char *e, Revnode *nd)
if(nd == nil || nd->name == nil)
return s;
s = seprint(nodepath(s, e, nd->up), e, "/");
s = seprint(nodepath(s, e, nd->up, mangle), e, "/");
p = nd->name;
if(!mangle)
return seprint(s, e, "%s", p);
for(i=0; i<nelem(frogs); i++){
l = strlen(frogs[i]);
if((strncmp(frogs[i], p, l) == 0) && (p[l] == 0 || p[l] == '.'))
@ -54,7 +56,7 @@ mknode(char *name, uchar *hash, char mode)
memset(d, 0, sizeof(*d));
s = (char*)&d[1];
if(hash){
d->path = *((uvlong*)hash);
d->path = hash2qid(hash);
memmove(d->hash = (uchar*)s, hash, HASHSZ);
s += HASHSZ;
}else
@ -88,10 +90,9 @@ addnode(Revnode *d, char *path, uchar *hash, char mode)
c->next = d->down;
d->down = c;
}
if(c->hash){
if(!slash){
p = c;
p->path = *((uvlong*)c->hash);
while(d->up){
while(d){
d->path += p->path;
p = d;
d = d->up;
@ -142,7 +143,7 @@ loadmanifest(Revnode *root, int fd, Hashstr **ht, int nh)
x = buf;
x += strlen(x) + 1;
strhash(x, hash);
hex2hash(x, hash);
x += HASHSZ*2;
if(ht == nil)