hgfs: change semantics of log to contain only the file list
This commit is contained in:
parent
402ee30714
commit
d0485d345d
4 changed files with 43 additions and 23 deletions
|
@ -63,6 +63,9 @@ struct Revinfo
|
||||||
char *who;
|
char *who;
|
||||||
char *why;
|
char *why;
|
||||||
long when;
|
long when;
|
||||||
|
|
||||||
|
vlong logoff;
|
||||||
|
vlong loglen;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Revtree
|
struct Revtree
|
||||||
|
|
|
@ -197,8 +197,7 @@ fsmkdir(Dir *d, int level, void *aux)
|
||||||
goto Strgen;
|
goto Strgen;
|
||||||
case Qlog:
|
case Qlog:
|
||||||
ri = aux;
|
ri = aux;
|
||||||
if((rev = hashrev(&changelog, ri->chash)) >= 0)
|
d->length = ri->loglen;
|
||||||
d->length = changelog.map[rev].flen;
|
|
||||||
goto Namegen;
|
goto Namegen;
|
||||||
case Qwho:
|
case Qwho:
|
||||||
ri = aux;
|
ri = aux;
|
||||||
|
@ -512,6 +511,11 @@ fsread(Req *r)
|
||||||
Revlog rl;
|
Revlog rl;
|
||||||
char *s;
|
char *s;
|
||||||
int i, n;
|
int i, n;
|
||||||
|
vlong off;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
off = r->ifcall.offset;
|
||||||
|
len = r->ifcall.count;
|
||||||
|
|
||||||
rf = r->fid->aux;
|
rf = r->fid->aux;
|
||||||
switch(rf->level){
|
switch(rf->level){
|
||||||
|
@ -540,6 +544,11 @@ fsread(Req *r)
|
||||||
}
|
}
|
||||||
goto Strgen;
|
goto Strgen;
|
||||||
case Qlog:
|
case Qlog:
|
||||||
|
if(off >= rf->info->loglen)
|
||||||
|
len = 0;
|
||||||
|
else if((off + len) >= rf->info->loglen)
|
||||||
|
len = rf->info->loglen - off;
|
||||||
|
off += rf->info->logoff;
|
||||||
if(rf->fd >= 0)
|
if(rf->fd >= 0)
|
||||||
goto Fdgen;
|
goto Fdgen;
|
||||||
if((rf->fd = revlogopentemp(&changelog, hashrev(&changelog, rf->info->chash))) < 0){
|
if((rf->fd = revlogopentemp(&changelog, hashrev(&changelog, rf->info->chash))) < 0){
|
||||||
|
@ -580,7 +589,7 @@ fsread(Req *r)
|
||||||
}
|
}
|
||||||
revlogclose(&rl);
|
revlogclose(&rl);
|
||||||
Fdgen:
|
Fdgen:
|
||||||
if((n = pread(rf->fd, r->ofcall.data, r->ifcall.count, r->ifcall.offset)) < 0){
|
if((n = pread(rf->fd, r->ofcall.data, len, off)) < 0){
|
||||||
responderror(r);
|
responderror(r);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ loadrevinfo(Revlog *changelog, int rev)
|
||||||
char buf[BUFSZ], *p, *e;
|
char buf[BUFSZ], *p, *e;
|
||||||
int fd, line, inmsg, n;
|
int fd, line, inmsg, n;
|
||||||
Revinfo *ri;
|
Revinfo *ri;
|
||||||
|
vlong off;
|
||||||
|
|
||||||
if((fd = revlogopentemp(changelog, rev)) < 0)
|
if((fd = revlogopentemp(changelog, rev)) < 0)
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -23,6 +24,7 @@ loadrevinfo(Revlog *changelog, int rev)
|
||||||
|
|
||||||
memmove(ri->chash, changelog->map[rev].hash, HASHSZ);
|
memmove(ri->chash, changelog->map[rev].hash, HASHSZ);
|
||||||
|
|
||||||
|
off = 0;
|
||||||
line = 0;
|
line = 0;
|
||||||
inmsg = 0;
|
inmsg = 0;
|
||||||
p = buf;
|
p = buf;
|
||||||
|
@ -42,19 +44,25 @@ loadrevinfo(Revlog *changelog, int rev)
|
||||||
case 2:
|
case 2:
|
||||||
ri->when = strtol(buf, nil, 10);
|
ri->when = strtol(buf, nil, 10);
|
||||||
break;
|
break;
|
||||||
|
case 3:
|
||||||
|
ri->logoff = off;
|
||||||
default:
|
default:
|
||||||
if(!inmsg){
|
if(!inmsg){
|
||||||
if(*buf == 0)
|
if(*buf == 0){
|
||||||
|
ri->loglen = off - ri->logoff;
|
||||||
inmsg = 1;
|
inmsg = 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
n = ri->why ? strlen(ri->why) : 0;
|
n = ri->why ? strlen(ri->why) : 0;
|
||||||
ri->why = realloc(ri->why, n + strlen(buf)+1);
|
ri->why = realloc(ri->why, n + strlen(buf)+1);
|
||||||
strcpy(ri->why + n, buf);
|
strcpy(ri->why + n, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p -= e - buf;
|
n = e - buf;
|
||||||
|
p -= n;
|
||||||
if(p > buf)
|
if(p > buf)
|
||||||
memmove(buf, e, p - buf);
|
memmove(buf, e, p - buf);
|
||||||
|
off += n;
|
||||||
}
|
}
|
||||||
e = buf + BUFSZ;
|
e = buf + BUFSZ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,41 +201,41 @@ loadchangestree(Revlog *changelog, Revlog *manifest, Revinfo *ri)
|
||||||
{
|
{
|
||||||
char buf[BUFSZ], *p, *e;
|
char buf[BUFSZ], *p, *e;
|
||||||
Hashstr *ht[256], *he, **hp;
|
Hashstr *ht[256], *he, **hp;
|
||||||
int fd, done, line, n;
|
int fd, n;
|
||||||
Revtree *t;
|
Revtree *t;
|
||||||
|
vlong off;
|
||||||
|
|
||||||
if((fd = revlogopentemp(changelog, hashrev(changelog, ri->chash))) < 0)
|
if((fd = revlogopentemp(changelog, hashrev(changelog, ri->chash))) < 0)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
done = 0;
|
off = seek(fd, ri->logoff, 0);
|
||||||
line = 0;
|
if(off < 0){
|
||||||
|
close(fd);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
memset(ht, 0, sizeof(ht));
|
memset(ht, 0, sizeof(ht));
|
||||||
|
|
||||||
p = buf;
|
p = buf;
|
||||||
e = buf + BUFSZ;
|
e = buf + BUFSZ;
|
||||||
while((n = read(fd, p, e - p)) > 0){
|
while((off - ri->logoff) < ri->loglen){
|
||||||
|
if((n = read(fd, p, e - p)) <= 0)
|
||||||
|
break;
|
||||||
p += n;
|
p += n;
|
||||||
while((p > buf) && (e = memchr(buf, '\n', p - buf))){
|
while((p > buf) && (e = memchr(buf, '\n', p - buf))){
|
||||||
*e++ = 0;
|
*e++ = 0;
|
||||||
|
|
||||||
if(++line >= 4){
|
he = malloc(sizeof(*he) + strlen(buf)+1);
|
||||||
if(*buf == 0){
|
hp = &ht[hashstr(strcpy(he->str, buf)) % nelem(ht)];
|
||||||
done = 1;
|
he->next = *hp;
|
||||||
break;
|
*hp = he;
|
||||||
}
|
|
||||||
|
|
||||||
he = malloc(sizeof(*he) + strlen(buf)+1);
|
n = e - buf;
|
||||||
hp = &ht[hashstr(strcpy(he->str, buf)) % nelem(ht)];
|
p -= n;
|
||||||
he->next = *hp;
|
|
||||||
*hp = he;
|
|
||||||
}
|
|
||||||
|
|
||||||
p -= e - buf;
|
|
||||||
if(p > buf)
|
if(p > buf)
|
||||||
memmove(buf, e, p - buf);
|
memmove(buf, e, p - buf);
|
||||||
|
off += n;
|
||||||
}
|
}
|
||||||
if(done)
|
|
||||||
break;
|
|
||||||
e = buf + BUFSZ;
|
e = buf + BUFSZ;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue