git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] mergetools: vimdiff3: make it work as intended

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Aug 2, 2022, 21:41 UTC
Message-ID
<20220802214134.681300-2-felipe.contreras@gmail.com>
In-Reply-To
<20220802214134.681300-1-felipe.contreras@gmail.com>

When vimdiff3 was added in 7c147b77d3 (mergetools: add vimdiff3 mode, 2014-04-20), the description made clear the intention:

It's similar to the default, except that the other windows are hidden. This ensures that removed/added colors are still visible on the main merge window, but the other windows not visible.

However, in 0041797449 (vimdiff: new implementation with layout support, 2022-03-30) this was broken by generating a command that never creates windows, and therefore vim never shows the diff.

In order to show the diff, the windows need to be created first, and then when they are hidden the diff remains (if hidenoff isn't set).

The layout support implementation broke the whole purpose of vimdiff3, and simply shows MERGED, which is no different from simply opening the file with vim.

We could restore the correct behavior by modifying gen_cmd to open all the windows, and then hide them, but there's no need to do that when the -d option of vim (vimdiff) does precisely that.

So let's skip the whole gen_cmd function for vimdiff3, and hide the windows, therefore restoring the previous intended behavior.

Cc: Fernando Ramos <greenfoo@u92.eu>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 mergetools/vimdiff | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/mergetools/vimdiff b/mergetools/vimdiff
index f770b8fe24..f4c3bf6d11 100644
--- a/mergetools/vimdiff
+++ b/mergetools/vimdiff
@@ -388,26 +388,36 @@ merge_cmd () {
 	layout=$(git config mergetool.vimdiff.layout)
 
 	case "$1" in
-	*vimdiff)
-		if test -z "$layout"
+	*vimdiff3)
+		if $base_present
 		then
-			# Default layout when none is specified
-			layout="(LOCAL,BASE,REMOTE)/MERGED"
+			CMD='hid | hid | hid'
+		else
+			CMD='hid | hid'
 		fi
+		FINAL_CMD="-d -c '$CMD'"
 		;;
-	*vimdiff1)
-		layout="@LOCAL,REMOTE"
-		;;
-	*vimdiff2)
-		layout="LOCAL,MERGED,REMOTE"
-		;;
-	*vimdiff3)
-		layout="MERGED"
+	*)
+		case "$1" in
+		*vimdiff)
+			if test -z "$layout"
+			then
+				# Default layout when none is specified
+				layout="(LOCAL,BASE,REMOTE)/MERGED"
+			fi
+			;;
+		*vimdiff1)
+			layout="@LOCAL,REMOTE"
+			;;
+		*vimdiff2)
+			layout="LOCAL,MERGED,REMOTE"
+			;;
+		esac
+
+		gen_cmd "$layout"
 		;;
 	esac
 
-	gen_cmd "$layout"
-
 	debug_print ""
 	debug_print "FINAL CMD : $FINAL_CMD"
 	debug_print "FINAL TAR : $FINAL_TARGET"
-- 
2.37.1.313.ge269dbcbc5
Previous: Felipe ContrerasNext: Felipe Contreras
Message 2 of 15 in “mergetools: vimdiff3: fix regression”
  1. 0/2 mergetools: vimdiff3: fix regressionFelipe Contreras, Aug 2, 2022
  2. 1/2 mergetools: vimdiff3: make it work as intendedFelipe Contreras, Aug 2, 2022
  3. 2/2 mergetools: vimdiff3: fix diffopt optionsFelipe Contreras, Aug 2, 2022
  4. Fernando RamosAug 6, 2022
  5. Fernando RamosAug 6, 2022
  6. Felipe ContrerasAug 6, 2022
  7. Fernando RamosAug 6, 2022
  8. vimdiff: fix 'vimdiff3' behavior (colors + no extra key press)Fernando Ramos, Aug 6, 2022
  9. Felipe ContrerasAug 6, 2022
  10. Fernando RamosAug 6, 2022
  11. vimdiff: fix 'vimdiff3' behavior (colors + no extra key press)Fernando Ramos, Aug 6, 2022
  12. Felipe ContrerasAug 7, 2022
  13. Felipe ContrerasAug 6, 2022
  14. Fernando RamosAug 6, 2022
  15. Felipe ContrerasAug 7, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.