shithub: riscv

Download patch

ref: 637a770a1698da227bcd296bd5578d978bea6e34
parent: fff6d18d5135b5a5580e5ea842958114325a508d
author: cinap_lenrek <cinap_lenrek@localhost>
date: Mon Jun 27 01:43:25 EDT 2011

hgfs: update index

--- a/sys/src/cmd/hgfs/dat.h
+++ b/sys/src/cmd/hgfs/dat.h
@@ -36,6 +36,8 @@
 	int	ifd;
 	int	dfd;
 
+	vlong	ioff;
+
 	int	nmap;
 	Revmap	*map;
 };
--- a/sys/src/cmd/hgfs/fns.h
+++ b/sys/src/cmd/hgfs/fns.h
@@ -13,6 +13,7 @@
 /* revlog */
 int fmktemp(void);
 int revlogopen(Revlog *r, char *path, int mode);
+void revlogupdate(Revlog *r);
 void revlogclose(Revlog *r);
 int revlogextract(Revlog *r, int rev, int ofd);
 uchar *revhash(Revlog *r, int rev);
--- a/sys/src/cmd/hgfs/fs.c
+++ b/sys/src/cmd/hgfs/fs.c
@@ -311,6 +311,9 @@
 	} else {
 		switch(rf->level){
 		case Qroot:
+			revlogupdate(&changelog);
+			revlogupdate(&manifest);
+
 			i = findrev(&changelog, name);
 			if(rf->info = getrevinfo(i)){
 				rf->level = Qrev;
@@ -455,6 +458,9 @@
 			respond(r, "bug in fsread");
 			return;
 		case Qroot:
+			revlogupdate(&changelog);
+			revlogupdate(&manifest);
+
 			dirread9p(r, rootgen, nil);
 			respond(r, nil);
 			return;
--- a/sys/src/cmd/hgfs/revlog.c
+++ b/sys/src/cmd/hgfs/revlog.c
@@ -13,15 +13,16 @@
 	return create(mktemp(temp), OTRUNC|ORCLOSE|ORDWR, 0666);
 }
 
-static void
-readindex(Revlog *r)
+void
+revlogupdate(Revlog *r)
 {
 	uchar buf[64];
 	Revmap *m;
 	int rev;
 
-	seek(r->ifd, 0, 0);
-	for(rev=0;;rev++){
+	if(seek(r->ifd, r->ioff, 0) < 0)
+		return;
+	for(rev=r->nmap;;rev++){
 		if(readn(r->ifd, buf, sizeof(buf)) != sizeof(buf))
 			break;
 		if((rev % 16) == 0)
@@ -48,8 +49,9 @@
 
 		if(r->dfd < 0){
 			m->hoff = seek(r->ifd, 0, 1);
-			seek(r->ifd, m->hlen, 1);
-		}
+			r->ioff = seek(r->ifd, m->hlen, 1);
+		} else
+			r->ioff = seek(r->ifd, 0, 1);
 	}
 	r->nmap = rev;
 }
@@ -67,9 +69,10 @@
 	path[strlen(path)-1] = 'd';
 	r->dfd = open(path, mode);
 	free(path);
+	r->ioff = 0;
 	r->nmap = 0;
 	r->map = nil;
-	readindex(r);
+	revlogupdate(r);
 	return 0;
 }