hgext/rebase.py
branchstable
changeset 33120 b63351f6a246
parent 32084 091d6b9157da
child 33121 a5abaa81fad6
--- a/hgext/rebase.py	Fri Jun 23 13:33:41 2017 +0800
+++ b/hgext/rebase.py	Tue Jun 27 17:39:55 2017 +0200
@@ -475,24 +475,12 @@
                 editopt = True
             editor = cmdutil.getcommiteditor(edit=editopt, editform=editform)
             revtoreuse = max(self.state)
-            dsguard = dirstateguard.dirstateguard(repo, 'rebase')
-            try:
-                newnode = concludenode(repo, revtoreuse, p1, self.external,
-                                       commitmsg=commitmsg,
-                                       extrafn=_makeextrafn(self.extrafns),
-                                       editor=editor,
-                                       keepbranches=self.keepbranchesf,
-                                       date=self.date)
-                dsguard.close()
-                release(dsguard)
-            except error.InterventionRequired:
-                dsguard.close()
-                release(dsguard)
-                raise
-            except Exception:
-                release(dsguard)
-                raise
-
+            newnode = concludenode(repo, revtoreuse, p1, self.external,
+                                   commitmsg=commitmsg,
+                                   extrafn=_makeextrafn(self.extrafns),
+                                   editor=editor,
+                                   keepbranches=self.keepbranchesf,
+                                   date=self.date)
             if newnode is None:
                 newrev = self.target
             else:
@@ -734,19 +722,11 @@
                 return retcode
 
         with repo.transaction('rebase') as tr:
-            dsguard = dirstateguard.dirstateguard(repo, 'rebase')
             try:
                 rbsrt._performrebase(tr)
-                dsguard.close()
-                release(dsguard)
             except error.InterventionRequired:
-                dsguard.close()
-                release(dsguard)
                 tr.close()
                 raise
-            except Exception:
-                release(dsguard)
-                raise
         rbsrt._finishrebase()
     finally:
         release(lock, wlock)
@@ -874,28 +854,33 @@
     '''Commit the wd changes with parents p1 and p2. Reuse commit info from rev
     but also store useful information in extra.
     Return node of committed revision.'''
-    repo.setparents(repo[p1].node(), repo[p2].node())
-    ctx = repo[rev]
-    if commitmsg is None:
-        commitmsg = ctx.description()
-    keepbranch = keepbranches and repo[p1].branch() != ctx.branch()
-    extra = {'rebase_source': ctx.hex()}
-    if extrafn:
-        extrafn(ctx, extra)
+    dsguard = dirstateguard.dirstateguard(repo, 'rebase')
+    try:
+        repo.setparents(repo[p1].node(), repo[p2].node())
+        ctx = repo[rev]
+        if commitmsg is None:
+            commitmsg = ctx.description()
+        keepbranch = keepbranches and repo[p1].branch() != ctx.branch()
+        extra = {'rebase_source': ctx.hex()}
+        if extrafn:
+            extrafn(ctx, extra)
 
-    targetphase = max(ctx.phase(), phases.draft)
-    overrides = {('phases', 'new-commit'): targetphase}
-    with repo.ui.configoverride(overrides, 'rebase'):
-        if keepbranch:
-            repo.ui.setconfig('ui', 'allowemptycommit', True)
-        # Commit might fail if unresolved files exist
-        if date is None:
-            date = ctx.date()
-        newnode = repo.commit(text=commitmsg, user=ctx.user(),
-                              date=date, extra=extra, editor=editor)
+        targetphase = max(ctx.phase(), phases.draft)
+        overrides = {('phases', 'new-commit'): targetphase}
+        with repo.ui.configoverride(overrides, 'rebase'):
+            if keepbranch:
+                repo.ui.setconfig('ui', 'allowemptycommit', True)
+            # Commit might fail if unresolved files exist
+            if date is None:
+                date = ctx.date()
+            newnode = repo.commit(text=commitmsg, user=ctx.user(),
+                                  date=date, extra=extra, editor=editor)
 
-    repo.dirstate.setbranch(repo[newnode].branch())
-    return newnode
+        repo.dirstate.setbranch(repo[newnode].branch())
+        dsguard.close()
+        return newnode
+    finally:
+        release(dsguard)
 
 def rebasenode(repo, rev, p1, base, state, collapse, target):
     'Rebase a single revision rev on top of p1 using base as merge ancestor'