Patchwork [4,of,6] filemerge: show warning if chosen tool has no binary files capability

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Aug. 15, 2018, 6:35 p.m.
Message ID <48c9d0cb2afe7692324e.1534358136@blacknile>
Download mbox | patch
Permalink /patch/33746/
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 1534339478 -32400
#      Wed Aug 15 22:24:38 2018 +0900
# Node ID 48c9d0cb2afe7692324e1fa7872bc577db6496af
# Parent  1d16378efeb91e435d520b081a7a34b78d7fa7e2
# Available At https://bitbucket.org/foozy/mercurial-wip
#              hg pull https://bitbucket.org/foozy/mercurial-wip -r 48c9d0cb2afe
# EXP-Topic filemerge-refactor
filemerge: show warning if chosen tool has no binary files capability

While matching patterns in "merge-patterns" configuration, Mercurial
silently assumes that all merge tools have binary files
capability. This implementation comes from 5af5f0f9d724 (or Mercurial
1.0).

At failure of merging binary files with incorrect internal merge tool,
there is no hint about this silent ignorance of binary files
capability.

This patch shows warning message, if chosen internal merge tool has no
binary files capability. This will help users to investigate why a
binary file isn't merged as expected.
Yuya Nishihara - Aug. 16, 2018, 9:49 a.m.
On Thu, 16 Aug 2018 03:35:36 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1534339478 -32400
> #      Wed Aug 15 22:24:38 2018 +0900
> # Node ID 48c9d0cb2afe7692324e1fa7872bc577db6496af
> # Parent  1d16378efeb91e435d520b081a7a34b78d7fa7e2
> # Available At https://bitbucket.org/foozy/mercurial-wip
> #              hg pull https://bitbucket.org/foozy/mercurial-wip -r 48c9d0cb2afe
> # EXP-Topic filemerge-refactor
> filemerge: show warning if chosen tool has no binary files capability

> --- a/mercurial/filemerge.py
> +++ b/mercurial/filemerge.py
> @@ -195,6 +195,12 @@ def _picktool(repo, ui, path, binary, sy
>      for pat, tool in ui.configitems("merge-patterns"):
>          mf = match.match(repo.root, '', [pat])
>          if mf(path) and check(tool, pat, symlink, False, changedelete):
> +            if binary and not hascapability(tool, "binary", strict=True):
> +                ui.warn(_("warning: check merge-patterns configurations,"
> +                          " if %r for binary file %r is unintentional\n"
> +                          "(see 'hg help merge-tools'"
> +                          " for binary files capability)\n")
> +                        % (tool, path))

Inserted pycompat.bytestr(...) to drop b'' on Python 3.

> +  $ hg update -q -C 0
> +  $ python <<EOF
> +  > with open('b', 'wb') as fp:
> +  >     fp.write(b'\x00\x01\x02\x03')
> +  > EOF

Nit: this can be inline python.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -195,6 +195,12 @@  def _picktool(repo, ui, path, binary, sy
     for pat, tool in ui.configitems("merge-patterns"):
         mf = match.match(repo.root, '', [pat])
         if mf(path) and check(tool, pat, symlink, False, changedelete):
+            if binary and not hascapability(tool, "binary", strict=True):
+                ui.warn(_("warning: check merge-patterns configurations,"
+                          " if %r for binary file %r is unintentional\n"
+                          "(see 'hg help merge-tools'"
+                          " for binary files capability)\n")
+                        % (tool, path))
             toolpath = _findtool(ui, tool)
             return (tool, _quotetoolpath(toolpath))
 
diff --git a/tests/test-merge-tools.t b/tests/test-merge-tools.t
--- a/tests/test-merge-tools.t
+++ b/tests/test-merge-tools.t
@@ -1805,6 +1805,41 @@  Verify naming of temporary files and tha
   0 files updated, 1 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
 
+Binary files capability checking
+
+  $ hg update -q -C 0
+  $ python <<EOF
+  > with open('b', 'wb') as fp:
+  >     fp.write(b'\x00\x01\x02\x03')
+  > EOF
+  $ hg add b
+  $ hg commit -qm "add binary file (#1)"
+
+  $ hg update -q -C 0
+  $ python <<EOF
+  > with open('b', 'wb') as fp:
+  >     fp.write(b'\x03\x02\x01\x00')
+  > EOF
+  $ hg add b
+  $ hg commit -qm "add binary file (#2)"
+
+By default, binary files capability of internal merge tools is not
+checked strictly.
+
+(for merge-patterns, chosen unintentionally)
+
+  $ hg merge 9 \
+  > --config merge-patterns.b=:merge-other \
+  > --config merge-patterns.re:[a-z]=:other
+  warning: check merge-patterns configurations, if ':merge-other' for binary file 'b' is unintentional
+  (see 'hg help merge-tools' for binary files capability)
+  merging b
+  warning: b looks like a binary file.
+  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
+  [1]
+  $ hg merge --abort -q
+
 Check that debugpicktool examines which merge tool is chosen for
 specified file as expected
 
@@ -1836,9 +1871,9 @@  specified file as expected
 
 (-r REV causes checking files in specified revision)
 
-  $ hg manifest -r tip
+  $ hg manifest -r 8
   f.txt
-  $ hg debugpickmergetool -r tip
+  $ hg debugpickmergetool -r 8
   f.txt = true
 
 #if symlink