shithub: riscv

Download patch

ref: d0485d345db63b0ee82301251339e72d6093107d
parent: 402ee30714c2cefa9116ff2031672bc6a8cd5c0b
author: cinap_lenrek <cinap_lenrek@localhost>
date: Mon Jun 27 06:07:19 EDT 2011

hgfs: change semantics of log to contain only the file list

--- a/sys/src/cmd/hgfs/dat.h
+++ b/sys/src/cmd/hgfs/dat.h
@@ -63,6 +63,9 @@
 	char	*who;
 	char	*why;
 	long	when;
+
+	vlong	logoff;
+	vlong	loglen;
 };
 
 struct Revtree
--- a/sys/src/cmd/hgfs/fs.c
+++ b/sys/src/cmd/hgfs/fs.c
@@ -197,8 +197,7 @@
 		goto Strgen;
 	case Qlog:
 		ri = aux;
-		if((rev = hashrev(&changelog, ri->chash)) >= 0)
-			d->length = changelog.map[rev].flen;
+		d->length = ri->loglen;
 		goto Namegen;
 	case Qwho:
 		ri = aux;
@@ -512,7 +511,12 @@
 	Revlog rl;
 	char *s;
 	int i, n;
+	vlong off;
+	int len;
 
+	off = r->ifcall.offset;
+	len = r->ifcall.count;
+
 	rf = r->fid->aux;
 	switch(rf->level){
 	case Qroot:
@@ -540,6 +544,11 @@
 		}
 		goto Strgen;
 	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)
 			goto Fdgen;
 		if((rf->fd = revlogopentemp(&changelog, hashrev(&changelog, rf->info->chash))) < 0){
@@ -580,7 +589,7 @@
 		}
 		revlogclose(&rl);
 	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);
 			return;
 		}
--- a/sys/src/cmd/hgfs/info.c
+++ b/sys/src/cmd/hgfs/info.c
@@ -10,6 +10,7 @@
 	char buf[BUFSZ], *p, *e;
 	int fd, line, inmsg, n;
 	Revinfo *ri;
+	vlong off;
 
 	if((fd = revlogopentemp(changelog, rev)) < 0)
 		return nil;
@@ -23,6 +24,7 @@
 
 	memmove(ri->chash, changelog->map[rev].hash, HASHSZ);
 
+	off = 0;
 	line = 0;
 	inmsg = 0;
 	p = buf;
@@ -42,10 +44,14 @@
 			case 2:
 				ri->when = strtol(buf, nil, 10);
 				break;
+			case 3:
+				ri->logoff = off;
 			default:
 				if(!inmsg){
-					if(*buf == 0)
+					if(*buf == 0){
+						ri->loglen = off - ri->logoff;
 						inmsg = 1;
+					}
 				} else {
 					n = ri->why ? strlen(ri->why) : 0;
 					ri->why = realloc(ri->why, n + strlen(buf)+1);
@@ -52,9 +58,11 @@
 					strcpy(ri->why + n, buf);
 				}
 			}
-			p -= e - buf;
+			n = e - buf;
+			p -= n;
 			if(p > buf)
 				memmove(buf, e, p - buf);
+			off += n;
 		}
 		e = buf + BUFSZ;
 	}
--- a/sys/src/cmd/hgfs/tree.c
+++ b/sys/src/cmd/hgfs/tree.c
@@ -201,41 +201,41 @@
 {
 	char buf[BUFSZ], *p, *e;
 	Hashstr *ht[256], *he, **hp;
-	int fd, done, line, n;
+	int fd, n;
 	Revtree *t;
+	vlong off;
 
 	if((fd = revlogopentemp(changelog, hashrev(changelog, ri->chash))) < 0)
 		return nil;
 
-	done = 0;
-	line = 0;
+	off = seek(fd, ri->logoff, 0);
+	if(off < 0){
+		close(fd);
+		return nil;
+	}
+
 	memset(ht, 0, sizeof(ht));
 
 	p = buf;
 	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;
 		while((p > buf) && (e = memchr(buf, '\n', p - buf))){
 			*e++ = 0;
 
-			if(++line >= 4){
-				if(*buf == 0){
-					done = 1;
-					break;
-				}
+			he = malloc(sizeof(*he) + strlen(buf)+1);
+			hp = &ht[hashstr(strcpy(he->str, buf)) % nelem(ht)];
+			he->next = *hp;
+			*hp = he;
 
-				he = malloc(sizeof(*he) + strlen(buf)+1);
-				hp = &ht[hashstr(strcpy(he->str, buf)) % nelem(ht)];
-				he->next = *hp;
-				*hp = he;
-			}
-
-			p -= e - buf;
+			n = e - buf;
+			p -= n;
 			if(p > buf)
 				memmove(buf, e, p - buf);
+			off += n;
 		}
-		if(done)
-			break;
 		e = buf + BUFSZ;
 	}
 	close(fd);