git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [EGIT PATCH] Silently permit invalid ObjectIds during RefUpdate
Date: Fri, 15 Aug 2008 10:44:46 -0700	[thread overview]
Message-ID: <1218822286-4069-1-git-send-email-spearce@spearce.org> (raw)

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@spearce.org>
---
 .../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

                 reply	other threads:[~2008-08-15 17:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1218822286-4069-1-git-send-email-spearce@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).