Patchwork [2,of,6] filemerge: set actual capabilities of internal merge tools

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Aug. 15, 2018, 6:35 p.m.
Message ID <ca968875ed9869cbfa46.1534358134@blacknile>
Download mbox | patch
Permalink /patch/33745/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Aug. 15, 2018, 6:35 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1534244907 -32400
#      Tue Aug 14 20:08:27 2018 +0900
# Node ID ca968875ed9869cbfa464af05c2a217219f298ed
# Parent  cffd12b0d927a859e99c8b5e3f451512c85999d1
# Available At https://bitbucket.org/foozy/mercurial-wip
#              hg pull https://bitbucket.org/foozy/mercurial-wip -r ca968875ed98
# EXP-Topic filemerge-refactor
filemerge: set actual capabilities of internal merge tools

This information is used to detect actual capabilities of internal
merge tools by subsequent patches.

For convenience, this patch assumes that merge tools typed as
"nomerge" have both binary files and symlinks capabilities.
Yuya Nishihara - Aug. 16, 2018, 10:15 a.m.
On Thu, 16 Aug 2018 03:35:34 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1534244907 -32400
> #      Tue Aug 14 20:08:27 2018 +0900
> # Node ID ca968875ed9869cbfa464af05c2a217219f298ed
> # Parent  cffd12b0d927a859e99c8b5e3f451512c85999d1
> # Available At https://bitbucket.org/foozy/mercurial-wip
> #              hg pull https://bitbucket.org/foozy/mercurial-wip -r ca968875ed98
> # EXP-Topic filemerge-refactor
> filemerge: set actual capabilities of internal merge tools

> +        # actual capabilities, which this internal merge tool has
> +        func.capabilities = {"binary": binarycap, "symlink": symlinkcap}

Alternatively, this could be a set of enabled capability names. I don't know
which is better, though.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -470,7 +470,7 @@  def _itagmerge(repo, mynode, orig, fcd, 
     success, status = tagmerge.merge(repo, fcd, fco, fca)
     return success, status, False
 
-@internaltool('dump', fullmerge)
+@internaltool('dump', fullmerge, binary=True, symlink=True)
 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
     """
     Creates three versions of the files to merge, containing the
@@ -496,7 +496,7 @@  def _idump(repo, mynode, orig, fcd, fco,
     repo.wwrite(fd + ".base", fca.data(), fca.flags())
     return False, 1, False
 
-@internaltool('forcedump', mergeonly)
+@internaltool('forcedump', mergeonly, binary=True, symlink=True)
 def _forcedump(repo, mynode, orig, fcd, fco, fca, toolconf, files,
                 labels=None):
     """
diff --git a/mercurial/registrar.py b/mercurial/registrar.py
--- a/mercurial/registrar.py
+++ b/mercurial/registrar.py
@@ -399,7 +399,8 @@  class internalmerge(_funcregistrarbase):
         internalmerge = registrar.internalmerge()
 
         @internalmerge('mymerge', internalmerge.mergeonly,
-                       onfailure=None, precheck=None):
+                       onfailure=None, precheck=None,
+                       binary=False, symlink=False):
         def mymergefunc(repo, mynode, orig, fcd, fco, fca,
                         toolconf, files, labels=None):
             '''Explanation of this internal merge tool ....
@@ -430,6 +431,12 @@  class internalmerge(_funcregistrarbase):
     'files' and 'labels'. If it returns false value, merging is aborted
     immediately (and file is marked as "unresolved").
 
+    Optional argument 'binary' is a binary files capability of internal
+    merge tool. 'nomerge' merge type implies binary=True.
+
+    Optional argument 'symlink' is a symlinks capability of inetrnal
+    merge function. 'nomerge' merge type implies symlink=True.
+
     'internalmerge' instance in example above can be used to
     decorate multiple functions.
 
@@ -447,7 +454,14 @@  class internalmerge(_funcregistrarbase):
     fullmerge = 'fullmerge'  # both premerge and merge
 
     def _extrasetup(self, name, func, mergetype,
-                    onfailure=None, precheck=None):
+                    onfailure=None, precheck=None,
+                    binary=False, symlink=False):
         func.mergetype = mergetype
         func.onfailure = onfailure
         func.precheck = precheck
+
+        binarycap = binary or mergetype == self.nomerge
+        symlinkcap = symlink or mergetype == self.nomerge
+
+        # actual capabilities, which this internal merge tool has
+        func.capabilities = {"binary": binarycap, "symlink": symlinkcap}