VisibilityChecker: Use RefDatabase.getTipsWithSha1() for visibility check The visibility check retrieves all refs, peels them and compares if they point to the requested object. This is offered now in in the RefDatabase.getTipsWithSha1() method. Using that method, we also benefit from fine-tuned implementations for the specific storage in use. Replace the loop with that method. Change-Id: I2623a3fc99cffcd791aa0c6450aba08d00408ca4 Signed-off-by: Ivan Frade <[email protected]>
diff --git a/java/com/google/gitiles/VisibilityChecker.java b/java/com/google/gitiles/VisibilityChecker.java index 22d08bc..ccd5cf1 100644 --- a/java/com/google/gitiles/VisibilityChecker.java +++ b/java/com/google/gitiles/VisibilityChecker.java
@@ -47,7 +47,6 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevSort; @@ -81,14 +80,7 @@ protected boolean isTipOfBranch(RefDatabase refDb, ObjectId id) throws IOException { // If any reference directly points at the requested object, permit display. Common for displays // of pending patch sets in Gerrit Code Review, or bookmarks to the commit a tag points at. - for (Ref ref : refDb.getRefs()) { - ref = refDb.peel(ref); - if (id.equals(ref.getObjectId()) || id.equals(ref.getPeeledObjectId())) { - return true; - } - } - - return false; + return !refDb.getTipsWithSha1(id).isEmpty(); } /**