shithub: riscv

Download patch

ref: 5cb6be9ce3bb53909879d6911cc2411f8458ed10
parent: ce59d96ee34905b58d39fa6e7defdf75220032ea
author: cinap_lenrek <[email protected]>
date: Thu Nov 1 23:31:55 EDT 2012

hgfs: fix metaheader offset for log

--- a/sys/src/cmd/hgfs/fs.c
+++ b/sys/src/cmd/hgfs/fs.c
@@ -303,7 +303,9 @@
 					 * BUG: this is not correct. mercurial might
 					 * prefix the data log with random \1\n escaped
 					 * metadata strings (see fmetaheader()) and the flen
-					 * *includes* the metadata part. m(
+					 * *includes* the metadata part. we try to compensate
+					 * for this once the revision got extracted and
+					 * subtract the metadata header in fsstat().
 					 */
 					d->length = rl->map[rev].flen;
 				}
@@ -353,6 +355,7 @@
 	rf->rlog = nil;
 
 	rf->fd = -1;
+	rf->doff = 0;
 	rf->buf = nil;
 
 	r->fid->aux = rf;
@@ -368,8 +371,11 @@
 	rf = r->fid->aux;
 	if(rf->level < Qtree)
 		fsmkdir(&r->d, rf->level,  rf->info);
-	else
+	else {
 		fsmkdir(&r->d, rf->level,  rf->node);
+		if(rf->level == Qtree)
+			r->d.length -= rf->doff;
+	}
 	respond(r, nil);
 }
 
@@ -686,7 +692,6 @@
 			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){
@@ -693,7 +698,7 @@
 			responderror(r);
 			return;
 		}
-		rf->doff = fmetaheader(rf->fd);
+		rf->doff = rf->info->logoff;
 		goto Fdgen;
 	case Qwho:
 		s = rf->info->who;
--- a/sys/src/cmd/hgfs/info.c
+++ b/sys/src/cmd/hgfs/info.c
@@ -17,14 +17,15 @@
 
 	seek(fd, 0, 2);
 	write(fd, "\n", 1);
-	seek(fd, 0, 0);
 
+	off = fmetaheader(fd);
+	seek(fd, off, 0);
+
 	ri = malloc(sizeof(*ri));
 	memset(ri, 0, sizeof(*ri));
 
 	memmove(ri->chash, changelog->map[rev].hash, HASHSZ);
 
-	off = 0;
 	line = 0;
 	inmsg = 0;
 	p = buf;