Mercurial > hg4j
changeset 19:40532cdc92fc
Inspector (visitor) for manifest
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 04 Jan 2011 01:01:39 +0100 |
parents | 02ee376bee79 |
children | 11cfabe692b3 |
files | src/com/tmate/hgkit/console/Manifest.java src/com/tmate/hgkit/ll/HgManifest.java |
diffstat | 2 files changed, 42 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/com/tmate/hgkit/console/Manifest.java Mon Jan 03 20:42:52 2011 +0100 +++ b/src/com/tmate/hgkit/console/Manifest.java Tue Jan 04 01:01:39 2011 +0100 @@ -1,10 +1,14 @@ /* - * Copyright (c) 2010 Artem Tikhomirov + * Copyright (c) 2010, 2011 Artem Tikhomirov */ package com.tmate.hgkit.console; +import static com.tmate.hgkit.ll.HgRepository.TIP; + import com.tmate.hgkit.fs.RepositoryLookup; +import com.tmate.hgkit.ll.HgManifest; import com.tmate.hgkit.ll.HgRepository; +import com.tmate.hgkit.ll.Nodeid; /** * @@ -21,6 +25,22 @@ return; } System.out.println(hgRepo.getLocation()); - hgRepo.getManifest().dump(); + HgManifest.Inspector insp = new HgManifest.Inspector() { + public boolean begin(int revision, Nodeid nid) { + System.out.printf("%d : %s\n", revision, nid); + return true; + } + + public boolean next(Nodeid nid, String fname, String flags) { + System.out.println(nid + "\t" + fname + "\t\t" + flags); + return true; + } + + public boolean end(int revision) { + System.out.println(); + return true; + } + }; + hgRepo.getManifest().walk(0, TIP, insp); } }
--- a/src/com/tmate/hgkit/ll/HgManifest.java Mon Jan 03 20:42:52 2011 +0100 +++ b/src/com/tmate/hgkit/ll/HgManifest.java Tue Jan 04 01:01:39 2011 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Artem Tikhomirov + * Copyright (c) 2010, 2011 Artem Tikhomirov */ package com.tmate.hgkit.ll; @@ -16,15 +16,21 @@ this.content = content; } - public void dump() { + public void walk(int start, int end, final Inspector inspector) { Revlog.Inspector insp = new Revlog.Inspector() { + + private boolean gtg = true; // good to go + public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { - System.out.printf("%d : %s\n", revisionNumber, new Nodeid(nodeid)); + if (!gtg) { + return; + } + gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid)); int i; String fname = null; String flags = null; Nodeid nid = null; - for (i = 0; i < actualLen; i++) { + for (i = 0; gtg && i < actualLen; i++) { int x = i; for( ; data[i] != '\n' && i < actualLen; i++) { if (fname == null && data[i] == 0) { @@ -41,14 +47,21 @@ // hg --debug manifest shows 644 for each regular file in my repo flags = new String(data, x + nodeidLen, i-x-nodeidLen); } - System.out.println(nid + "\t" + fname + "\t\t" + flags); + gtg = gtg && inspector.next(nid, fname, flags); + } nid = null; fname = flags = null; } - System.out.println(); + gtg = gtg && inspector.end(revisionNumber); } }; - content.iterate(0, -1, true, insp); + content.iterate(start, end, true, insp); + } + + public interface Inspector { + boolean begin(int revision, Nodeid nid); + boolean next(Nodeid nid, String fname, String flags); + boolean end(int revision); } }