Patchwork [2,of,6,mergedriver] filemerge: switch trymerge boolean to mergetype enum

login
register
mail settings
Submitter Siddharth Agarwal
Date Oct. 8, 2015, 7:33 a.m.
Message ID <6b702d711892b207ee84.1444289593@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/10870/
State Accepted
Headers show

Comments

Siddharth Agarwal - Oct. 8, 2015, 7:33 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1444259697 25200
#      Wed Oct 07 16:14:57 2015 -0700
# Node ID 6b702d711892b207ee8478d3b382781782ef71d2
# Parent  95d03fa9c7b235dc81a5d09339c3dd92424f8ada
filemerge: switch trymerge boolean to mergetype enum

trymerge = False becomes mergetype = nomerge, and trymerge = True becomes
mergetype = fullmerge or mergeonly, depending on whether a premerge happens.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -43,7 +43,7 @@  nomerge = None
 mergeonly = 'mergeonly'  # just the full merge, no premerge
 fullmerge = 'fullmerge'  # both premerge and merge
 
-def internaltool(name, trymerge, onfailure=None, precheck=None):
+def internaltool(name, mergetype, onfailure=None, precheck=None):
     '''return a decorator for populating internal merge tool table'''
     def decorator(func):
         fullname = ':' + name
@@ -51,7 +51,7 @@  def internaltool(name, trymerge, onfailu
         internals[fullname] = func
         internals['internal:' + name] = func
         internalsdoc[fullname] = func
-        func.trymerge = trymerge
+        func.mergetype = mergetype
         func.onfailure = onfailure
         func.precheck = precheck
         return func
@@ -165,7 +165,7 @@  def _matcheol(file, origfile):
             if newdata != data:
                 util.writefile(file, newdata)
 
-@internaltool('prompt', False)
+@internaltool('prompt', nomerge)
 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf):
     """Asks the user which of the local or the other version to keep as
     the merged version."""
@@ -179,18 +179,18 @@  def _iprompt(repo, mynode, orig, fcd, fc
     else:
         return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf)
 
-@internaltool('local', False)
+@internaltool('local', nomerge)
 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf):
     """Uses the local version of files as the merged version."""
     return 0
 
-@internaltool('other', False)
+@internaltool('other', nomerge)
 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf):
     """Uses the other version of files as the merged version."""
     repo.wwrite(fcd.path(), fco.data(), fco.flags())
     return 0
 
-@internaltool('fail', False)
+@internaltool('fail', nomerge)
 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf):
     """
     Rather than attempting to merge files that were modified on both
@@ -257,7 +257,7 @@  def _merge(repo, mynode, orig, fcd, fco,
         return True, r
     return False, 0
 
-@internaltool('union', True,
+@internaltool('union', fullmerge,
               _("merging %s incomplete! "
                 "(edit conflicts, then use 'hg resolve --mark')\n"),
               precheck=_symlinkcheck)
@@ -269,7 +269,7 @@  def _iunion(repo, mynode, orig, fcd, fco
     return _merge(repo, mynode, orig, fcd, fco, fca, toolconf,
                   files, labels, 'union')
 
-@internaltool('merge', True,
+@internaltool('merge', fullmerge,
               _("merging %s incomplete! "
                 "(edit conflicts, then use 'hg resolve --mark')\n"),
               precheck=_symlinkcheck)
@@ -282,7 +282,7 @@  def _imerge(repo, mynode, orig, fcd, fco
     return _merge(repo, mynode, orig, fcd, fco, fca, toolconf,
                   files, labels, 'merge')
 
-@internaltool('merge3', True,
+@internaltool('merge3', fullmerge,
               _("merging %s incomplete! "
                 "(edit conflicts, then use 'hg resolve --mark')\n"),
               precheck=_symlinkcheck)
@@ -314,7 +314,7 @@  def _imergeauto(repo, mynode, orig, fcd,
                                 localorother=localorother)
     return True, r
 
-@internaltool('merge-local', True)
+@internaltool('merge-local', mergeonly)
 def _imergelocal(*args, **kwargs):
     """
     Like :merge, but resolve all conflicts non-interactively in favor
@@ -322,7 +322,7 @@  def _imergelocal(*args, **kwargs):
     success, status = _imergeauto(localorother='local', *args, **kwargs)
     return success, status
 
-@internaltool('merge-other', True)
+@internaltool('merge-other', mergeonly)
 def _imergeother(*args, **kwargs):
     """
     Like :merge, but resolve all conflicts non-interactively in favor
@@ -330,7 +330,7 @@  def _imergeother(*args, **kwargs):
     success, status = _imergeauto(localorother='other', *args, **kwargs)
     return success, status
 
-@internaltool('tagmerge', True,
+@internaltool('tagmerge', mergeonly,
               _("automatic tag merging of %s failed! "
                 "(use 'hg resolve --tool :merge' or another merge "
                 "tool of your choice)\n"))
@@ -340,7 +340,7 @@  def _itagmerge(repo, mynode, orig, fcd, 
     """
     return tagmerge.merge(repo, fcd, fco, fca)
 
-@internaltool('dump', True)
+@internaltool('dump', fullmerge)
 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
     """
     Creates three versions of the files to merge, containing the
@@ -479,18 +479,18 @@  def filemerge(repo, mynode, orig, fcd, f
 
         if tool in internals:
             func = internals[tool]
-            trymerge = func.trymerge
+            mergetype = func.mergetype
             onfailure = func.onfailure
             precheck = func.precheck
         else:
             func = _xmerge
-            trymerge = True
+            mergetype = fullmerge
             onfailure = _("merging %s failed!\n")
             precheck = None
 
         toolconf = tool, toolpath, binary, symlink
 
-        if not trymerge:
+        if mergetype == nomerge:
             return func(repo, mynode, orig, fcd, fco, fca, toolconf)
 
         a = repo.wjoin(fd)