Mercurial > jhg
diff src/org/tmatesoft/hg/repo/Revlog.java @ 405:866fc3b597a0
Add an explicit constant instead of -1 to indicate 'no revision' case
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 14 Mar 2012 22:49:32 +0100 |
parents | 2747b0723867 |
children | d30083c80d52 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/Revlog.java Mon Mar 05 14:50:51 2012 +0100 +++ b/src/org/tmatesoft/hg/repo/Revlog.java Wed Mar 14 22:49:32 2012 +0100 @@ -17,6 +17,7 @@ package org.tmatesoft.hg.repo; import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; +import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; import static org.tmatesoft.hg.repo.HgRepository.TIP; import java.io.IOException; @@ -228,13 +229,14 @@ } /** - * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query? + * Fills supplied arguments with information about revision parents. * * @param revision - revision to query parents, or {@link HgRepository#TIP} - * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1}) + * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1}), {@link HgRepository#NO_REVISION} indicates parent not set * @param parent1 - byte[20] or null, if parent's nodeid is not needed * @param parent2 - byte[20] or null, if second parent's nodeid is not needed * @throws HgInvalidRevisionException + * @throws HgInvalidControlFileException FIXME * @throws IllegalArgumentException */ public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) throws HgInvalidRevisionException, HgInvalidControlFileException { @@ -265,10 +267,11 @@ }; ParentCollector pc = new ParentCollector(); content.iterate(revision, revision, false, pc); - parentRevisions[0] = pc.p1; - parentRevisions[1] = pc.p2; + // although next code looks odd (NO_REVISION *is* -1), it's safer to be explicit + parentRevisions[0] = pc.p1 == -1 ? NO_REVISION : pc.p1; + parentRevisions[1] = pc.p2 == -1 ? NO_REVISION : pc.p2; if (parent1 != null) { - if (parentRevisions[0] == -1) { + if (parentRevisions[0] == NO_REVISION) { Arrays.fill(parent1, 0, 20, (byte) 0); } else { content.iterate(parentRevisions[0], parentRevisions[0], false, pc); @@ -276,7 +279,7 @@ } } if (parent2 != null) { - if (parentRevisions[1] == -1) { + if (parentRevisions[1] == NO_REVISION) { Arrays.fill(parent2, 0, 20, (byte) 0); } else { content.iterate(parentRevisions[1], parentRevisions[1], false, pc);