If we are packing for local use, or are sending the pack file to a dumb server we must also genrate the matching .idx file so Git can use random access requests to read object data. Since all of the necessary information is available in our ObjectToPack we can just pass off the sorted list to PackIndexWriter. Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- .../src/org/spearce/jgit/lib/PackWriter.java | 38 ++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java index 6adb629..e346668 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java @@ -192,6 +192,8 @@ public class PackWriter { private int maxDeltaDepth = DEFAULT_MAX_DELTA_DEPTH; + private int outputVersion; + private boolean thin; /** @@ -348,6 +350,18 @@ public class PackWriter { } /** + * Set the pack index file format version this instance will create. + * + * @param version + * the version to write. The special version 0 designates the + * oldest (most compatible) format available for the objects. + * @see PackIndexWriter + */ + public void setIndexVersion(final int version) { + outputVersion = version; + } + + /** * Returns objects number in a pack file that was created by this writer. * * @return number of objects in pack. @@ -482,6 +496,30 @@ public class PackWriter { return ObjectId.fromRaw(md.digest()); } + /** + * Create an index file to match the pack file just written. + * <p> + * This method can only be invoked after {@link #writePack(Iterator)} or + * {@link #writePack(Collection, Collection, boolean, boolean)} has been + * invoked and completed successfully. Writing a corresponding index is an + * optional feature that not all pack users may require. + * + * @param indexStream + * output for the index data. Caller is responsible for closing + * this stream. + * @throws IOException + * the index data could not be written to the supplied stream. + */ + public void writeIndex(final OutputStream indexStream) throws IOException { + final List<ObjectToPack> list = sortByName(); + final PackIndexWriter iw; + if (outputVersion <= 0) + iw = PackIndexWriter.createOldestPossible(indexStream, list); + else + iw = PackIndexWriter.createVersion(indexStream, outputVersion); + iw.write(list, packcsum); + } + private List<ObjectToPack> sortByName() { if (sortedByName == null) { sortedByName = new ArrayList<ObjectToPack>(objectsMap.size()); -- 1.5.6.74.g8a5e -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html