[EGIT PATCH] Silently permit invalid ObjectIds during RefUpdate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If we try to parse objects which don't exist it may be because
we are trying to force deletion of a ref exactly because the
object the ref currently refers to has been pruned from the
object database already.  Rather than fail with an exception
we should still permit the removal.

This also fixes the breakage in the unit tests introduced by
Charles' 5a318367 "Refactor of RefUpdate force ...".  One of
the unit tests for RefUpdate is using a bad ObjectId as the
new value for the ref, and uses forceUpdate to hammer it into
the ref database anyway, even though it is not valid as the
object does not exist.

Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 .../src/org/spearce/jgit/lib/RefUpdate.java        |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
index 858ba46..ca77b75 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
@@ -40,6 +40,7 @@
 import java.io.File;
 import java.io.IOException;
 
+import org.spearce.jgit.errors.MissingObjectException;
 import org.spearce.jgit.lib.Ref.Storage;
 import org.spearce.jgit.revwalk.RevCommit;
 import org.spearce.jgit.revwalk.RevObject;
@@ -345,8 +346,8 @@ private Result updateImpl(final RevWalk walk, final Store store)
 			if (oldValue == null)
 				return store.store(lock, Result.NEW);
 
-			newObj = walk.parseAny(newValue);
-			oldObj = walk.parseAny(oldValue);
+			newObj = safeParse(walk, newValue);
+			oldObj = safeParse(walk, oldValue);
 			if (newObj == oldObj)
 				return Result.NO_CHANGE;
 
@@ -363,6 +364,20 @@ private Result updateImpl(final RevWalk walk, final Store store)
 		}
 	}
 
+	private static RevObject safeParse(final RevWalk rw, final AnyObjectId id)
+			throws IOException {
+		try {
+			return rw.parseAny(id);
+		} catch (MissingObjectException e) {
+			// We can expect some objects to be missing, like if we are
+			// trying to force a deletion of a branch and the object it
+			// points to has been pruned from the database due to freak
+			// corruption accidents (it happens with 'git new-work-dir').
+			//
+			return null;
+		}
+	}
+
 	private Result updateStore(final LockFile lock, final Result status)
 			throws IOException {
 		lock.setNeedStatInformation(true);
-- 
1.6.0.rc3.250.g8dd0

--
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux