Patchwork [5,of,6,mergedriver] merge: introduce a preresolve function

login
register
mail settings
Submitter Siddharth Agarwal
Date Oct. 12, 2015, 8:09 p.m.
Message ID <d16d6cbc3155462397dd.1444680581@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/10974/
State Accepted
Headers show

Comments

Siddharth Agarwal - Oct. 12, 2015, 8:09 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1444619532 25200
#      Sun Oct 11 20:12:12 2015 -0700
# Node ID d16d6cbc3155462397dd78398f488307a4bc1545
# Parent  f7af6a6a06e73338b8a2536035a40e8303a5175f
merge: introduce a preresolve function

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5589,7 +5589,10 @@  def resolve(ui, repo, *pats, **opts):
                     # 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')
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -287,7 +287,7 @@  class mergestate(object):
             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 @@  class mergestate(object):
         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,6 +325,9 @@  class mergestate(object):
             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(False, dfile, wctx, labels=labels)[1]
@@ -855,7 +860,9 @@  def applyupdates(repo, actions, wctx, mc
                              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: