From: Marek Zawirski Date: Sun, 15 Jun 2008 21:45:32 GMT Subject: [EGIT PATCH 03/20] Add openObjectInAllPacks() to Repository, exposing packed objects storage Message-ID: <1213566349-25395-4-git-send-email-marek.zawirski@gmail.com> In-Reply-To: <1213566349-25395-3-git-send-email-marek.zawirski@gmail.com> Gives client a way to access specified object from any pack where it is stored (this may be useful when an object is stored in more than 1 pack). Signed-off-by: Marek Zawirski --- .../src/org/spearce/jgit/lib/Repository.java | 42 ++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java index 3efe60b..64f93ff 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java @@ -48,6 +48,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.LinkedList; import java.util.Map; import org.spearce.jgit.errors.IncorrectObjectTypeException; @@ -292,6 +293,47 @@ public class Repository { } /** + * Open object in all packs containing specified object. + * + * @param objectId + * id of object to search for + * @param curs + * temporary working space associated with the calling thread. + * @return collection of loaders for this object, from all packs containing + * this object + * @throws IOException + */ + public Collection openObjectInAllPacks( + final AnyObjectId objectId, final WindowCursor curs) + throws IOException { + Collection result = new LinkedList(); + openObjectInAllPacks(objectId, result, curs); + return result; + } + + /** + * Open object in all packs containing specified object. + * + * @param objectId + * id of object to search for + * @param resultLoaders + * result collection of loaders for this object, filled with + * loaders from all packs containing specified object + * @param curs + * temporary working space associated with the calling thread. + * @throws IOException + */ + void openObjectInAllPacks(final AnyObjectId objectId, + final Collection resultLoaders, + final WindowCursor curs) throws IOException { + for (PackFile pack : packs) { + final PackedObjectLoader loader = pack.get(curs, objectId); + if (loader != null) + resultLoaders.add(loader); + } + } + + /** * @param id * SHA'1 of a blob * @return an {@link ObjectLoader} for accessing the data of a named blob -- 1.5.5.1