Mercurial > jhg
changeset 135:3959bffb14e9
explicit op name instead math op to get last rev number
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 16 Feb 2011 22:00:39 +0100 |
parents | afac8ddc5dd2 |
children | 947bf231acbb |
files | src/org/tmatesoft/hg/repo/HgChangelog.java src/org/tmatesoft/hg/repo/HgDataFile.java src/org/tmatesoft/hg/repo/HgStatusCollector.java src/org/tmatesoft/hg/repo/Revlog.java test/org/tmatesoft/hg/test/TestByteChannel.java |
diffstat | 5 files changed, 15 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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) {
--- 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(); }
--- 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))
--- 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;
--- 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");