changeset 26617:dfd9811c5c9b

merge: introduce a preresolve function The section of code that writes out the version of the file cached in the merge state should only be run at preresolve time. This is so that if the premerge keeps around conflict markers, those don't get overwritten before the main merge.
author Siddharth Agarwal <sid0@fb.com>
date Sun, 11 Oct 2015 20:12:12 -0700
parents 2f1fce0d4e86
children 8e6d5b7317e6
files mercurial/commands.py mercurial/merge.py
diffstat 2 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sun Oct 11 18:37:54 2015 -0700
+++ b/mercurial/commands.py	Sun Oct 11 20:12:12 2015 -0700
@@ -5589,7 +5589,10 @@
                     # resolve file
                     ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
                                  'resolve')
-                    if ms.resolve(f, wctx):
+                    complete, r = ms.preresolve(f, wctx)
+                    if not complete:
+                        r = ms.resolve(f, wctx)
+                    if r:
                         ret = 1
                 finally:
                     ui.setconfig('ui', 'forcemerge', '', 'resolve')
--- a/mercurial/merge.py	Sun Oct 11 18:37:54 2015 -0700
+++ b/mercurial/merge.py	Sun Oct 11 20:12:12 2015 -0700
@@ -287,7 +287,7 @@
             if entry[0] == 'u':
                 yield f
 
-    def _resolve(self, dfile, wctx, labels=None):
+    def _resolve(self, preresolve, dfile, wctx, labels=None):
         """rerun merge process for file path `dfile`"""
         if self[dfile] == 'r':
             return True, 0
@@ -302,17 +302,19 @@
         fla = fca.flags()
         if 'x' in flags + flo + fla and 'l' not in flags + flo + fla:
             if fca.node() == nullid:
-                self._repo.ui.warn(_('warning: cannot merge flags for %s\n') %
-                                   afile)
+                if preresolve:
+                    self._repo.ui.warn(
+                        _('warning: cannot merge flags for %s\n') % afile)
             elif flags == fla:
                 flags = flo
-        # restore local
-        f = self._repo.vfs('merge/' + hash)
-        self._repo.wwrite(dfile, f.read(), flags)
-        f.close()
-        complete, r = filemerge.premerge(self._repo, self._local, lfile, fcd,
-                                         fco, fca, labels=labels)
-        if not complete:
+        if preresolve:
+            # restore local
+            f = self._repo.vfs('merge/' + hash)
+            self._repo.wwrite(dfile, f.read(), flags)
+            f.close()
+            complete, r = filemerge.premerge(self._repo, self._local, lfile,
+                                             fcd, fco, fca, labels=labels)
+        else:
             complete, r = filemerge.filemerge(self._repo, self._local, lfile,
                                               fcd, fco, fca, labels=labels)
         if r is None:
@@ -323,9 +325,12 @@
             self.mark(dfile, 'r')
         return complete, r
 
+    def preresolve(self, dfile, wctx, labels=None):
+        return self._resolve(True, dfile, wctx, labels=labels)
+
     def resolve(self, dfile, wctx, labels=None):
         """rerun merge process for file path `dfile`"""
-        return self._resolve(dfile, wctx, labels=labels)[1]
+        return self._resolve(False, dfile, wctx, labels=labels)[1]
 
 def _checkunknownfile(repo, wctx, mctx, f, f2=None):
     if f2 is None:
@@ -855,7 +860,9 @@
                              overwrite)
             continue
         audit(f)
-        r = ms.resolve(f, wctx, labels=labels)
+        complete, r = ms.preresolve(f, wctx, labels=labels)
+        if not complete:
+            r = ms.resolve(f, wctx, labels=labels)
         if r is not None and r > 0:
             unresolved += 1
         else: