summaryrefslogtreecommitdiff
path: root/sys/src/cmd/hgfs/info.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@localhost>2011-06-26 07:03:12 +0200
committercinap_lenrek <cinap_lenrek@localhost>2011-06-26 07:03:12 +0200
commitbc1ff6985c03402497a052d2b4e2a299b3cdf218 (patch)
tree92dcfc77cd3fed9adae59994fd4825a7770bead8 /sys/src/cmd/hgfs/info.c
parent8fa679d04171417d9420b91471cf45e148b4cc50 (diff)
add hgfs, a mercurial filesystem
Diffstat (limited to 'sys/src/cmd/hgfs/info.c')
-rw-r--r--sys/src/cmd/hgfs/info.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/sys/src/cmd/hgfs/info.c b/sys/src/cmd/hgfs/info.c
new file mode 100644
index 000000000..66246a9e2
--- /dev/null
+++ b/sys/src/cmd/hgfs/info.c
@@ -0,0 +1,64 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include "dat.h"
+#include "fns.h"
+
+Revinfo*
+loadrevinfo(Revlog *changelog, int rev)
+{
+ char buf[BUFSZ], *p, *e;
+ int fd, line, inmsg, n;
+ Revinfo *ri;
+
+ if((fd = revlogopentemp(changelog, rev)) < 0)
+ return nil;
+
+ seek(fd, 0, 2);
+ write(fd, "\n", 1);
+ seek(fd, 0, 0);
+
+ ri = malloc(sizeof(*ri));
+ memset(ri, 0, sizeof(*ri));
+
+ memmove(ri->chash, changelog->map[rev].hash, HASHSZ);
+
+ line = 0;
+ inmsg = 0;
+ p = buf;
+ e = buf + BUFSZ;
+ while((n = read(fd, p, e - p)) > 0){
+ p += n;
+ while((p > buf) && (e = memchr(buf, '\n', p - buf))){
+ *e++ = 0;
+
+ switch(line++){
+ case 0:
+ strhash(buf, ri->mhash);
+ break;
+ case 1:
+ ri->who = strdup(buf);
+ break;
+ case 2:
+ ri->when = strtol(buf, nil, 10);
+ break;
+ default:
+ if(!inmsg){
+ if(*buf == 0)
+ inmsg = 1;
+ } else {
+ n = ri->why ? strlen(ri->why) : 0;
+ ri->why = realloc(ri->why, n + strlen(buf)+1);
+ strcpy(ri->why + n, buf);
+ }
+ }
+ p -= e - buf;
+ if(p > buf)
+ memmove(buf, e, p - buf);
+ }
+ e = buf + BUFSZ;
+ }
+ close(fd);
+
+ return ri;
+}