]> source.dussan.org Git - jgit.git/commitdiff
Unlock DirCache in case of occurring exception 69/4869/2
authorJens Baumgart <jens.baumgart@sap.com>
Tue, 3 Apr 2012 15:25:32 +0000 (17:25 +0200)
committerJens Baumgart <jens.baumgart@sap.com>
Tue, 3 Apr 2012 15:25:32 +0000 (17:25 +0200)
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>
org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java

index 854e0b8c961fd47af0b996dced369bb9deb4c1fd..e03805b7279559d692df83508e8f6ebf7924bf34 100644 (file)
@@ -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))