git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[EGIT PATCH 10/23] Add ignoreMissingUninteresting option to PackWriter

From
MZMarek Zawirski <marek.zawirski@gmail.com>
Date
Jun 27, 2008, 22:06 UTC
Message-ID
<1214604407-30572-11-git-send-email-marek.zawirski@gmail.com>
In-Reply-To
<1214604407-30572-10-git-send-email-marek.zawirski@gmail.com>

This option is useful when caller cares only about locally existing uninteresting objects.

Test cases created.
Signed-off-by: Marek Zawirski <marek.zawirski@gmail.com>
---
 .../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
Previous: Marek ZawirskiNext: Marek Zawirski
Message 11 of 26 in “Push implementation”
  1. 00/23 Push implementationMarek Zawirski, Jun 27, 2008
  2. 01/23 Fix: let FetchProcess use fetch() instead of doFetch()Marek Zawirski, Jun 27, 2008
  3. 02/23 RefUpdate: new possible result Result.IO_FAILUREMarek Zawirski, Jun 27, 2008
  4. 03/23 Refactor TrackingRefUpdate to not hold RefSpecMarek Zawirski, Jun 27, 2008
  5. 04/23 New constructor without RefSpec for TrackingRefUpdateMarek Zawirski, Jun 27, 2008
  6. 05/23 Add RemoteRefUpdate classMarek Zawirski, Jun 27, 2008
  7. 06/23 Refactor: extract superclass OperationResult from FetchResultMarek Zawirski, Jun 27, 2008
  8. 07/23 Add PushResult classMarek Zawirski, Jun 27, 2008
  9. 08/23 Support for fetchThin and pushThin options in TransportMarek Zawirski, Jun 27, 2008
  10. 09/23 Big refactor: *Connection hierarchyMarek Zawirski, Jun 27, 2008
  11. 10/23 Add ignoreMissingUninteresting option to PackWriterMarek Zawirski, Jun 27, 2008
  12. 11/23 Add BasePackPushConnection implementing git-send-pack protocolMarek Zawirski, Jun 27, 2008
  13. 12/23 Fix: let RevWalk reset correctly before isMergedInto()Marek Zawirski, Jun 27, 2008
  14. 13/23 Add PushProcess class implementing git-send-pack logicMarek Zawirski, Jun 27, 2008
  15. 14/23 Clarify Repository#resolve() documentationMarek Zawirski, Jun 27, 2008
  16. 15/23 Add String versions of methods in RefSpecMarek Zawirski, Jun 27, 2008
  17. 16/23 Transport* - general support for push() and implementationsMarek Zawirski, Jun 27, 2008
  18. 17/23 Test cases for PushProcessMarek Zawirski, Jun 27, 2008
  19. 18/23 Test cases for RefSpec to RemoteRefUpdate conversionsMarek Zawirski, Jun 27, 2008
  20. 19/23 Repository search for command line toolsMarek Zawirski, Jun 27, 2008
  21. 20/23 Push command line utilityMarek Zawirski, Jun 27, 2008
  22. 21/23 Don't accept RefSpec with null source for fetchMarek Zawirski, Jun 27, 2008
  23. 22/23 Add new handy constructors to TransportException, PackProtocolExceptionMarek Zawirski, Jun 27, 2008
  24. 23/23 Use new TransportException constructorsMarek Zawirski, Jun 27, 2008
  25. Robin RosenbergJun 28, 2008
  26. Robin RosenbergJun 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.