# HG changeset patch # User Artem Tikhomirov # Date 1314237459 -7200 # Node ID 9fb50c04f03c297e43df013a8c789e9eefc827dc # Parent 8f872bd7ddd254b4fa6e1d4ecf0c122f9c48ae61 Use Nodeid.isNull check instead of NULL.equals diff -r 8f872bd7ddd2 -r 9fb50c04f03c cmdline/org/tmatesoft/hg/console/ChangesetDumpHandler.java --- a/cmdline/org/tmatesoft/hg/console/ChangesetDumpHandler.java Thu Aug 25 03:56:27 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/ChangesetDumpHandler.java Thu Aug 25 03:57:39 2011 +0200 @@ -104,8 +104,8 @@ if (complete) { Nodeid p1 = cset.getFirstParentRevision(); Nodeid p2 = cset.getSecondParentRevision(); - int p1x = p1 == Nodeid.NULL ? -1 : repo.getChangelog().getLocalRevision(p1); - int p2x = p2 == Nodeid.NULL ? -1 : repo.getChangelog().getLocalRevision(p2); + int p1x = p1.isNull() ? -1 : repo.getChangelog().getLocalRevision(p1); + int p2x = p2.isNull() ? -1 : repo.getChangelog().getLocalRevision(p2); int mx = repo.getManifest().getLocalRevision(cset.getManifestRevision()); f.format("parent: %d:%s\nparent: %d:%s\nmanifest: %d:%s\n", p1x, p1, p2x, p2, mx, cset.getManifestRevision()); } diff -r 8f872bd7ddd2 -r 9fb50c04f03c src/org/tmatesoft/hg/core/HgChangeset.java --- a/src/org/tmatesoft/hg/core/HgChangeset.java Thu Aug 25 03:56:27 2011 +0200 +++ b/src/org/tmatesoft/hg/core/HgChangeset.java Thu Aug 25 03:57:39 2011 +0200 @@ -16,8 +16,6 @@ */ package org.tmatesoft.hg.core; -import static org.tmatesoft.hg.core.Nodeid.NULL; - import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -140,9 +138,12 @@ public boolean isMerge() { // p1 == -1 and p2 != -1 is legitimate case - return !NULL.equals(getFirstParentRevision()) && !NULL.equals(getSecondParentRevision()); + return !(getFirstParentRevision().isNull() || getSecondParentRevision().isNull()); } + /** + * @return never null + */ public Nodeid getFirstParentRevision() { if (parentHelper != null) { return parentHelper.safeFirstParent(nodeid); @@ -156,6 +157,9 @@ return Nodeid.fromBinary(parent1, 0); } + /** + * @return never null + */ public Nodeid getSecondParentRevision() { if (parentHelper != null) { return parentHelper.safeSecondParent(nodeid); diff -r 8f872bd7ddd2 -r 9fb50c04f03c src/org/tmatesoft/hg/core/HgCloneCommand.java --- a/src/org/tmatesoft/hg/core/HgCloneCommand.java Thu Aug 25 03:56:27 2011 +0200 +++ b/src/org/tmatesoft/hg/core/HgCloneCommand.java Thu Aug 25 03:57:39 2011 +0200 @@ -232,7 +232,7 @@ } private int knownRevision(Nodeid p) { - if (NULL.equals(p)) { + if (p.isNull()) { return -1; } else { for (int i = revisionSequence.size() - 1; i >= 0; i--) { @@ -250,7 +250,7 @@ boolean writeComplete = false; Nodeid p1 = ge.firstParent(); Nodeid p2 = ge.secondParent(); - if (NULL.equals(p1) && NULL.equals(p2) /* or forced flag, does REVIDX_PUNCHED_FLAG indicate that? */) { + if (p1.isNull() && p2.isNull() /* or forced flag, does REVIDX_PUNCHED_FLAG indicate that? */) { prevRevContent = new ByteArrayDataAccess(new byte[0]); writeComplete = true; } diff -r 8f872bd7ddd2 -r 9fb50c04f03c src/org/tmatesoft/hg/core/HgFileInformer.java --- a/src/org/tmatesoft/hg/core/HgFileInformer.java Thu Aug 25 03:56:27 2011 +0200 +++ b/src/org/tmatesoft/hg/core/HgFileInformer.java Thu Aug 25 03:57:39 2011 +0200 @@ -58,7 +58,7 @@ * @return this for convenience */ public HgFileInformer changeset(Nodeid nid) { - if (nid == null || Nodeid.NULL.equals(nid)) { + if (nid == null || nid.isNull()) { throw new IllegalArgumentException(); } cset = nid; diff -r 8f872bd7ddd2 -r 9fb50c04f03c src/org/tmatesoft/hg/internal/RepositoryComparator.java --- a/src/org/tmatesoft/hg/internal/RepositoryComparator.java Thu Aug 25 03:56:27 2011 +0200 +++ b/src/org/tmatesoft/hg/internal/RepositoryComparator.java Thu Aug 25 03:57:39 2011 +0200 @@ -155,10 +155,10 @@ checkUp2Head.add(rb); } else { // dig deeper in the history, if necessary - if (!NULL.equals(rb.p1) && !localRepo.knownNode(rb.p1)) { + if (!rb.p1.isNull() && !localRepo.knownNode(rb.p1)) { toQuery.add(rb.p1); } - if (!NULL.equals(rb.p2) && !localRepo.knownNode(rb.p2)) { + if (!rb.p2.isNull() && !localRepo.knownNode(rb.p2)) { toQuery.add(rb.p2); } } @@ -245,7 +245,7 @@ } else { chainElement.branchRoot = rb.root; // dig deeper in the history, if necessary - boolean hasP1 = !NULL.equals(rb.p1), hasP2 = !NULL.equals(rb.p2); + boolean hasP1 = !rb.p1.isNull(), hasP2 = !rb.p2.isNull(); if (hasP1 && !localRepo.knownNode(rb.p1)) { toQuery.add(rb.p1); // we might have seen parent node already, and recorded it as a branch chain @@ -356,7 +356,7 @@ // true when this BranchChain is a branch that spans up to very start of the repository // Thus, the only common revision is NULL, recorded in a fake BranchChain object shared between p1 and p2 /*package-local*/ boolean isRepoStart() { - return p1 == p2 && p1 != null && p1.branchHead == p1.branchRoot && NULL.equals(p1.branchHead); + return p1 == p2 && p1 != null && p1.branchHead == p1.branchRoot && p1.branchHead.isNull(); } @Override diff -r 8f872bd7ddd2 -r 9fb50c04f03c src/org/tmatesoft/hg/repo/HgBundle.java --- a/src/org/tmatesoft/hg/repo/HgBundle.java Thu Aug 25 03:56:27 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgBundle.java Thu Aug 25 03:57:39 2011 +0200 @@ -16,8 +16,6 @@ */ package org.tmatesoft.hg.repo; -import static org.tmatesoft.hg.core.Nodeid.NULL; - import java.io.File; import java.io.IOException; import java.util.LinkedList; @@ -141,7 +139,7 @@ HgChangelog changelog = hgRepo.getChangelog(); try { if (prevRevContent == null) { - if (NULL.equals(ge.firstParent()) && NULL.equals(ge.secondParent())) { + if (ge.firstParent().isNull() && ge.secondParent().isNull()) { prevRevContent = new ByteArrayDataAccess(new byte[0]); } else { final Nodeid base = ge.firstParent(); @@ -389,18 +387,22 @@ dataAccess = rawDataAccess; } + // non-null public Nodeid node() { return Nodeid.fromBinary(header, 0); } + // non-null public Nodeid firstParent() { return Nodeid.fromBinary(header, 20); } + // non-null public Nodeid secondParent() { return Nodeid.fromBinary(header, 40); } + // non-null public Nodeid cset() { // cs seems to be changeset return Nodeid.fromBinary(header, 60); } diff -r 8f872bd7ddd2 -r 9fb50c04f03c src/org/tmatesoft/hg/repo/HgRemoteRepository.java --- a/src/org/tmatesoft/hg/repo/HgRemoteRepository.java Thu Aug 25 03:56:27 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRemoteRepository.java Thu Aug 25 03:57:39 2011 +0200 @@ -442,6 +442,7 @@ return false; } RemoteBranch o = (RemoteBranch) obj; + // in fact, p1 and p2 are not supposed to be null, ever (at least for RemoteBranch created from server output) return head.equals(o.head) && root.equals(o.root) && (p1 == null && o.p1 == null || p1.equals(o.p1)) && (p2 == null && o.p2 == null || p2.equals(o.p2)); } } diff -r 8f872bd7ddd2 -r 9fb50c04f03c src/org/tmatesoft/hg/repo/Revlog.java --- a/src/org/tmatesoft/hg/repo/Revlog.java Thu Aug 25 03:56:27 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/Revlog.java Thu Aug 25 03:57:39 2011 +0200 @@ -16,7 +16,6 @@ */ package org.tmatesoft.hg.repo; -import static org.tmatesoft.hg.core.Nodeid.NULL; import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; import static org.tmatesoft.hg.repo.HgRepository.TIP; @@ -439,7 +438,7 @@ return sequential[localRevision]; } public int localRevision(Nodeid revision) { - if (revision == null || NULL.equals(revision)) { + if (revision == null || revision.isNull()) { return BAD_REVISION; } int x = Arrays.binarySearch(sorted, revision);