summaryrefslogtreecommitdiff
path: root/sys/src/cmd/hgfs/info.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2012-11-21 19:22:46 +0100
committercinap_lenrek <cinap_lenrek@gmx.de>2012-11-21 19:22:46 +0100
commit40d11cea3fac49a660b5714b18393c2e74487d54 (patch)
tree09ae5180eaeefffa293cec6d2e71765e0e951f9b /sys/src/cmd/hgfs/info.c
parent73744b9f4896c513d4d7c40ef4ce1d24703810e9 (diff)
hgfs: various improvements
lazily close revlog files and keep up to 8 revlogs arround. also cache the latest extracted file descriptor of a revision in the revlog. this avoids the quite expensive reextracting/patching when we reopen the same file revision. dont use the racy mktemp()/create, instead create a uniqueue name and create with OEXCL. this also avoids a bunch of access() calls. fix eof case and use pread() in fcopy() to avoid the seeks. dont modify changelog temp file but simulate trailing newline instead.
Diffstat (limited to 'sys/src/cmd/hgfs/info.c')
-rw-r--r--sys/src/cmd/hgfs/info.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/sys/src/cmd/hgfs/info.c b/sys/src/cmd/hgfs/info.c
index 6a17a8fcc..45877f957 100644
--- a/sys/src/cmd/hgfs/info.c
+++ b/sys/src/cmd/hgfs/info.c
@@ -8,16 +8,13 @@ Revinfo*
loadrevinfo(Revlog *changelog, int rev)
{
char buf[BUFSZ], *p, *e;
- int fd, line, inmsg, n;
+ int fd, line, eof, inmsg, n;
Revinfo *ri;
vlong off;
if((fd = revlogopentemp(changelog, rev)) < 0)
return nil;
- seek(fd, 0, 2);
- write(fd, "\n", 1);
-
off = fmetaheader(fd);
seek(fd, off, 0);
@@ -26,11 +23,19 @@ loadrevinfo(Revlog *changelog, int rev)
memmove(ri->chash, changelog->map[rev].hash, HASHSZ);
+ eof = 0;
line = 0;
inmsg = 0;
p = buf;
e = buf + BUFSZ;
- while((n = read(fd, p, e - p)) > 0){
+ while(eof == 0){
+ if((n = read(fd, p, e - p)) < 0)
+ break;
+ if(n == 0){
+ eof = 1;
+ *p = '\n';
+ n++;
+ }
p += n;
while((p > buf) && (e = memchr(buf, '\n', p - buf))){
*e++ = 0;