* [EGIT PATCH] Silently permit invalid ObjectIds during RefUpdate
@ 2008-08-15 17:44 Shawn O. Pearce
0 siblings, 0 replies; only message in thread
From: Shawn O. Pearce @ 2008-08-15 17:44 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2008-08-15 17:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-15 17:44 [EGIT PATCH] Silently permit invalid ObjectIds during RefUpdate Shawn O. Pearce
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).