From 270890b687c28cc314914e7f48dfc47456b23266 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 May 2008 22:42:17 -0400 Subject: [PATCH] Make PackIndex public and expose PackIndex.hasObject Some application code, such as "dumb" commit walkers that perform fetching over non-Git aware protocols like HTTP or FTP require an efficient means to read a pack's .idx file and then test if there is an occurrence of an object stored within that pack. The test frequently gets used by application code to determine if it needs to download a pack file. Indexes are generally smaller and thus cheaper to transport over the dumb protocol, so they are the better method to determine an object existence test. Signed-off-by: Shawn O. Pearce --- org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java | 2 +- org.spearce.jgit/src/org/spearce/jgit/lib/PackIndex.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java index 05e97003..7fc46862 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java @@ -84,7 +84,7 @@ public class PackFile { * @return true if the object is in this pack; false otherwise. */ public boolean hasObject(final AnyObjectId id) { - return idx.findOffset(id) != -1; + return idx.hasObject(id); } /** diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PackIndex.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PackIndex.java index 0c9aa6bb..1d4bb575 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackIndex.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackIndex.java @@ -32,7 +32,7 @@ import org.spearce.jgit.util.NB; * by ObjectId. *

*/ -abstract class PackIndex { +public abstract class PackIndex { /** * Open an existing pack .idx file for reading. *

@@ -50,7 +50,7 @@ abstract class PackIndex { * the file exists but could not be read due to security errors, * unrecognized data version, or unexpected data corruption. */ - static PackIndex open(final File idxFile) throws IOException { + public static PackIndex open(final File idxFile) throws IOException { final FileInputStream fd = new FileInputStream(idxFile); try { final byte[] hdr = new byte[8]; @@ -85,6 +85,17 @@ abstract class PackIndex { } /** + * Determine if an object is contained within the pack file. + * + * @param id + * the object to look for. Must not be null. + * @return true if the object is listed in this index; false otherwise. + */ + public boolean hasObject(final AnyObjectId id) { + return findOffset(id) != -1; + } + + /** * Obtain the total number of objects described by this index. * * @return number of objects in this index, and likewise in the associated -- 2.11.4.GIT