comparison src/com/tmate/hgkit/ll/HgManifest.java @ 19:40532cdc92fc

Inspector (visitor) for manifest
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 04 Jan 2011 01:01:39 +0100
parents 254078595653
children 11cfabe692b3
comparison
equal deleted inserted replaced
18:02ee376bee79 19:40532cdc92fc
1 /* 1 /*
2 * Copyright (c) 2010 Artem Tikhomirov 2 * Copyright (c) 2010, 2011 Artem Tikhomirov
3 */ 3 */
4 package com.tmate.hgkit.ll; 4 package com.tmate.hgkit.ll;
5 5
6 /** 6 /**
7 * 7 *
14 /*package-local*/ HgManifest(HgRepository hgRepo, RevlogStream content) { 14 /*package-local*/ HgManifest(HgRepository hgRepo, RevlogStream content) {
15 super(hgRepo); 15 super(hgRepo);
16 this.content = content; 16 this.content = content;
17 } 17 }
18 18
19 public void dump() { 19 public void walk(int start, int end, final Inspector inspector) {
20 Revlog.Inspector insp = new Revlog.Inspector() { 20 Revlog.Inspector insp = new Revlog.Inspector() {
21
22 private boolean gtg = true; // good to go
23
21 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { 24 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
22 System.out.printf("%d : %s\n", revisionNumber, new Nodeid(nodeid)); 25 if (!gtg) {
26 return;
27 }
28 gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid));
23 int i; 29 int i;
24 String fname = null; 30 String fname = null;
25 String flags = null; 31 String flags = null;
26 Nodeid nid = null; 32 Nodeid nid = null;
27 for (i = 0; i < actualLen; i++) { 33 for (i = 0; gtg && i < actualLen; i++) {
28 int x = i; 34 int x = i;
29 for( ; data[i] != '\n' && i < actualLen; i++) { 35 for( ; data[i] != '\n' && i < actualLen; i++) {
30 if (fname == null && data[i] == 0) { 36 if (fname == null && data[i] == 0) {
31 fname = new String(data, x, i - x); 37 fname = new String(data, x, i - x);
32 x = i+1; 38 x = i+1;
39 if (nodeidLen + x < i) { 45 if (nodeidLen + x < i) {
40 // 'x' and 'l' for executable bits and symlinks? 46 // 'x' and 'l' for executable bits and symlinks?
41 // hg --debug manifest shows 644 for each regular file in my repo 47 // hg --debug manifest shows 644 for each regular file in my repo
42 flags = new String(data, x + nodeidLen, i-x-nodeidLen); 48 flags = new String(data, x + nodeidLen, i-x-nodeidLen);
43 } 49 }
44 System.out.println(nid + "\t" + fname + "\t\t" + flags); 50 gtg = gtg && inspector.next(nid, fname, flags);
51
45 } 52 }
46 nid = null; 53 nid = null;
47 fname = flags = null; 54 fname = flags = null;
48 } 55 }
49 System.out.println(); 56 gtg = gtg && inspector.end(revisionNumber);
50 } 57 }
51 }; 58 };
52 content.iterate(0, -1, true, insp); 59 content.iterate(start, end, true, insp);
60 }
61
62 public interface Inspector {
63 boolean begin(int revision, Nodeid nid);
64 boolean next(Nodeid nid, String fname, String flags);
65 boolean end(int revision);
53 } 66 }
54 } 67 }