# HG changeset patch # User Artem Tikhomirov # Date 1297890039 -3600 # Node ID 3959bffb14e967b54198f49ccd2a79618b371f3b # Parent afac8ddc5dd277e2295b82a870582c45b42d3938 explicit op name instead math op to get last rev number diff -r afac8ddc5dd2 -r 3959bffb14e9 src/org/tmatesoft/hg/repo/HgChangelog.java --- a/src/org/tmatesoft/hg/repo/HgChangelog.java Wed Feb 16 21:51:32 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgChangelog.java Wed Feb 16 22:00:39 2011 +0100 @@ -44,7 +44,7 @@ } public void all(final HgChangelog.Inspector inspector) { - range(0, content.revisionCount() - 1, inspector); + range(0, lastRevision(), inspector); } public void range(int start, int end, final HgChangelog.Inspector inspector) { diff -r afac8ddc5dd2 -r 3959bffb14e9 src/org/tmatesoft/hg/repo/HgDataFile.java --- a/src/org/tmatesoft/hg/repo/HgDataFile.java Wed Feb 16 21:51:32 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgDataFile.java Wed Feb 16 22:00:39 2011 +0100 @@ -97,7 +97,7 @@ @Override public byte[] content(int revision) { if (revision == TIP) { - revision = content.revisionCount() - 1; // FIXME maxRevision. + revision = getLastRevision(); } byte[] data = super.content(revision); if (metadata == null) { @@ -154,14 +154,14 @@ } public void history(HgChangelog.Inspector inspector) { - history(0, content.revisionCount() - 1, inspector); + history(0, getLastRevision(), inspector); } public void history(int start, int end, HgChangelog.Inspector inspector) { if (!exists()) { throw new IllegalStateException("Can't get history of invalid repository file node"); } - final int last = content.revisionCount() - 1; + final int last = getLastRevision(); if (start < 0 || start > last) { throw new IllegalArgumentException(); } diff -r afac8ddc5dd2 -r 3959bffb14e9 src/org/tmatesoft/hg/repo/HgStatusCollector.java --- a/src/org/tmatesoft/hg/repo/HgStatusCollector.java Wed Feb 16 21:51:32 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgStatusCollector.java Wed Feb 16 22:00:39 2011 +0100 @@ -105,10 +105,10 @@ ((Record) inspector).init(rev1, rev2, this); } if (rev1 == TIP) { - rev1 = repo.getManifest().getRevisionCount() - 1; + rev1 = repo.getManifest().getLastRevision(); } if (rev2 == TIP) { - rev2 = repo.getManifest().getRevisionCount() - 1; // XXX add Revlog.tip() func ? + rev2 = repo.getManifest().getLastRevision(); } // in fact, rev1 and rev2 are often next (or close) to each other, // thus, we can optimize Manifest reads here (manifest.walk(rev1, rev2)) diff -r afac8ddc5dd2 -r 3959bffb14e9 src/org/tmatesoft/hg/repo/Revlog.java --- a/src/org/tmatesoft/hg/repo/Revlog.java Wed Feb 16 21:51:32 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/Revlog.java Wed Feb 16 22:00:39 2011 +0100 @@ -62,16 +62,20 @@ return repo; } - public int getRevisionCount() { + public final int getRevisionCount() { return content.revisionCount(); } - public Nodeid getRevision(int revision) { + public final int getLastRevision() { + return content.revisionCount() - 1; + } + + public final Nodeid getRevision(int revision) { // XXX cache nodeids? return Nodeid.fromBinary(content.nodeid(revision), 0); } - public int getLocalRevision(Nodeid nid) { + public final int getLocalRevision(Nodeid nid) { int revision = content.findLocalRevisionNumber(nid); if (revision == BAD_REVISION) { throw new IllegalArgumentException(String.format("%s doesn't represent a revision of %s", nid.toString(), this /*XXX HgDataFile.getPath might be more suitable here*/)); @@ -80,7 +84,7 @@ } // Till now, i follow approach that NULL nodeid is never part of revlog - public boolean isKnown(Nodeid nodeid) { + public final boolean isKnown(Nodeid nodeid) { final int rn = content.findLocalRevisionNumber(nodeid); if (Integer.MIN_VALUE == rn) { return false; diff -r afac8ddc5dd2 -r 3959bffb14e9 test/org/tmatesoft/hg/test/TestByteChannel.java --- a/test/org/tmatesoft/hg/test/TestByteChannel.java Wed Feb 16 21:51:32 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestByteChannel.java Wed Feb 16 22:00:39 2011 +0100 @@ -34,7 +34,7 @@ HgRepoFacade rf = new HgRepoFacade(); rf.init(); HgDataFile file = rf.getRepository().getFileNode("src/org/tmatesoft/hg/internal/KeywordFilter.java"); - for (int i = file.getRevisionCount() - 1; i >= 0; i--) { + for (int i = file.getLastRevision(); i >= 0; i--) { System.out.print("Content for revision:" + i); compareContent(file, i); System.out.println(" OK");