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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html| James Bottomley | [Ksummit-2008-discuss] Fixing the Kernel Janitors project |
| Greg Kroah-Hartman | [PATCH 001/196] Chinese: Add the known_regression URI to the HOWTO |
| Tarkan Erimer | Re: Dual-Licensing Linux Kernel with GPL V2 and GPL V3 |
| James Bottomley | Re: Integration of SCST in the mainstream Linux kernel |
git: | |
| Jarek Poplawski | [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| Gerrit Renker | [PATCH 15/37] dccp: Set per-connection CCIDs via socket options |
| David Miller | [GIT]: Networking |
| Antonio Almeida | HTB accuracy for high speed |
