From mboxrd@z Thu Jan 1 00:00:00 1970
From: "Shawn O. Pearce"
* Class provide set of configurable options and {@link ProgressMonitor} @@ -99,7 +100,7 @@ public class PackWriter { * Title of {@link ProgressMonitor} task used during counting objects to * pack. * - * @see #writePack(Collection, Collection, boolean, boolean) + * @see #preparePack(Collection, Collection, boolean, boolean) */ public static final String COUNTING_OBJECTS_PROGRESS = "Counting objects to pack"; @@ -107,8 +108,7 @@ public class PackWriter { * Title of {@link ProgressMonitor} task used during searching for objects * reuse or delta reuse. * - * @see #writePack(Iterator) - * @see #writePack(Collection, Collection, boolean, boolean) + * @see #writePack(OutputStream) */ public static final String SEARCHING_REUSE_PROGRESS = "Searching for delta and object reuse"; @@ -116,8 +116,7 @@ public class PackWriter { * Title of {@link ProgressMonitor} task used during writing out pack * (objects) * - * @see #writePack(Iterator) - * @see #writePack(Collection, Collection, boolean, boolean) + * @see #writePack(OutputStream) */ public static final String WRITING_OBJECTS_PROGRESS = "Writing objects"; @@ -168,9 +167,9 @@ public class PackWriter { private final Repository db; - private final DigestOutputStream out; + private DigestOutputStream out; - private final CountingOutputStream countingOut; + private CountingOutputStream countingOut; private final Deflater deflater; @@ -197,28 +196,22 @@ public class PackWriter { private boolean thin; /** - * Create writer for specified repository, that will write a pack to - * provided output stream. Objects for packing are specified in - * {@link #writePack(Iterator)} or - * {@link #writePack(Collection, Collection, boolean, boolean)}. + * Create writer for specified repository. + *
+ * Objects for packing are specified in {@link #preparePack(Iterator)} or + * {@link #preparePack(Collection, Collection, boolean, boolean)}. * * @param repo * repository where objects are stored. - * @param out - * output stream of pack data; no buffering is guaranteed by - * writer. * @param monitor * operations progress monitor, used within - * {@link #writePack(Iterator)} or - * {@link #writePack(Collection, Collection, boolean, boolean)}. + * {@link #preparePack(Iterator)}, + * {@link #preparePack(Collection, Collection, boolean, boolean)}, + * or {@link #writePack(OutputStream)}. */ - public PackWriter(final Repository repo, final OutputStream out, - final ProgressMonitor monitor) { + public PackWriter(final Repository repo, final ProgressMonitor monitor) { this.db = repo; this.monitor = monitor; - this.countingOut = new CountingOutputStream(out); - this.out = new DigestOutputStream(countingOut, Constants - .newMessageDigest()); this.deflater = new Deflater(db.getConfig().getCore().getCompression()); } @@ -241,9 +234,9 @@ public class PackWriter { * use it if possible. Normally, only deltas with base to another object * existing in set of objects to pack will be used. Exception is however * thin-pack (see - * {@link #writePack(Collection, Collection, boolean, boolean)} and - * {@link #writePack(Iterator)}) where base object must exist on other side - * machine. + * {@link #preparePack(Collection, Collection, boolean, boolean)} and + * {@link #preparePack(Iterator)}) where base object must exist on other + * side machine. *
* When raw delta data is directly copied from a pack file, checksum is * computed to verify data. @@ -371,8 +364,7 @@ public class PackWriter { } /** - * Write pack to output stream according to current writer configuration for - * provided source iterator of objects. + * Prepare the list of objects to be written to the pack stream. *
* Iterator exactly determines which objects are included in a pack * and order they appear in pack (except that objects order by type is not @@ -391,17 +383,6 @@ public class PackWriter { * {@link RevFlag#UNINTERESTING} flag. This type of pack is used only for * transport. *
- *- * At first, this method collects and sorts objects to pack, then deltas - * search is performed if set up accordingly, finally pack stream is - * written. {@link ProgressMonitor} tasks {@value #SEARCHING_REUSE_PROGRESS} - * (only if resueDeltas or reuseObjects is enabled) and - * {@value #WRITING_OBJECTS_PROGRESS} are updated during packing. - *
- *- * All reused objects data checksum (Adler32/CRC32) is computed and - * validated against existing checksum. - *
* * @param objectsSource * iterator of object to store in a pack; order of objects within @@ -414,20 +395,17 @@ public class PackWriter { * {@link RevFlag#UNINTERESTING} flag set, it won't be included * in a pack, but is considered as edge-object for thin-pack. * @throws IOException - * when some I/O problem occur during reading objects for pack - * or writing pack stream. + * when some I/O problem occur during reading objects. */ - public void writePack(final Iterator* Basing on these 2 sets, another set of objects to put in a pack file is * created: this set consists of all objects reachable (ancestors) from @@ -437,18 +415,6 @@ public class PackWriter { * Order is consistent with general git in-pack rules: sort by object type, * recency, path and delta-base first. *
- *- * At first, this method collects and sorts objects to pack, then deltas - * search is performed if set up accordingly, finally pack stream is - * written. {@link ProgressMonitor} tasks - * {@value #COUNTING_OBJECTS_PROGRESS}, {@value #SEARCHING_REUSE_PROGRESS} - * (only if resueDeltas or reuseObjects is enabled) and - * {@value #WRITING_OBJECTS_PROGRESS} are updated during packing. - *
- *- * All reused objects data checksum (Adler32/CRC32) is computed and - * validated against existing checksum. - *
* * @param interestingObjects * collection of objects to be marked as interesting (start @@ -468,17 +434,15 @@ public class PackWriter { * otherwise - non existing uninteresting objects may cause * {@link MissingObjectException} * @throws IOException - * when some I/O problem occur during reading objects for pack - * or writing pack stream. + * when some I/O problem occur during reading objects. */ - public void writePack(final Collection- * This method can only be invoked after {@link #writePack(Iterator)} or - * {@link #writePack(Collection, Collection, boolean, boolean)} has been + * This method can only be invoked after {@link #preparePack(Iterator)} or + * {@link #preparePack(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. * @@ -532,10 +496,38 @@ public class PackWriter { return sortedByName; } - private void writePackInternal() throws IOException { + /** + * Write the prepared pack to the supplied stream. + *
+ * At first, this method collects and sorts objects to pack, then deltas + * search is performed if set up accordingly, finally pack stream is + * written. {@link ProgressMonitor} tasks {@value #SEARCHING_REUSE_PROGRESS} + * (only if resueDeltas or reuseObjects is enabled) and + * {@value #WRITING_OBJECTS_PROGRESS} are updated during packing. + *
+ *+ * All reused objects data checksum (Adler32/CRC32) is computed and + * validated against existing checksum. + *
+ * + * @param packStream + * output stream of pack data. If the stream is not buffered it + * will be buffered by the writer. Caller is responsible for + * closing the stream. + * @throws IOException + * an error occurred reading a local object's data to include in + * the pack, or writing compressed object data to the output + * stream. + */ + public void writePack(OutputStream packStream) throws IOException { if (reuseDeltas || reuseObjects) searchForReuse(); + if (!(packStream instanceof BufferedOutputStream)) + packStream = new BufferedOutputStream(packStream); + countingOut = new CountingOutputStream(packStream); + out = new DigestOutputStream(countingOut, Constants.newMessageDigest()); + monitor.beginTask(WRITING_OBJECTS_PROGRESS, getObjectsNumber()); writeHeader(); writeObjects(); diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java index 217486a..7ae3aa7 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java @@ -161,7 +161,7 @@ class BasePackPushConnection extends BasePackConnection implements private void writePack(final Map