D931: merge: ensure that we always commit the mergestate

ryanmce (Ryan McElroy) phabricator at mercurial-scm.org
Wed Oct 4 13:55:30 UTC 2017


ryanmce created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  In future patches, we may halt the merge process based on configuration or
  user requests by raising exceptions. We need to ensure that the mergestate
  is unconditionally committed even when such an exception is raised.
  
  Depends on https://phab.mercurial-scm.org/D930.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D931

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1325,30 +1325,32 @@
                 newactions.append((f, args, msg))
         mergeactions = newactions
 
-    # premerge
-    tocomplete = []
-    for f, args, msg in mergeactions:
-        repo.ui.debug(" %s: %s -> m (premerge)\n" % (f, msg))
-        z += 1
-        progress(_updating, z, item=f, total=numupdates, unit=_files)
-        if f == '.hgsubstate': # subrepo states need updating
-            subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
-                             overwrite, labels)
-            continue
-        wctx[f].audit()
-        complete, r = ms.preresolve(f, wctx)
-        if not complete:
-            numupdates += 1
-            tocomplete.append((f, args, msg))
+    try:
+        # premerge
+        tocomplete = []
+        for f, args, msg in mergeactions:
+            repo.ui.debug(" %s: %s -> m (premerge)\n" % (f, msg))
+            z += 1
+            progress(_updating, z, item=f, total=numupdates, unit=_files)
+            if f == '.hgsubstate': # subrepo states need updating
+                subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
+                                 overwrite, labels)
+                continue
+            wctx[f].audit()
+            complete, r = ms.preresolve(f, wctx)
+            if not complete:
+                numupdates += 1
+                tocomplete.append((f, args, msg))
 
-    # merge
-    for f, args, msg in tocomplete:
-        repo.ui.debug(" %s: %s -> m (merge)\n" % (f, msg))
-        z += 1
-        progress(_updating, z, item=f, total=numupdates, unit=_files)
-        ms.resolve(f, wctx)
+        # merge
+        for f, args, msg in tocomplete:
+            repo.ui.debug(" %s: %s -> m (merge)\n" % (f, msg))
+            z += 1
+            progress(_updating, z, item=f, total=numupdates, unit=_files)
+            ms.resolve(f, wctx)
 
-    ms.commit()
+    finally:
+        ms.commit()
 
     unresolved = ms.unresolvedcount()
 



To: ryanmce, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list