diff mbox series

[v4] mergetools: vimdiff: use correct tool's name when reading mergetool config

Message ID 20240217162718.21272-1-kipras@kipras.org (mailing list archive)
State Accepted
Commit b21d164275b9186421ebe39498be47ea9f171694
Headers show
Series [v4] mergetools: vimdiff: use correct tool's name when reading mergetool config | expand

Commit Message

Kipras Melnikovas Feb. 17, 2024, 4:27 p.m. UTC
The /mergetools/vimdiff script, which handles both vimdiff, nvimdiff
and gvimdiff mergetools (the latter 2 simply source the vimdiff script), has a
function merge_cmd() which read the layout variable from git config, and it
would always read the value of mergetool.**vimdiff**.layout, instead of the
mergetool being currently used (vimdiff or nvimdiff or gvimdiff).

It looks like in 7b5cf8be18 (vimdiff: add tool documentation, 2022-03-30),
we explained the current behavior in Documentation/config/mergetool.txt:

```
mergetool.vimdiff.layout::
	The vimdiff backend uses this variable to control how its split
	windows look like. Applies even if you are using Neovim (`nvim`) or
	gVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section
```

which makes sense why it's explained this way - the vimdiff backend is used by
gvim and nvim. But the mergetool's configuration should be separate for each tool,
and indeed that's confirmed in same commit at Documentation/mergetools/vimdiff.txt:

```
Variants

Instead of `--tool=vimdiff`, you can also use one of these other variants:
  * `--tool=gvimdiff`, to open gVim instead of Vim.
  * `--tool=nvimdiff`, to open Neovim instead of Vim.

When using these variants, in order to specify a custom layout you will have to
set configuration variables `mergetool.gvimdiff.layout` and
`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`
```

So it looks like we just forgot to update the 1 part of the vimdiff script
that read the config variable. Cheers.

Though, for backward compatibility, I've kept the mergetool.vimdiff
fallback, so that people who unknowingly relied on it, won't have their
setup broken now.

Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
---

Okay I've finalised the documentation, should be the last patch.
Also I realise I've forgotten to cc the mailing list on my replies to
Junio and Fernando - sorry! First time..

Range-diff against v3:
1:  0018c7e18c = 1:  0018c7e18c mergetools: vimdiff: use correct tool's name when reading mergetool config

 Documentation/config/mergetool.txt   | 21 ++++++++++++++-------
 Documentation/mergetools/vimdiff.txt |  3 ++-
 mergetools/vimdiff                   | 12 ++++++++++--
 3 files changed, 26 insertions(+), 10 deletions(-)


base-commit: 3e0d3cd5c7def4808247caf168e17f2bbf47892b

Comments

Junio C Hamano Feb. 20, 2024, 2:52 a.m. UTC | #1
Kipras Melnikovas <kipras@kipras.org> writes:

> Okay I've finalised the documentation, should be the last patch.
> Also I realise I've forgotten to cc the mailing list on my replies to
> Junio and Fernando - sorry! First time..
>
> Range-diff against v3:
> 1:  0018c7e18c = 1:  0018c7e18c mergetools: vimdiff: use correct tool's name when reading mergetool config
>
>  Documentation/config/mergetool.txt   | 21 ++++++++++++++-------
>  Documentation/mergetools/vimdiff.txt |  3 ++-
>  mergetools/vimdiff                   | 12 ++++++++++--
>  3 files changed, 26 insertions(+), 10 deletions(-)

That's curious.  This is v4 and no changes from v3?
Kipras Melnikovas Feb. 21, 2024, 5:20 a.m. UTC | #2
On 24/02/19 06:52PM, Junio C Hamano wrote:

> That's curious.  This is v4 and no changes from v3?

My bad. The patches are slightly different [1], I just managed to screw up the
range-diff args [2]. Won't happen again [3].

Sorry, I know this is wasting your time; this whole submission should've
been a single reroll not 3. I'll be more thorough next time.

Thank you for your time, help and quick responses.

Kipras

---

[3] https://github.com/kiprasmel/git-reroll/commit/3aa14a2860b19f86bb51f70ce0d5cec99a5aca59#diff-59ce06aeaf7a77de81c8f24c0301d95d017a83fdaec8bc1dce9877af708d1ad3R213-R227

[2]
What essentially happened was: I marked a new checkpoint "v4" *before*
sending the email, and ran format-patch with --range-diff "<checkpoint>..@",
which of course was "v4 against v4" instead of "v3 against v4"..

[1] fwiw,
Range-diff against v3:
1:  60be87c3d5 ! 1:  0018c7e18c mergetools: vimdiff: use correct tool's name when reading mergetool config
    @@ Documentation/config/mergetool.txt: mergetool.meld.useAutoMerge::
     -	windows appear. Applies even if you are using Neovim (`nvim`) or
     -	gVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section
     +mergetool.<vimdiff variant>.layout::
    -+	Git's vimdiff backend uses this variable to control how the split windows of
    -+	`<vimdiff variant>` appear. Here `<vimdiff variant>` is any of `vimdiff`,
    -+	`nvimdiff`, `gvimdiff`. To configure the layout and use the tool, see the
    -+	`BACKEND SPECIFIC HINTS`
    ++	Configure the split window layout for vimdiff's `<variant>`, which is any of `vimdiff`,
    ++	`nvimdiff`, `gvimdiff`.
    ++	Upon launching `git mergetool` with `--tool=<variant>` (or without `--tool`
    ++	if `merge.tool` is configured as `<variant>`), Git will consult
    ++	`mergetool.<variant>.layout` to determine the tool's layout. If the
    ++	variant-specific configuration is not available, `vimdiff`'s is used as
    ++	fallback.  If that too is not available, a default layout with 4 windows
    ++	will be used.  To configure the layout, see the `BACKEND SPECIFIC HINTS`
     +ifdef::git-mergetool[]
     +	section.
     +endif::[]
    @@ Documentation/config/mergetool.txt: mergetool.meld.useAutoMerge::
      mergetool.hideResolved::
      	During a merge, Git will automatically resolve as many conflicts as
     
    + ## Documentation/mergetools/vimdiff.txt ##
    +@@ Documentation/mergetools/vimdiff.txt: Instead of `--tool=vimdiff`, you can also use one of these other variants:
    + 
    + When using these variants, in order to specify a custom layout you will have to
    + set configuration variables `mergetool.gvimdiff.layout` and
    +-`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`
    ++`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout` (though the
    ++latter will be used as fallback if the variant-specific one is not set).
    + 
    + In addition, for backwards compatibility with previous Git versions, you can
    + also append `1`, `2` or `3` to either `vimdiff` or any of the variants (ex:
    +
      ## mergetools/vimdiff ##
     @@ mergetools/vimdiff: diff_cmd_help () {


 Documentation/config/mergetool.txt   | 19 +++++++++++++------
 Documentation/mergetools/vimdiff.txt |  3 ++-
 mergetools/vimdiff                   | 12 ++++++++++--
 3 files changed, 25 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt
index 294f61efd1..00bf665aa0 100644
--- a/Documentation/config/mergetool.txt
+++ b/Documentation/config/mergetool.txt
@@ -45,14 +45,21 @@  mergetool.meld.useAutoMerge::
 	value of `false` avoids using `--auto-merge` altogether, and is the
 	default value.
 
-mergetool.vimdiff.layout::
-	The vimdiff backend uses this variable to control how its split
-	windows appear. Applies even if you are using Neovim (`nvim`) or
-	gVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section
-ifndef::git-mergetool[]
-	in linkgit:git-mergetool[1].
+mergetool.<vimdiff variant>.layout::
+	Configure the split window layout for vimdiff's `<variant>`, which is any of `vimdiff`,
+	`nvimdiff`, `gvimdiff`.
+	Upon launching `git mergetool` with `--tool=<variant>` (or without `--tool`
+	if `merge.tool` is configured as `<variant>`), Git will consult
+	`mergetool.<variant>.layout` to determine the tool's layout. If the
+	variant-specific configuration is not available, `vimdiff`'s is used as
+	fallback.  If that too is not available, a default layout with 4 windows
+	will be used.  To configure the layout, see the `BACKEND SPECIFIC HINTS`
+ifdef::git-mergetool[]
+	section.
+endif::[]
+ifndef::git-mergetool[]
+	section in linkgit:git-mergetool[1].
 endif::[]
-	for details.
 
 mergetool.hideResolved::
 	During a merge, Git will automatically resolve as many conflicts as
diff --git a/Documentation/mergetools/vimdiff.txt b/Documentation/mergetools/vimdiff.txt
index d1a4c468e6..befa86d692 100644
--- a/Documentation/mergetools/vimdiff.txt
+++ b/Documentation/mergetools/vimdiff.txt
@@ -177,7 +177,8 @@  Instead of `--tool=vimdiff`, you can also use one of these other variants:
 
 When using these variants, in order to specify a custom layout you will have to
 set configuration variables `mergetool.gvimdiff.layout` and
-`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`
+`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout` (though the
+latter will be used as fallback if the variant-specific one is not set).
 
 In addition, for backwards compatibility with previous Git versions, you can
 also append `1`, `2` or `3` to either `vimdiff` or any of the variants (ex:
diff --git a/mergetools/vimdiff b/mergetools/vimdiff
index 06937acbf5..97e376329b 100644
--- a/mergetools/vimdiff
+++ b/mergetools/vimdiff
@@ -371,9 +371,17 @@  diff_cmd_help () {
 
 
 merge_cmd () {
-	layout=$(git config mergetool.vimdiff.layout)
+	TOOL=$1
 
-	case "$1" in
+	layout=$(git config "mergetool.$TOOL.layout")
+
+	# backward compatibility:
+	if test -z "$layout"
+	then
+		layout=$(git config mergetool.vimdiff.layout)
+	fi
+
+	case "$TOOL" in
 	*vimdiff)
 		if test -z "$layout"
 		then