Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Baumgart2012-04-03 15:25:32 +0000
committerJens Baumgart2012-04-03 15:25:32 +0000
commit0a84ad2d2ac8153d06564895279ab4fd11ef0e80 (patch)
tree743ddf4a08b5fd366fbcc86b20b471106a7892d6
parent86db05602fc8f42fd171df177fb9f4394a1b8ae5 (diff)
downloadjgit-0a84ad2d2ac8153d06564895279ab4fd11ef0e80.tar.gz
jgit-0a84ad2d2ac8153d06564895279ab4fd11ef0e80.tar.xz
jgit-0a84ad2d2ac8153d06564895279ab4fd11ef0e80.zip
Unlock DirCache in case of occurring exception
A DirCache was not unlocked if an exception occurred in the DirCacheCheckout constructor. Bug: 365449 Change-Id: I231d902d52e3e5e9a7748eedaa63a2bb889ebb13 Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java22
1 files changed, 14 insertions, 8 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
index 854e0b8c96..e03805b727 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
@@ -160,15 +160,21 @@ public class CheckoutCommand extends GitCommand<Ref> {
.parseCommit(headId);
RevCommit newCommit = revWalk.parseCommit(branch);
RevTree headTree = headCommit == null ? null : headCommit.getTree();
- DirCacheCheckout dco = new DirCacheCheckout(repo, headTree,
- repo.lockDirCache(), newCommit.getTree());
- dco.setFailOnConflict(true);
+ DirCacheCheckout dco;
+ DirCache dc = repo.lockDirCache();
try {
- dco.checkout();
- } catch (org.eclipse.jgit.errors.CheckoutConflictException e) {
- status = new CheckoutResult(Status.CONFLICTS, dco
- .getConflicts());
- throw new CheckoutConflictException(dco.getConflicts(), e);
+ dco = new DirCacheCheckout(repo, headTree, dc,
+ newCommit.getTree());
+ dco.setFailOnConflict(true);
+ try {
+ dco.checkout();
+ } catch (org.eclipse.jgit.errors.CheckoutConflictException e) {
+ status = new CheckoutResult(Status.CONFLICTS,
+ dco.getConflicts());
+ throw new CheckoutConflictException(dco.getConflicts(), e);
+ }
+ } finally {
+ dc.unlock();
}
Ref ref = repo.getRef(name);
if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))

Back to the top