git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] mergetools: vimdiff: use correct tool's name when reading mergetool config
@ 2024-02-15  8:39 Kipras Melnikovas
  2024-02-15 14:20 ` [PATCH v2] " Kipras Melnikovas
  0 siblings, 1 reply; 8+ messages in thread
From: Kipras Melnikovas @ 2024-02-15  8:39 UTC (permalink / raw
  To: git; +Cc: greenfoo, Kipras Melnikovas

I was curious why layout customizations, such as the multi-tab layout,
worked fine with vimdiff, but when changing to nvimdiff, it wouldn't anymore,
and instead showed the default view.

I was testing with the following config, everything was fine:

```conf
[merge]
	tool = vimdiff

[mergetool "vimdiff"]
	layout = local,base,remote / merged + base,local + base,remote + (local/base/remote),merged
```

```sh
git mergetool # opens vim w/ the custom 4-tab layout
```

But then I'd swap the tool to nvimdiff:

```diff
[merge]
-	tool = vimdiff
+	tool = nvimdiff

-[mergetool "vimdiff"]
+[mergetool "nvimdiff"]
	layout = local,base,remote / merged + base,local + base,remote + (local/base/remote),merged
```

and I'd get only the default 1-tab layout in neovim.

At first I thought that unlike vim,
neovim was somehow unable to launch multiple tabs.. Not the case.

Turns out, the /mergetools/vimdiff script, which handles both vimdiff, nvimdiff
and gvimdiff mergetools (the latter 2 simply source the vimdiff script), had 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.

Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
---
 Documentation/config/mergetool.txt | 9 +++++----
 mergetools/vimdiff                 | 6 ++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt
index 294f61efd1..8e3d321a57 100644
--- a/Documentation/config/mergetool.txt
+++ b/Documentation/config/mergetool.txt
@@ -45,10 +45,11 @@ 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
+mergetool.{g,n,}vimdiff.layout::
+	The vimdiff backend uses this variable to control how its split windows
+	appear. Use `mergetool.vimdiff` for regular Vim, `mergetool.nvimdiff` for
+	Neovim and `mergetool.gvimdiff` for gVim to configure the merge tool. See
+	BACKEND SPECIFIC HINTS section
 ifndef::git-mergetool[]
 	in linkgit:git-mergetool[1].
 endif::[]
diff --git a/mergetools/vimdiff b/mergetools/vimdiff
index 06937acbf5..dd6bc411d9 100644
--- a/mergetools/vimdiff
+++ b/mergetools/vimdiff
@@ -371,9 +371,11 @@ diff_cmd_help () {
 
 
 merge_cmd () {
-	layout=$(git config mergetool.vimdiff.layout)
+	TOOL=$1
 
-	case "$1" in
+	layout=$(git config mergetool.$TOOL.layout)
+
+	case "$TOOL" in
 	*vimdiff)
 		if test -z "$layout"
 		then
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2] mergetools: vimdiff: use correct tool's name when reading mergetool config
  2024-02-15  8:39 [PATCH] mergetools: vimdiff: use correct tool's name when reading mergetool config Kipras Melnikovas
@ 2024-02-15 14:20 ` Kipras Melnikovas
  2024-02-15 18:42   ` Junio C Hamano
                     ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Kipras Melnikovas @ 2024-02-15 14:20 UTC (permalink / raw
  To: git; +Cc: greenfoo, Kipras Melnikovas

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 backwards-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>
---
Range-diff against v1:
1:  197e42deef ! 1:  070280d95d mergetools: vimdiff: use correct tool's name when reading mergetool config
    @@ Metadata
      ## Commit message ##
         So it looks like we just forgot to update the 1 part of the vimdiff script
         that read the config variable. Cheers.
     
    +    Though, for backwards-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>
     
    @@ mergetools/vimdiff: diff_cmd_help () {
     -	case "$1" in
     +	layout=$(git config mergetool.$TOOL.layout)
     +
    ++	# backwards-compatibility:
    ++	if test -z "$layout"
    ++	then
    ++		layout=$(git config mergetool.vimdiff.layout)
    ++	fi
    ++
     +	case "$TOOL" in
      	*vimdiff)
      		if test -z "$layout"

 Documentation/config/mergetool.txt |  9 +++++----
 mergetools/vimdiff                 | 12 ++++++++++--
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt
index 294f61efd1..8e3d321a57 100644
--- a/Documentation/config/mergetool.txt
+++ b/Documentation/config/mergetool.txt
@@ -45,10 +45,11 @@ 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
+mergetool.{g,n,}vimdiff.layout::
+	The vimdiff backend uses this variable to control how its split windows
+	appear. Use `mergetool.vimdiff` for regular Vim, `mergetool.nvimdiff` for
+	Neovim and `mergetool.gvimdiff` for gVim to configure the merge tool. See
+	BACKEND SPECIFIC HINTS section
 ifndef::git-mergetool[]
 	in linkgit:git-mergetool[1].
 endif::[]
diff --git a/mergetools/vimdiff b/mergetools/vimdiff
index 06937acbf5..0e3058868a 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)
+
+	# backwards-compatibility:
+	if test -z "$layout"
+	then
+		layout=$(git config mergetool.vimdiff.layout)
+	fi
+
+	case "$TOOL" in
 	*vimdiff)
 		if test -z "$layout"
 		then

base-commit: 4fc51f00ef18d2c0174ab2fd39d0ee473fd144bd
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] mergetools: vimdiff: use correct tool's name when reading mergetool config
  2024-02-15 14:20 ` [PATCH v2] " Kipras Melnikovas
@ 2024-02-15 18:42   ` Junio C Hamano
  2024-02-15 20:43   ` Fernando Ramos
  2024-02-17  7:43   ` [PATCH v3] " Kipras Melnikovas
  2 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2024-02-15 18:42 UTC (permalink / raw
  To: Kipras Melnikovas; +Cc: git, greenfoo

Kipras Melnikovas <kipras@kipras.org> writes:

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

It is a good consideration, and should be documented ...

> diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt
> index 294f61efd1..8e3d321a57 100644
> --- a/Documentation/config/mergetool.txt
> +++ b/Documentation/config/mergetool.txt
> @@ -45,10 +45,11 @@ 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
> +mergetool.{g,n,}vimdiff.layout::
> +	The vimdiff backend uses this variable to control how its split windows
> +	appear. Use `mergetool.vimdiff` for regular Vim, `mergetool.nvimdiff` for
> +	Neovim and `mergetool.gvimdiff` for gVim to configure the merge tool. See
> +	BACKEND SPECIFIC HINTS section

... perhaps before "See BACKEND SPECIFIC HINTS section."  E.g.

	When a variant of vimdiff (vim, Neovim, or gVim) is used as
	a mergetool backend, they use this variable to control how
	the split windows appear.
	The variable `mergetool.<variant>.layout` (where <variant>
	is one of `vimdiff`, `nvimdiff`, or `gvimdiff`, depending on
	what you are using) is consulted first, and if it is missing,
	`mergetool.vimdiff.layout` is used as a fallback.  See
	BACKEND SPECIFIC HINTS section.

or something?	


> diff --git a/mergetools/vimdiff b/mergetools/vimdiff
> index 06937acbf5..0e3058868a 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)

The callers of merge_cmd are careful to do

	merge_cmd "$1"

so it would be a good hygiene to also quote $TOOL here, i.e.

	layout=$(git config "mergetool.$TOOL.layout")

It might not matter if the caller of run_merge_cmd (which calls
merge_cmd) eventually chooses from a known set of strings hardcoded
in mergetools--lib.sh, but it is much easier to show that you are
doing the right thing without relying on such a detail of what
happens far in the code to quote what you get from the caller
appropriately.

> +
> +	# backwards-compatibility:
> +	if test -z "$layout"
> +	then
> +		layout=$(git config mergetool.vimdiff.layout)
> +	fi
> +
> +	case "$TOOL" in

This one is quoted properly (and TOOL=$1 at the beginning does not
require quoting).  The "git config" call above is the only one that
needs to be fixed.

Thanks.

>  	*vimdiff)
>  		if test -z "$layout"
>  		then
>
> base-commit: 4fc51f00ef18d2c0174ab2fd39d0ee473fd144bd


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] mergetools: vimdiff: use correct tool's name when reading mergetool config
  2024-02-15 14:20 ` [PATCH v2] " Kipras Melnikovas
  2024-02-15 18:42   ` Junio C Hamano
@ 2024-02-15 20:43   ` Fernando Ramos
  2024-02-17  7:43   ` [PATCH v3] " Kipras Melnikovas
  2 siblings, 0 replies; 8+ messages in thread
From: Fernando Ramos @ 2024-02-15 20:43 UTC (permalink / raw
  To: Kipras Melnikovas; +Cc: git

On 24/02/15 04:20PM, Kipras Melnikovas wrote:
> 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).

You are 100% right. I completely overlooked this detail in the original
implementation.

Thanks for the fix!



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3] mergetools: vimdiff: use correct tool's name when reading mergetool config
  2024-02-15 14:20 ` [PATCH v2] " Kipras Melnikovas
  2024-02-15 18:42   ` Junio C Hamano
  2024-02-15 20:43   ` Fernando Ramos
@ 2024-02-17  7:43   ` Kipras Melnikovas
  2024-02-17 16:27     ` [PATCH v4] " Kipras Melnikovas
  2 siblings, 1 reply; 8+ messages in thread
From: Kipras Melnikovas @ 2024-02-17  7:43 UTC (permalink / raw
  To: git; +Cc: gitster, greenfoo, Kipras Melnikovas

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>
---

Here's some variants I considered for mergetool.<vimdiff variant>.layout
in Documentation/config/mergetool.txt, but discarded for a shorter
version. Feel free to pick & edit the final.

a)
	The `<vimdiff variant>` is any of `vimdiff`, `nvimdiff`, `gvimdiff`. When
	you run `git mergetool` with `--tool=<vimdiff variant>`, Git will consult
	`mergetool.<vimdiff variant>.layout` to determine the tool's layout. If it's
	not specified, `vimdiff`'s is used as fallback. If that too is not available,
	a default layout with 4 windows is used. See BACKEND SPECIFIC HINTS section
ifndef::git-mergetool[]
	in linkgit:git-mergetool[1]
endif::[]
	for details.

b)
	Configure a custom layout for your mergetool. The `<variant>` 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.<vimdiff variant>.layout` to determine the tool's
	layout.  If the variant-specific config is not available, `vimdiff`'s is
	used as fallback. If that too is not available, a default layout with 4
	windows will be used. See BACKEND SPECIFIC HINTS section
ifndef::git-mergetool[]
	in linkgit:git-mergetool[1]
endif::[]
	for details.


The ifdef + ifndef is used to avoid an extra space before the final "."


Range-diff against v2:
1:  070280d95d ! 1:  60be87c3d5 mergetools: vimdiff: use correct tool's name when reading mergetool config
    @@ Documentation/config/mergetool.txt: mergetool.meld.useAutoMerge::
     -	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
    -+mergetool.{g,n,}vimdiff.layout::
    -+	The vimdiff backend uses this variable to control how its split windows
    -+	appear. Use `mergetool.vimdiff` for regular Vim, `mergetool.nvimdiff` for
    -+	Neovim and `mergetool.gvimdiff` for gVim to configure the merge tool. See
    -+	BACKEND SPECIFIC HINTS section
    - ifndef::git-mergetool[]
    - 	in linkgit:git-mergetool[1].
    +-ifndef::git-mergetool[]
    +-	in linkgit:git-mergetool[1].
    ++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`
    ++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
     
      ## mergetools/vimdiff ##
     @@ mergetools/vimdiff: diff_cmd_help () {
    @@ mergetools/vimdiff: diff_cmd_help () {
     +	TOOL=$1
      
     -	case "$1" in
    -+	layout=$(git config mergetool.$TOOL.layout)
    ++	layout=$(git config "mergetool.$TOOL.layout")
     +
    -+	# backwards-compatibility:
    ++	# backward compatibility:
     +	if test -z "$layout"
     +	then
     +		layout=$(git config mergetool.vimdiff.layout)

 Documentation/config/mergetool.txt | 17 ++++++++++-------
 mergetools/vimdiff                 | 12 ++++++++++--
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt
index 294f61efd1..f79c798b74 100644
--- a/Documentation/config/mergetool.txt
+++ b/Documentation/config/mergetool.txt
@@ -45,14 +45,17 @@ 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::
+	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`
+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/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

base-commit: 3e0d3cd5c7def4808247caf168e17f2bbf47892b
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v4] mergetools: vimdiff: use correct tool's name when reading mergetool config
  2024-02-17  7:43   ` [PATCH v3] " Kipras Melnikovas
@ 2024-02-17 16:27     ` Kipras Melnikovas
  2024-02-20  2:52       ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Kipras Melnikovas @ 2024-02-17 16:27 UTC (permalink / raw
  To: git; +Cc: gitster, greenfoo, Kipras Melnikovas

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(-)

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

base-commit: 3e0d3cd5c7def4808247caf168e17f2bbf47892b
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] mergetools: vimdiff: use correct tool's name when reading mergetool config
  2024-02-17 16:27     ` [PATCH v4] " Kipras Melnikovas
@ 2024-02-20  2:52       ` Junio C Hamano
  2024-02-21  5:20         ` Kipras Melnikovas
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2024-02-20  2:52 UTC (permalink / raw
  To: Kipras Melnikovas; +Cc: git, greenfoo

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?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] mergetools: vimdiff: use correct tool's name when reading mergetool config
  2024-02-20  2:52       ` Junio C Hamano
@ 2024-02-21  5:20         ` Kipras Melnikovas
  0 siblings, 0 replies; 8+ messages in thread
From: Kipras Melnikovas @ 2024-02-21  5:20 UTC (permalink / raw
  To: gitster; +Cc: git, greenfoo, kipras

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(-)



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-02-21  5:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-15  8:39 [PATCH] mergetools: vimdiff: use correct tool's name when reading mergetool config Kipras Melnikovas
2024-02-15 14:20 ` [PATCH v2] " Kipras Melnikovas
2024-02-15 18:42   ` Junio C Hamano
2024-02-15 20:43   ` Fernando Ramos
2024-02-17  7:43   ` [PATCH v3] " Kipras Melnikovas
2024-02-17 16:27     ` [PATCH v4] " Kipras Melnikovas
2024-02-20  2:52       ` Junio C Hamano
2024-02-21  5:20         ` Kipras Melnikovas

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).