Patchwork [disable-tools] merge-tools: allow marking a mergetool as completely disabled

login
register
mail settings
Submitter Augie Fackler
Date Oct. 14, 2015, 5:27 p.m.
Message ID <a9313815992aa2f0af99.1444843666@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/11051/
State Accepted
Headers show

Comments

Augie Fackler - Oct. 14, 2015, 5:27 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1444841853 14400
#      Wed Oct 14 12:57:33 2015 -0400
# Node ID a9313815992aa2f0af995762eaca6aa926358bfc
# Parent  335b06e9a9cab0bebb527718e1c80daf1560141d
merge-tools: allow marking a mergetool as completely disabled

Very often in my life I'm finding that the only configured merge tool
present on the system is vimdiff[0], and it's currently impossible (as
far as I can tell) short of specifying `ui.merge = `[1] to actually
*disable* a merge tool. This allows vimdiff-haters to put:

  [merge-tools]
  vimdiff.disable = yes

in their ~/.hgrc and never see vimdiff again. I'm stopping short of
putting this as a commented out entry in the sample new user hgrc
(seen when a user runs `hg config --edit` with no ~/.hgrc) for now,
but I might come back and do that later.

0: vimdiff is at an awkward intersection: it's usually installed by
the vim package which is often installed as a vi substitute, so it's
mere presence doesn't imply me wanting it, unlike (say) kdiff3.

1: There's a related problem I ran into today where specifying
`ui.merge = :merge` failed because :merge isn't a command, which I
think is a regression. I'll try and figure that out and at least file
a bug.
Yuya Nishihara - Oct. 16, 2015, 3:24 p.m.
On Wed, 14 Oct 2015 13:27:46 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1444841853 14400
> #      Wed Oct 14 12:57:33 2015 -0400
> # Node ID a9313815992aa2f0af995762eaca6aa926358bfc
> # Parent  335b06e9a9cab0bebb527718e1c80daf1560141d
> merge-tools: allow marking a mergetool as completely disabled
> 
> Very often in my life I'm finding that the only configured merge tool
> present on the system is vimdiff[0], and it's currently impossible (as
> far as I can tell) short of specifying `ui.merge = `[1] to actually
> *disable* a merge tool. This allows vimdiff-haters to put:
> 
>   [merge-tools]
>   vimdiff.disable = yes
> 
> in their ~/.hgrc and never see vimdiff again. I'm stopping short of
> putting this as a commented out entry in the sample new user hgrc
> (seen when a user runs `hg config --edit` with no ~/.hgrc) for now,
> but I might come back and do that later.
> 
> 0: vimdiff is at an awkward intersection: it's usually installed by
> the vim package which is often installed as a vi substitute, so it's
> mere presence doesn't imply me wanting it, unlike (say) kdiff3.
> 
> 1: There's a related problem I ran into today where specifying
> `ui.merge = :merge` failed because :merge isn't a command, which I
> think is a regression. I'll try and figure that out and at least file
> a bug.
> 
> diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
> --- a/mercurial/filemerge.py
> +++ b/mercurial/filemerge.py
> @@ -120,12 +120,15 @@ def _picktool(repo, ui, path, binary, sy
>  
>      # then merge tools
>      tools = {}
> +    disabled = set()
>      for k, v in ui.configitems("merge-tools"):
>          t = k.split('.')[0]
>          if t not in tools:
>              tools[t] = int(_toolstr(ui, t, "priority", "0"))
> +        if _toolbool(ui, t, "disabled", False):
> +            disabled.add(t)
>      names = tools.keys()
> -    tools = sorted([(-p, t) for t, p in tools.items()])
> +    tools = sorted([(-p, t) for t, p in tools.items() if t not in disabled])
>      uimerge = ui.config("ui", "merge")
>      if uimerge:
>          if uimerge not in names:
> diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
> --- a/mercurial/help/config.txt
> +++ b/mercurial/help/config.txt
> @@ -1004,7 +1004,10 @@ Example ``~/.hgrc``::
>    kdiff3.priority = 1
>  
>    # Changing the priority of preconfigured tool
> -  vimdiff.priority = 0
> +  meld.priority = 0
> +
> +  # Disable a preconfigured tool
> +  vimdiff.disabled = yes

I agree vimdiff is annoying. I think it'll be nice if vimdiff is opt-in (i.e.
disabled by default). As "disabled" tools can be selected by ui.merge, it just
means priority = -inf.
Augie Fackler - Oct. 16, 2015, 3:28 p.m.
> On Oct 16, 2015, at 11:24, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> On Wed, 14 Oct 2015 13:27:46 -0400, Augie Fackler wrote:
>> # HG changeset patch
>> # User Augie Fackler <augie@google.com>
>> # Date 1444841853 14400
>> #      Wed Oct 14 12:57:33 2015 -0400
>> # Node ID a9313815992aa2f0af995762eaca6aa926358bfc
>> # Parent  335b06e9a9cab0bebb527718e1c80daf1560141d
>> merge-tools: allow marking a mergetool as completely disabled
>> 
>> Very often in my life I'm finding that the only configured merge tool
>> present on the system is vimdiff[0], and it's currently impossible (as
>> far as I can tell) short of specifying `ui.merge = `[1] to actually
>> *disable* a merge tool. This allows vimdiff-haters to put:
>> 
>>  [merge-tools]
>>  vimdiff.disable = yes
>> 
>> in their ~/.hgrc and never see vimdiff again. I'm stopping short of
>> putting this as a commented out entry in the sample new user hgrc
>> (seen when a user runs `hg config --edit` with no ~/.hgrc) for now,
>> but I might come back and do that later.
>> 
>> 0: vimdiff is at an awkward intersection: it's usually installed by
>> the vim package which is often installed as a vi substitute, so it's
>> mere presence doesn't imply me wanting it, unlike (say) kdiff3.
>> 
>> 1: There's a related problem I ran into today where specifying
>> `ui.merge = :merge` failed because :merge isn't a command, which I
>> think is a regression. I'll try and figure that out and at least file
>> a bug.
>> 
>> diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
>> --- a/mercurial/filemerge.py
>> +++ b/mercurial/filemerge.py
>> @@ -120,12 +120,15 @@ def _picktool(repo, ui, path, binary, sy
>> 
>>     # then merge tools
>>     tools = {}
>> +    disabled = set()
>>     for k, v in ui.configitems("merge-tools"):
>>         t = k.split('.')[0]
>>         if t not in tools:
>>             tools[t] = int(_toolstr(ui, t, "priority", "0"))
>> +        if _toolbool(ui, t, "disabled", False):
>> +            disabled.add(t)
>>     names = tools.keys()
>> -    tools = sorted([(-p, t) for t, p in tools.items()])
>> +    tools = sorted([(-p, t) for t, p in tools.items() if t not in disabled])
>>     uimerge = ui.config("ui", "merge")
>>     if uimerge:
>>         if uimerge not in names:
>> diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
>> --- a/mercurial/help/config.txt
>> +++ b/mercurial/help/config.txt
>> @@ -1004,7 +1004,10 @@ Example ``~/.hgrc``::
>>   kdiff3.priority = 1
>> 
>>   # Changing the priority of preconfigured tool
>> -  vimdiff.priority = 0
>> +  meld.priority = 0
>> +
>> +  # Disable a preconfigured tool
>> +  vimdiff.disabled = yes
> 
> I agree vimdiff is annoying. I think it'll be nice if vimdiff is opt-in (i.e.
> disabled by default). As "disabled" tools can be selected by ui.merge, it just
> means priority = -inf.

Yup, but that's (intentionally) beyond the scope of this patch - I just want to be able to have an obvious "make it stop" switch users can flip on merge tools they never want to see.
Matt Mackall - Oct. 16, 2015, 5:45 p.m.
On Wed, 2015-10-14 at 13:27 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1444841853 14400
> #      Wed Oct 14 12:57:33 2015 -0400
> # Node ID a9313815992aa2f0af995762eaca6aa926358bfc
> # Parent  335b06e9a9cab0bebb527718e1c80daf1560141d
> merge-tools: allow marking a mergetool as completely disabled

Queued for default, thanks.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -120,12 +120,15 @@  def _picktool(repo, ui, path, binary, sy
 
     # then merge tools
     tools = {}
+    disabled = set()
     for k, v in ui.configitems("merge-tools"):
         t = k.split('.')[0]
         if t not in tools:
             tools[t] = int(_toolstr(ui, t, "priority", "0"))
+        if _toolbool(ui, t, "disabled", False):
+            disabled.add(t)
     names = tools.keys()
-    tools = sorted([(-p, t) for t, p in tools.items()])
+    tools = sorted([(-p, t) for t, p in tools.items() if t not in disabled])
     uimerge = ui.config("ui", "merge")
     if uimerge:
         if uimerge not in names:
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1004,7 +1004,10 @@  Example ``~/.hgrc``::
   kdiff3.priority = 1
 
   # Changing the priority of preconfigured tool
-  vimdiff.priority = 0
+  meld.priority = 0
+
+  # Disable a preconfigured tool
+  vimdiff.disabled = yes
 
   # Define new tool
   myHtmlTool.args = -m $local $other $base $output
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
@@ -193,6 +193,26 @@  or false set higher on command line:
   M f
   ? f.orig
 
+or true set to disabled:
+  $ beforemerge
+  [merge-tools]
+  false.whatever=
+  true.priority=1
+  # hg update -C 1
+  $ hg merge -r 2 --config merge-tools.true.disabled=yes
+  merging f
+  merging f failed!
+  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
+  [1]
+  $ aftermerge
+  # cat f
+  revision 1
+  space
+  # hg stat
+  M f
+  ? f.orig
+
 or true.executable not found in PATH:
 
   $ beforemerge