Mercurial > jhg
changeset 48:e34f90b9ded1
Limit option for history/log
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 14 Jan 2011 23:22:20 +0100 |
parents | b01500fe2604 |
children | 26e3eeaa3962 |
files | src/com/tmate/hgkit/console/Log.java src/com/tmate/hgkit/fs/RepositoryLookup.java src/com/tmate/hgkit/ll/Changelog.java src/com/tmate/hgkit/ll/HgDataFile.java |
diffstat | 4 files changed, 57 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/com/tmate/hgkit/console/Log.java Fri Jan 14 20:03:14 2011 +0100 +++ b/src/com/tmate/hgkit/console/Log.java Fri Jan 14 23:22:20 2011 +0100 @@ -32,13 +32,31 @@ dump.reverseOrder = true; if (cmdLineOpts.files.isEmpty()) { // no revisions and no limit - hgRepo.getChangelog().all(dump); + if (cmdLineOpts.limit == -1) { + hgRepo.getChangelog().all(dump); + } else { + int[] r = new int[] { 0, hgRepo.getChangelog().getRevisionCount() }; + if (fixRange(r, dump.reverseOrder, cmdLineOpts.limit) == 0) { + System.out.println("No changes"); + return; + } + hgRepo.getChangelog().range(r[0], r[1], dump); + } dump.complete(); } else { for (String fname : cmdLineOpts.files) { HgDataFile f1 = hgRepo.getFileNode(fname); System.out.println("History of the file: " + f1.getPath()); - f1.history(dump); + if (cmdLineOpts.limit == -1) { + f1.history(dump); + } else { + int[] r = new int[] { 0, f1.getRevisionCount() }; + if (fixRange(r, dump.reverseOrder, cmdLineOpts.limit) == 0) { + System.out.println("No changes"); + continue; + } + f1.history(r[0], r[1], dump); + } dump.complete(); } } @@ -49,6 +67,21 @@ // //new ChangelogWalker().setFile("hello.c").setRevisionRange(1, 4).accept(new Visitor); } + + private static int fixRange(int[] start_end, boolean reverse, int limit) { + assert start_end.length == 2; + if (limit < start_end[1]) { + if (reverse) { + // adjust left boundary of the range + start_end[0] = start_end[1] - limit; + } else { + start_end[1] = limit; // adjust right boundary + } + } + int rv = start_end[1] - start_end[0]; + start_end[1]--; // range needs index, not length + return rv; + } private static final class Dump implements Changeset.Inspector { // params @@ -86,17 +119,17 @@ Formatter f = new Formatter(sb); f.format("changeset: %d:%s\n", revNumber, complete ? csetNodeid : csetNodeid.shortNotation()); if (complete) { - f.format("parent: %s\nparent: %s\nmanifest: %s", "-1", "-1", cset.manifest()); + f.format("parent: %s\nparent: %s\nmanifest: %s\n", "-1", "-1", cset.manifest()); } f.format("user: %s\ndate: %s\n", cset.user(), cset.dateString()); if (complete) { final List<String> files = cset.files(); - sb.append("files: "); + sb.append("files: "); for (String s : files) { sb.append(' '); sb.append(s); } - f.format("description:\n%s\n\n", cset.comment()); + f.format("\ndescription:\n%s\n\n", cset.comment()); } else { f.format("summary: %s\n\n", cset.comment()); }
--- a/src/com/tmate/hgkit/fs/RepositoryLookup.java Fri Jan 14 20:03:14 2011 +0100 +++ b/src/com/tmate/hgkit/fs/RepositoryLookup.java Fri Jan 14 23:22:20 2011 +0100 @@ -56,6 +56,7 @@ public String repoLocation; public List<String> files; + public int limit = -1; public static Options parse(String[] commandLineArgs) { Options rv = new Options(); @@ -76,6 +77,13 @@ rv.repoLocation = it.next(); break; } + case (int) 'l' : { + if (!it.hasNext()) { + throw new IllegalArgumentException(); + } + rv.limit = Integer.parseInt(it.next()); + break; + } } } else { // filename
--- a/src/com/tmate/hgkit/ll/Changelog.java Fri Jan 14 20:03:14 2011 +0100 +++ b/src/com/tmate/hgkit/ll/Changelog.java Fri Jan 14 23:22:20 2011 +0100 @@ -18,6 +18,10 @@ } public void all(final Changeset.Inspector inspector) { + range(0, content.revisionCount() - 1, inspector); + } + + public void range(int start, int end, final Changeset.Inspector inspector) { Revlog.Inspector i = new Revlog.Inspector() { public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { @@ -26,7 +30,7 @@ inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); } }; - content.iterate(0, content.revisionCount() - 1, true, i); + content.iterate(start, end, true, i); } public List<Changeset> range(int start, int end) {
--- a/src/com/tmate/hgkit/ll/HgDataFile.java Fri Jan 14 20:03:14 2011 +0100 +++ b/src/com/tmate/hgkit/ll/HgDataFile.java Fri Jan 14 23:22:20 2011 +0100 @@ -42,10 +42,14 @@ } public void history(Changeset.Inspector inspector) { + history(0, content.revisionCount() - 1, inspector); + } + + public void history(int start, int end, Changeset.Inspector inspector) { if (!exists()) { throw new IllegalStateException("Can't get history of invalid repository file node"); } - final int[] commitRevisions = new int[content.revisionCount()]; + final int[] commitRevisions = new int[end - start + 1]; Revlog.Inspector insp = new Revlog.Inspector() { int count = 0; @@ -53,14 +57,10 @@ commitRevisions[count++] = linkRevision; } }; - content.iterate(0, -1, false, insp); + content.iterate(start, end, false, insp); getRepo().getChangelog().range(inspector, commitRevisions); } - public void history(int start, int end, Changeset.Inspector i) { - throw HgRepository.notImplemented(); - } - /** * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query? *