This option is useful when caller cares only about locally existing uninteresting objects. Test cases created. Signed-off-by: Marek Zawirski <marek.zawirski@xxxxxxxxx> --- .../tst/org/spearce/jgit/lib/PackWriterTest.java | 45 +++++++++++++++++--- .../src/org/spearce/jgit/lib/PackWriter.java | 37 +++++++++++----- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java index 9572342..f94eb72 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java @@ -120,7 +120,7 @@ public class PackWriterTest extends RepositoryTestCase { * @throws IOException */ public void testWriteEmptyPack1() throws IOException { - createVerifyOpenPack(EMPTY_LIST_OBJECT, EMPTY_LIST_OBJECT, false); + createVerifyOpenPack(EMPTY_LIST_OBJECT, EMPTY_LIST_OBJECT, false, false); assertEquals(0, writer.getObjectsNumber()); assertEquals(0, pack.getObjectCount()); @@ -142,6 +142,37 @@ public class PackWriterTest extends RepositoryTestCase { } /** + * Try to pass non-existing object as uninteresting, with non-ignoring + * setting. + * + * @throws IOException + */ + public void testNotIgnoreNonExistingObjects() throws IOException { + final ObjectId nonExisting = ObjectId + .fromString("0000000000000000000000000000000000000001"); + try { + createVerifyOpenPack(EMPTY_LIST_OBJECT, Collections.nCopies(1, + nonExisting), false, false); + fail("Should have thrown MissingObjectException"); + } catch (MissingObjectException x) { + // expected + } + } + + /** + * Try to pass non-existing object as uninteresting, with ignoring setting. + * + * @throws IOException + */ + public void testIgnoreNonExistingObjects() throws IOException { + final ObjectId nonExisting = ObjectId + .fromString("0000000000000000000000000000000000000001"); + createVerifyOpenPack(EMPTY_LIST_OBJECT, Collections.nCopies(1, + nonExisting), false, true); + // shouldn't throw anything + } + + /** * Create pack basing on only interesting objects, then precisely verify * content. No delta reuse here. * @@ -326,7 +357,7 @@ public class PackWriterTest extends RepositoryTestCase { final LinkedList<ObjectId> interestings = new LinkedList<ObjectId>(); interestings.add(ObjectId .fromString("82c6b885ff600be425b4ea96dee75dca255b69e7")); - createVerifyOpenPack(interestings, EMPTY_LIST_OBJECT, false); + createVerifyOpenPack(interestings, EMPTY_LIST_OBJECT, false, false); final ObjectId expectedOrder[] = new ObjectId[] { ObjectId.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7"), @@ -352,7 +383,7 @@ public class PackWriterTest extends RepositoryTestCase { final LinkedList<ObjectId> uninterestings = new LinkedList<ObjectId>(); uninterestings.add(ObjectId .fromString("540a36d136cf413e4b064c2b0e0a4db60f77feab")); - createVerifyOpenPack(interestings, uninterestings, false); + createVerifyOpenPack(interestings, uninterestings, false, false); final ObjectId expectedOrder[] = new ObjectId[] { ObjectId.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7"), @@ -380,7 +411,7 @@ public class PackWriterTest extends RepositoryTestCase { final LinkedList<ObjectId> uninterestings = new LinkedList<ObjectId>(); uninterestings.add(ObjectId .fromString("c59759f143fb1fe21c197981df75a7ee00290799")); - createVerifyOpenPack(interestings, uninterestings, thin); + createVerifyOpenPack(interestings, uninterestings, thin, false); final ObjectId writtenObjects[] = new ObjectId[] { ObjectId.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7"), @@ -404,9 +435,11 @@ public class PackWriterTest extends RepositoryTestCase { } private void createVerifyOpenPack(final Collection<ObjectId> interestings, - final Collection<ObjectId> uninterestings, final boolean thin) + final Collection<ObjectId> uninterestings, final boolean thin, + final boolean ignoreMissingUninteresting) throws MissingObjectException, IOException { - writer.writePack(interestings, uninterestings, thin); + writer.writePack(interestings, uninterestings, thin, + ignoreMissingUninteresting); verifyOpenPack(thin); } 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 ba43da5..a331237 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java @@ -77,7 +77,7 @@ import org.spearce.jgit.util.NB; * Typical usage consists of creating instance intended for some pack, * configuring options through accessors methods and finally call * {@link #writePack(Iterator)} or - * {@link #writePack(Collection, Collection, boolean)} with objects + * {@link #writePack(Collection, Collection, boolean, boolean)} with objects * specification, to generate a pack stream. * </p> * <p> @@ -98,7 +98,7 @@ public class PackWriter { * Title of {@link ProgressMonitor} task used during counting objects to * pack. * - * @see #writePack(Collection, Collection, boolean) + * @see #writePack(Collection, Collection, boolean, boolean) */ public static final String COUNTING_OBJECTS_PROGRESS = "Counting objects to pack"; @@ -107,7 +107,7 @@ public class PackWriter { * reuse or delta reuse. * * @see #writePack(Iterator) - * @see #writePack(Collection, Collection, boolean) + * @see #writePack(Collection, Collection, boolean, boolean) */ public static final String SEARCHING_REUSE_PROGRESS = "Searching for delta and object reuse"; @@ -116,7 +116,7 @@ public class PackWriter { * (objects) * * @see #writePack(Iterator) - * @see #writePack(Collection, Collection, boolean) + * @see #writePack(Collection, Collection, boolean, boolean) */ public static final String WRITING_OBJECTS_PROGRESS = "Writing objects"; @@ -193,7 +193,7 @@ public class PackWriter { * 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)}. + * {@link #writePack(Collection, Collection, boolean, boolean)}. * * @param repo * repository where objects are stored. @@ -203,7 +203,7 @@ public class PackWriter { * @param monitor * operations progress monitor, used within * {@link #writePack(Iterator)} or - * {@link #writePack(Collection, Collection, boolean)}. + * {@link #writePack(Collection, Collection, boolean, boolean)}. */ public PackWriter(final Repository repo, final OutputStream out, final ProgressMonitor monitor) { @@ -233,7 +233,8 @@ public class PackWriter { * writer will search for delta representation of object in repository and * 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)} and + * thin-pack (see + * {@link #writePack(Collection, Collection, boolean, boolean)} and * {@link #writePack(Iterator)}) where base object must exist on other side * machine. * <p> @@ -442,15 +443,21 @@ public class PackWriter { * belonging to party repository (uninteresting/boundary) as * determined by set; this kind of pack is used only for * transport; true - to produce thin pack, false - otherwise. + * @param ignoreMissingUninteresting + * true if writer should ignore non existing uninteresting + * objects during construction set of objects to pack; false + * 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. */ public void writePack(final Collection<ObjectId> interestingObjects, - final Collection<ObjectId> uninterestingObjects, boolean thin) + final Collection<ObjectId> uninterestingObjects, + final boolean thin, final boolean ignoreMissingUninteresting) throws IOException { ObjectWalk walker = setUpWalker(interestingObjects, - uninterestingObjects, thin); + uninterestingObjects, thin, ignoreMissingUninteresting); findObjectsToPack(walker); writePackInternal(); } @@ -682,7 +689,8 @@ public class PackWriter { private ObjectWalk setUpWalker( final Collection<ObjectId> interestingObjects, - final Collection<ObjectId> uninterestingObjects, boolean thin) + final Collection<ObjectId> uninterestingObjects, + final boolean thin, final boolean ignoreMissingUninteresting) throws MissingObjectException, IOException, IncorrectObjectTypeException { final ObjectWalk walker = new ObjectWalk(db); @@ -696,7 +704,14 @@ public class PackWriter { walker.markStart(o); } for (ObjectId id : uninterestingObjects) { - RevObject o = walker.parseAny(id); + final RevObject o; + try { + o = walker.parseAny(id); + } catch (MissingObjectException x) { + if (ignoreMissingUninteresting) + continue; + throw x; + } walker.markUninteresting(o); } return walker; -- 1.5.5.3 -- 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