{"thread":{"id":"57623","subject":"[PATCH v6 1/3] vimdiff: new implementation with layout support","startedAt":"2022-03-27T11:23:25Z","lastAt":"2022-03-28T19:20:02Z","messageCount":16,"participants":["Fernando Ramos","Philippe Blain","Junio C Hamano","Bagas Sanjaya"],"isPatch":true,"patchVersion":6,"patchTotal":3},"messages":[{"id":"452429","messageId":"20220327112307.151044-2-greenfoo@u92.eu","threadId":"57623","inReplyTo":"20220327112307.151044-1-greenfoo@u92.eu","subject":"[PATCH v6 1/3] vimdiff: new implementation with layout support","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-27T11:23:05Z","receivedAt":"2022-03-27T11:23:25Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"When running 'git mergetool -t vimdiff', a new configuration option\n('mergetool.vimdiff.layout') can now be used to select how the user\nwants the different windows, tabs and buffers to be displayed.\n\nIf the option is not provided, the layout will be the same one that was\nbeing used before this commit (ie. two rows with LOCAL, BASE and COMMIT\nin the top one and MERGED in the bottom one).\n\nThe 'vimdiff' variants ('vimdiff{1,2,3}') still work but, because they\nrepresented nothing else than different layouts, are now internally\nimplemented as a subcase of 'vimdiff' with the corresponding\npre-configured 'layout'.\n\nAgain, if you don't set \"mergetool.vimdiff.layout\" everything will work\nthe same as before *but* the arguments used to call {n,g,}vim will be\nothers (even if you don't/shouldn't notice it):\n\n  - git mergetool -t vimdiff\n\n    > Before this commit:\n      {n,g,}vim -f -d -c '4wincmd w | wincmd J' $LOCAL $BASE $REMOTE $MERGED\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff1\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'echon \"...\"' $LOCAL $REMOTE\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff2\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'wincmd l' $LOCAL $MERGED $REMOTE\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | vertical split | 1b | wincmd l | vertical split | 4b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff3\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'hid | hid | hid' $LOCAL $REMOTE $BASE $MERGED\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | 4b | bufdo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\nDespite being different, I have manually verified that they generate the same\nlayout as before.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n mergetools/vimdiff | 547 ++++++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 519 insertions(+), 28 deletions(-)\n\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 96f6209a04..e3f442caf3 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -1,49 +1,441 @@\n+# This script can be run in two different contexts:\n+#\n+#   - From git, when the user invokes the \"vimdiff\" merge tool. In this context\n+#     this script expects the following environment variables (among others) to\n+#     be defined (which is something \"git\" takes care of):\n+#\n+#       - $BASE\n+#       - $LOCAL\n+#       - $REMOTE\n+#       - $MERGED\n+#\n+#     In this mode, all this script does is to run the next command:\n+#\n+#         vim -f -c ... $LOCAL $BASE $REMOTE $MERGED\n+#\n+#     ...where the \"...\" string depends on the value of the\n+#     \"mergetool.vimdiff.layout\" configuration variable and is used to open vim\n+#     with a certain layout of buffers, windows and tabs.\n+#\n+#   - From a script inside the unit tests framework folder (\"t\" folder) by\n+#     sourcing this script and then manually calling \"run_unit_tests\", which\n+#     will run a battery of unit tests to make sure nothing breaks.\n+#     In this context this script does not expect any particular environment\n+#     variable to be set.\n+\n+\n+################################################################################\n+## Internal functions (not meant to be used outside this script)\n+################################################################################\n+\n+debug_print () { \n+\t# Send message to stderr if global variable DEBUG is set to \"true\"\n+\n+\tif test -n \"$GIT_MERGETOOL_VIMDIFF_DEBUG\"\n+\tthen\n+\t\t>&2 echo \"$@\"\n+\tfi\n+}\n+\n+substring () {\n+\t# Return a substring of $1 containing $3 characters starting at\n+\t# zero-based offset $2.\n+\t# \n+\t# Examples:\n+\t#\n+\t#   substring \"Hello world\" 0 4  --> \"Hell\"\n+\t#   substring \"Hello world\" 3 4  --> \"lo w\"\n+\t#   substring \"Hello world\" 3 10 --> \"lo world\"\n+\n+\tSTRING=$1\n+\tSTART=$2\n+\tLEN=$3\n+\n+\techo \"$STRING\" | cut -c$(( START + 1 ))-$(( START + $LEN ))\n+}\n+\n+gen_cmd_aux () {\n+\t# Auxiliary function used from \"gen_cmd()\".\n+\t# Read that other function documentation for more details.\n+\n+\tLAYOUT=$1 \n+\tCMD=$2  # This is a second (hidden) argument used for recursion  \n+\n+\tdebug_print\n+\tdebug_print \"LAYOUT    : $LAYOUT\"\n+\tdebug_print \"CMD       : $CMD\"\n+\n+\tif test -z \"$CMD\"\n+\tthen\n+\t\tCMD=\"echo\" # vim \"nop\" operator\n+\tfi\n+\n+\tstart=0\n+\tend=${#LAYOUT}\n+\n+\tnested=0\n+\tnested_min=100\n+\n+\n+\t# Step 1:\n+\t#\n+\t# Increase/decrease \"start\"/\"end\" indices respectively to get rid of\n+\t# outer parenthesis.\n+\t#\n+\t# Example:\n+\t#\n+\t#   - BEFORE: (( LOCAL , BASE ) / MERGED )\n+\t#   - AFTER :  ( LOCAL , BASE ) / MERGED \n+\n+\toldIFS=$IFS\n+\tIFS=#\n+\tfor c in $(echo \"$LAYOUT\" | sed 's:.:&#:g')\n+\tdo\n+\t\tif test \"$c\" = \" \"\n+\t\tthen\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \"(\"\n+\t\tthen\n+\t\t\tnested=$(( nested + 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \")\"\n+\t\tthen\n+\t\t\tnested=$(( nested - 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$nested\" -lt \"$nested_min\"\n+\t\tthen\n+\t\t\tnested_min=$nested\n+\t\tfi\n+\tdone\n+\tIFS=$oldIFS\n+\n+\tdebug_print \"NESTED MIN: $nested_min\"\n+\n+\twhile test \"$nested_min\" -gt \"0\"\n+\tdo\n+\t\tstart=$(( start + 1 ))\n+\t\tend=$(( end - 1 ))\n+\n+\t\tstart_minus_one=$(( start - 1 ))\n+\n+\t\twhile ! test \"$(substring \"$LAYOUT\" \"$start_minus_one\" 1)\" = \"(\"\n+\t\tdo\n+\t\t\tstart=$(( start + 1 ))\n+\t\t\tstart_minus_one=$(( start_minus_one + 1 ))\n+\t\tdone\n+\n+\t\twhile ! test \"$(substring \"$LAYOUT\" \"$end\" 1)\" = \")\"\n+\t\tdo\n+\t\t\tend=$(( end - 1 ))\n+\t\tdone\n+\n+\t\tnested_min=$(( nested_min - 1 ))\n+\tdone\n+\n+\tdebug_print \"CLEAN     : $(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\")\"\n+\n+\n+\t# Step 2:\n+\t#\n+\t# Search for all valid separators (\"+\", \"/\" or \",\") which are *not*\n+\t# inside parenthesis. Save the index at which each of them makes the\n+\t# first appearance.\n+\n+\tindex_new_tab=\"\"\n+\tindex_horizontal_split=\"\"\n+\tindex_vertical_split=\"\"\n+\n+\tnested=0\n+\ti=$(( start - 1 ))\n+\n+\toldIFS=$IFS\n+\tIFS=#\n+\tfor c in $(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\" | sed 's:.:&#:g');\n+\tdo\n+\t\ti=$(( i + 1 ))\n+\n+\t\tif test \"$c\" = \" \"\n+\t\tthen\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \"(\"\n+\t\tthen\n+\t\t\tnested=$(( nested + 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \")\"\n+\t\tthen\n+\t\t\tnested=$(( nested - 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$nested\" = 0\n+\t\tthen\n+\t\t\tcurrent=$c\n+\t\t\t\n+\t\t\tif test \"$current\" = \"+\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_new_tab\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_new_tab=$i\n+\t\t\t\tfi\n+\n+\t\t\telif test \"$current\" = \"/\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_horizontal_split\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_horizontal_split=$i\n+\t\t\t\tfi\n+\n+\t\t\telif test \"$current\" = \",\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_vertical_split\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_vertical_split=$i\n+\t\t\t\tfi\n+\t\t\tfi\n+\t\tfi\n+\tdone\n+\tIFS=$oldIFS\n+\n+\n+\t# Step 3:\n+\t#\n+\t# Process the separator with the highest order of precedence\n+\t# (\";\" has the highest precedence and \"|\" the lowest one).\n+\t#\n+\t# By \"process\" I mean recursively call this function twice: the first\n+\t# one with the substring at the left of the separator and the second one\n+\t# with the one at its right.\n+\n+\tterminate=\"false\"\n+\n+\tif ! test -z \"$index_new_tab\"\n+\tthen\n+\t\tbefore=\"-tabnew\"\n+\t\tafter=\"tabnext\"\n+\t\tindex=$index_new_tab\n+\t\tterminate=\"true\"\n+\n+\telif ! test -z \"$index_horizontal_split\"\n+\tthen\n+\t\tbefore=\"split\"\n+\t\tafter=\"wincmd j\"\n+\t\tindex=$index_horizontal_split\n+\t\tterminate=\"true\"\n+\n+\telif ! test -z \"$index_vertical_split\"\n+\tthen\n+\t\tbefore=\"vertical split\"\n+\t\tafter=\"wincmd l\"\n+\t\tindex=$index_vertical_split\n+\t\tterminate=\"true\"\n+\tfi\n+\n+\tif  test \"$terminate\" = \"true\"\n+\tthen\n+\t\tCMD=\"$CMD | $before\"\n+\t\tCMD=$(gen_cmd_aux \"$(substring \"$LAYOUT\" \"$start\" \"$(( index - start ))\")\" \"$CMD\")\n+\t\tCMD=\"$CMD | $after\"\n+\t\tCMD=$(gen_cmd_aux \"$(substring \"$LAYOUT\" \"$(( index + 1 ))\" \"$(( ${#LAYOUT} - index ))\")\" \"$CMD\")\n+\t\techo \"$CMD\"\n+\t\treturn\n+\tfi\n+\n+\n+\t# Step 4:\n+\t#\n+\t# If we reach this point, it means there are no separators and we just\n+\t# need to print the command to display the specified buffer\n+\n+\ttarget=$(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\" | sed 's:[ @();|-]::g')\n+\n+\tif test \"$target\" = \"LOCAL\"\n+\tthen\n+\t\tCMD=\"$CMD | 1b\"\n+\n+\telif test \"$target\" = \"BASE\"\n+\tthen\n+\t\tCMD=\"$CMD | 2b\"\n+\n+\telif test \"$target\" = \"REMOTE\"\n+\tthen\n+\t\tCMD=\"$CMD | 3b\"\n+\n+\telif test \"$target\" = \"MERGED\"\n+\tthen\n+\t\tCMD=\"$CMD | 4b\"\n+\n+\telse\n+\t\tCMD=\"$CMD | ERROR: >$target<\"\n+\tfi\n+\n+\techo \"$CMD\"\n+\treturn\n+}\n+\n+\n+gen_cmd () {\n+\t# This function returns (in global variable FINAL_CMD) the string that\n+\t# you can use when invoking \"vim\" (as shown next) to obtain a given\n+\t# layout:\n+\t#\n+\t#   $ vim -f $FINAL_CMD \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n+\t#\n+\t# It takes one single argument: a string containing the desired layout\n+\t# definition.\n+\t#\n+\t# The syntax of the \"layout definitions\" is explained in ... (TODO)...\n+\t# but you can already intuitively understand how it works by knowing\n+\t# that...\n+\t#\n+\t#   * \";\" means \"a new vim tab\"\n+\t#   * \"-\" means \"a new vim horizontal split\"\n+\t#   * \"|\" means \"a new vim vertical split\"\n+\t#\n+\t# It also returns (in global variable FINAL_TARGET) the name (\"LOCAL\",\n+\t# \"BASE\", \"REMOTE\" or \"MERGED\") of the file that is marked with an \"@\",\n+\t# or \"MERGED\" if none of them is.\n+\t#\n+\t# Example:\n+\t#\n+\t#     gen_cmd \"@LOCAL , REMOTE\"\n+\t#     |\n+\t#     `-> FINAL_CMD    == \"-c \\\"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\t#         FINAL_TARGET == \"LOCAL\"\n+\n+\tLAYOUT=$1 \n+\n+\n+\t# Search for a \"@\" in one of the files identifiers (\"LOCAL\", \"BASE\",\n+\t# \"REMOTE\", \"MERGED\"). If not found, use \"MERGE\" as the default file\n+\t# where changes will be saved.\n+\n+\tif echo \"$LAYOUT\" | grep @LOCAL >/dev/null\n+\tthen\n+\t\tFINAL_TARGET=\"LOCAL\"\n+\telif echo \"$LAYOUT\" | grep @BASE >/dev/null\n+\tthen\n+\t\tFINAL_TARGET=\"BASE\"\n+\telse\n+\t\tFINAL_TARGET=\"MERGED\"\n+\tfi\n+\n+\n+\t# Obtain the first part of vim \"-c\" option to obtain the desired layout\n+\n+\tCMD=$(gen_cmd_aux \"$LAYOUT\")\n+\n+\n+\t# Adjust the just obtained script depending on whether more than one\n+\t# windows are visible or not\n+\n+\tif echo \"$LAYOUT\" | grep \",\\|/\" >/dev/null\n+\tthen\n+\t\tCMD=\"$CMD | tabdo windo diffthis\"\n+\telse\n+\t\tCMD=\"$CMD | bufdo diffthis\"\n+\tfi\n+\n+\n+\t# Add an extra \"-c\" option to move to the first tab (notice that we\n+\t# can't simply append the command to the previous \"-c\" string as\n+\t# explained here: https://github.com/vim/vim/issues/9076\n+\n+\tFINAL_CMD=\"-c \\\"$CMD\\\" -c \\\"tabfirst\\\"\"\n+}\n+\n+\n+################################################################################\n+## API functions (called from \"git-mergetool--lib.sh\")\n+################################################################################\n+\n diff_cmd () {\n \t\"$merge_tool_path\" -R -f -d \\\n \t\t-c 'wincmd l' -c 'cd $GIT_PREFIX' \"$LOCAL\" \"$REMOTE\"\n }\n \n+\n merge_cmd () {\n+\tlayout=$(git config mergetool.$merge_tool.layout)\n+\n \tcase \"$1\" in\n \t*vimdiff)\n-\t\tif $base_present\n+\t\tif test -z \"$layout\"\n \t\tthen\n-\t\t\t\"$merge_tool_path\" -f -d -c '4wincmd w | wincmd J' \\\n-\t\t\t\t\"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n-\t\telse\n-\t\t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n-\t\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\t\t# Default layout when none is specified\n+\t\t\tlayout=\"(LOCAL,BASE,REMOTE)/MERGED\"\n \t\tfi\n \t\t;;\n \t*vimdiff1)\n-\t\t\"$merge_tool_path\" -f -d \\\n-\t\t\t-c 'echon \"Resolve conflicts leftward then save. Use :cq to abort.\"' \\\n-\t\t\t\"$LOCAL\" \"$REMOTE\"\n-\t\tret=\"$?\"\n-\t\tif test \"$ret\" -eq 0\n-\t\tthen\n-\t\t\tcp -- \"$LOCAL\" \"$MERGED\"\n-\t\tfi\n-\t\treturn \"$ret\"\n+\t\tlayout=\"@LOCAL,REMOTE\"\n \t\t;;\n \t*vimdiff2)\n-\t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n-\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\tlayout=\"LOCAL,MERGED,REMOTE\"\n \t\t;;\n \t*vimdiff3)\n-\t\tif $base_present\n-\t\tthen\n-\t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid | hid' \\\n-\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"\n-\t\telse\n-\t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid' \\\n-\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$MERGED\"\n-\t\tfi\n+\t\tlayout=\"MERGED\"\n \t\t;;\n \tesac\n+\n+\tgen_cmd \"$layout\"\n+\n+\tdebug_print \"\"\n+\tdebug_print \"FINAL CMD : $FINAL_CMD\"\n+\tdebug_print \"FINAL TAR : $FINAL_TARGET\"\n+\n+\tif $base_present\n+\tthen\n+\t\teval \"$merge_tool_path\" \\\n+\t\t\t-f \"$FINAL_CMD\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n+\telse\n+\t\t# If there is no BASE (example: a merge conflict in a new file\n+\t\t# with the same name created in both braches which didn't exist\n+\t\t# before), close all BASE windows using vim's \"quit\" command\n+\n+\t\tFINAL_CMD=$(echo \"$FINAL_CMD\" | \\\n+\t\t\tsed -e 's:2b:quit:g' -e 's:3b:2b:g' -e 's:4b:3b:g')\n+\n+\t\teval \"$merge_tool_path\" \\\n+\t\t\t-f \"$FINAL_CMD\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"\n+\tfi\n+\n+\tret=\"$?\"\n+\n+\tif test \"$ret\" -eq 0\n+\tthen\n+\t\tcase \"$FINAL_TARGET\" in\n+\t\tLOCAL)\n+\t\t\tsource_path=\"$LOCAL\"\n+\t\t\t;;\n+\t\tREMOTE)\n+\t\t\tsource_path=\"$REMOTE\"\n+\t\t\t;;\n+\t\tMERGED|*)\n+\t\t\t# Do nothing\n+\t\t\tsource_path=\n+\t\t\t;;\n+\t\tesac\n+\n+\t\tif test -n \"$source_path\"\n+\t\tthen\n+\t\t\tcp \"$source_path\" \"$MERGED\"\n+\t\tfi\n+\tfi\n+\n+\treturn \"$ret\"\n }\n \n-translate_merge_tool_path() {\n+\n+translate_merge_tool_path () {\n \tcase \"$1\" in\n \tnvimdiff*)\n \t\techo nvim\n@@ -57,14 +449,113 @@ translate_merge_tool_path() {\n \tesac\n }\n \n+\n exit_code_trustable () {\n \ttrue\n }\n \n+\n list_tool_variants () {\n-\tfor prefix in '' g n; do\n-\t\tfor suffix in '' 1 2 3; do\n+\tfor prefix in '' g n\n+\tdo\n+\t\tfor suffix in '' 1 2 3\n+\t\tdo\n \t\t\techo \"${prefix}vimdiff${suffix}\"\n \t\tdone\n \tdone\n }\n+\n+\n+################################################################################\n+## Unit tests (called from scripts inside the \"t\" folder)\n+################################################################################\n+\n+run_unit_tests () {\n+\t# Function to make sure that we don't break anything when modifying this\n+\t# script.\n+\n+\tNUMBER_OF_TEST_CASES=16\n+\n+\tTEST_CASE_01=\"(LOCAL,BASE,REMOTE)/MERGED\"   # default behaviour\n+\tTEST_CASE_02=\"@LOCAL,REMOTE\"                # when using vimdiff1\n+\tTEST_CASE_03=\"LOCAL,MERGED,REMOTE\"          # when using vimdiff2\n+\tTEST_CASE_04=\"MERGED\"                       # when using vimdiff3\n+\tTEST_CASE_05=\"LOCAL/MERGED/REMOTE\"\n+\tTEST_CASE_06=\"(LOCAL/REMOTE),MERGED\"\n+\tTEST_CASE_07=\"MERGED,(LOCAL/REMOTE)\"\n+\tTEST_CASE_08=\"(LOCAL,REMOTE)/MERGED\"\n+\tTEST_CASE_09=\"MERGED/(LOCAL,REMOTE)\"\n+\tTEST_CASE_10=\"(LOCAL/BASE/REMOTE),MERGED\"\n+\tTEST_CASE_11=\"(LOCAL,BASE,REMOTE)/MERGED+BASE,LOCAL+BASE,REMOTE+(LOCAL/BASE/REMOTE),MERGED\"\n+\tTEST_CASE_12=\"((LOCAL,REMOTE)/BASE),MERGED\"\n+\tTEST_CASE_13=\"((LOCAL,REMOTE)/BASE),((LOCAL/REMOTE),MERGED)\"\n+\tTEST_CASE_14=\"BASE,REMOTE+BASE,LOCAL\"\n+\tTEST_CASE_15=\"  ((  (LOCAL , BASE , REMOTE) / MERGED))   +(BASE)   , LOCAL+ BASE , REMOTE+ (((LOCAL / BASE / REMOTE)) ,    MERGED   )  \"\n+\tTEST_CASE_16=\"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL / BASE / REMOTE),MERGED\"\n+\n+\tEXPECTED_CMD_01=\"-c \\\"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_02=\"-c \\\"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_03=\"-c \\\"echo | vertical split | 1b | wincmd l | vertical split | 4b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_04=\"-c \\\"echo | 4b | bufdo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_05=\"-c \\\"echo | split | 1b | wincmd j | split | 4b | wincmd j | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_06=\"-c \\\"echo | vertical split | split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_07=\"-c \\\"echo | vertical split | 4b | wincmd l | split | 1b | wincmd j | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_08=\"-c \\\"echo | split | vertical split | 1b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_09=\"-c \\\"echo | split | 4b | wincmd j | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_10=\"-c \\\"echo | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_11=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_12=\"-c \\\"echo | vertical split | split | vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_13=\"-c \\\"echo | vertical split | split | vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | vertical split | split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_14=\"-c \\\"echo | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | 2b | wincmd l | 1b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_15=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_16=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\n+\tEXPECTED_TARGET_01=\"MERGED\"\n+\tEXPECTED_TARGET_02=\"LOCAL\"\n+\tEXPECTED_TARGET_03=\"MERGED\"\n+\tEXPECTED_TARGET_04=\"MERGED\"\n+\tEXPECTED_TARGET_05=\"MERGED\"\n+\tEXPECTED_TARGET_06=\"MERGED\"\n+\tEXPECTED_TARGET_07=\"MERGED\"\n+\tEXPECTED_TARGET_08=\"MERGED\"\n+\tEXPECTED_TARGET_09=\"MERGED\"\n+\tEXPECTED_TARGET_10=\"MERGED\"\n+\tEXPECTED_TARGET_11=\"MERGED\"\n+\tEXPECTED_TARGET_12=\"MERGED\"\n+\tEXPECTED_TARGET_13=\"MERGED\"\n+\tEXPECTED_TARGET_14=\"MERGED\"\n+\tEXPECTED_TARGET_15=\"MERGED\"\n+\tEXPECTED_TARGET_16=\"MERGED\"\n+\n+\tat_least_one_ko=\"false\"\n+\n+\tfor i in $(seq -w 1 99)\n+\tdo\n+\t\tif test \"$i\" -gt $NUMBER_OF_TEST_CASES\n+\t\tthen\n+\t\t\tbreak\n+\t\tfi\n+\n+\t\tgen_cmd \"$(eval echo \\${TEST_CASE_\"$i\"})\"\n+\n+\t\tif test \"$FINAL_CMD\" = \"$(eval echo \\${EXPECTED_CMD_\"$i\"})\" \\\n+\t\t\t&& test \"$FINAL_TARGET\" = \"$(eval echo \\${EXPECTED_TARGET_\"$i\"})\"\n+\t\tthen\n+\t\t\tprintf \"Test Case #%02d: OK\\n\" \"$(echo \"$i\" | sed 's/^0*//')\"\n+\t\telse\n+\t\t\tprintf \"Test Case #%02d: KO !!!!\\n\" \"$(echo \"$i\" | sed 's/^0*//')\"\n+\t\t\techo \"  FINAL_CMD              : $FINAL_CMD\"\n+\t\t\techo \"  FINAL_CMD (expected)   : $(eval echo \\${EXPECTED_CMD_\"$i\"})\"\n+\t\t\techo \"  FINAL_TARGET           : $FINAL_TARGET\"\n+\t\t\techo \"  FINAL_TARGET (expected): $(eval echo \\${EXPECTED_TARGET_\"$i\"})\"\n+\t\t\tat_least_one_ko=\"true\"\n+\t\tfi\n+\tdone\n+\t\n+\tif test \"$at_least_one_ko\" = \"true\"\n+\tthen\n+\t\treturn 255\n+\telse\n+\t\treturn 0\n+\tfi\n+}\n-- \n2.35.1\n\n"},{"id":"452430","messageId":"20220327112307.151044-3-greenfoo@u92.eu","threadId":"57623","inReplyTo":"20220327112307.151044-1-greenfoo@u92.eu","subject":"[PATCH v6 2/3] vimdiff: integrate layout tests in the unit tests framework ('t' folder)","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-27T11:23:06Z","receivedAt":"2022-03-27T11:23:28Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Create a new test case file for the different available merge tools.\nRight now it only tests the 'mergetool.vimdiff.layout' option. Other\nmerge tools might be interested in adding their own tests here too.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n t/t7609-mergetool--lib.sh | 15 +++++++++++++++\n 1 file changed, 15 insertions(+)\n create mode 100755 t/t7609-mergetool--lib.sh\n\ndiff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh\nnew file mode 100755\nindex 0000000000..8cfc22e27c\n--- /dev/null\n+++ b/t/t7609-mergetool--lib.sh\n@@ -0,0 +1,15 @@\n+#!/bin/sh\n+\n+test_description='git mergetool\n+\n+Testing basic merge tools options'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '\n+\t. $GIT_BUILD_DIR/mergetools/vimdiff && \n+\trun_unit_tests\n+'\n+\n+test_done\n+\n-- \n2.35.1\n\n"},{"id":"452431","messageId":"20220327112307.151044-1-greenfoo@u92.eu","threadId":"57623","inReplyTo":null,"subject":"[PATCH v6 0/3] vimdiff: new implementation with layout support","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-27T11:23:04Z","receivedAt":"2022-03-27T11:23:33Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Original cover letter (see v6 changes at the end):\n\n---\n\nA few weeks ago I presented this RFC [1] where I introduced a new variant of the\nvimdiff merge tool (\"vimdiff4\") that creates three tabs (instead of just one)\nthat look like this:\n\n    ------------------------------------------\n    | <TAB #1> |  TAB #2  |  TAB #3  |       |\n    ------------------------------------------\n    |             |           |              |\n    |   LOCAL     |   BASE    |   REMOTE     |\n    |             |           |              |   <---- Same information\n    ------------------------------------------         presented by the\n    |                                        |         \"standard\" vimdiff\n    |                MERGED                  |         merge tool\n    |                                        |\n    ------------------------------------------\n    \n    ------------------------------------------\n    |  TAB #1  | <TAB #2> |  TAB #3  |       |\n    ------------------------------------------\n    |                   |                    |\n    |                   |                    |\n    |                   |                    |\n    |     BASE          |    LOCAL           |   <---- Only differences\n    |                   |                    |         between BASE and\n    |                   |                    |         LOCAL are shown\n    |                   |                    |\n    ------------------------------------------\n    \n    ------------------------------------------\n    |  TAB #1  |  TAB #2  | <TAB #3> |       |\n    ------------------------------------------\n    |                   |                    |\n    |                   |                    |\n    |                   |                    |\n    |     BASE          |    REMOTE          |   <---- Only differences\n    |                   |                    |         between BASE and\n    |                   |                    |         REMOTE are shown\n    |                   |                    |\n    ------------------------------------------\n\n\nThe motivation behind this was that, for non-trivial merges, the three way diff\npresented in the first tab tends to be very confusing and in these cases\nindividual diffs between BASE and LOCAL and between BASE and REMOTE are very\nuseful.\n\nI have been using a \"custom\" merge tool for months to achieve this same result\nby adding these lines to my .gitconfig file:\n\n  [mergetool \"supermerge\"]\n        cmd = vim -f -d -c \\\"4wincmd w | wincmd J | tabnew | edit $LOCAL | vertical diffsplit $BASE | tabnew | edit $REMOTE | vertical diffsplit $BASE | 2tabprevious\\\" \\\"$LOCAL\\\" \\\"$BASE\\\" \\\"$REMOTE\\\" \\\"$MERGED\\\"\n        trustExitCode = true\n\n...and, because I found this \"trick\" very useful, I thought it would be a good\nidea to add it as a git built-in merge tool (called \"vimdiff4\" because  1, 2 and\n3 had already been taken) for everyone to use... and that's exactly what the RFC\nI published did.\n\nNow... as you can see in the RFC thread [1], David and Juno suggested that\nmaybe, instead of creating *yet another vimdiff variant*, we should take this\nopportunity to:\n\n  * Come up with a more general way of defining arbitrary vim layouts.\n  \n  * Re-implement \"vimdiff1\", \"vimdiff2\" and \"vimdiff3\" using this new mechanism\n    (after all, the only difference among them is that they present different\n    layouts to the user)\n\n  * Add documentation to all of this.\n\nAnd the result of that work is what I'm presenting today :)\n\nSome things I would like to mention:\n\n  1. There are three commits in this patch series:\n\n     - The first one implements the logic to generate new arbitrary layouts and\n       also re-defines \"vimdiff1\", \"vimdiff2\" and \"vimdiff3\" on top of it.\n\n     - The second one adds documentation. It is probably a good idea to start\n       reviewing this commit before the first one!\n\n     - The last commit *is not meant to be merged now*. It removes \"vimdiff1\",\n       \"vimdiff2\" and \"vimdiff3\", which is something that should only be done\n       after one or two releases with a deprecation notice and only if everyone\n       agrees to do so :)\n\n  2. \"mergetools/vimdiff\" is now a ~800 lines bash script, but most of it is\n     documentation (which is embedded in the tool itself for easier maintenance)\n     and unit tests.\n     I have only tested it with bash, but I've tried not to use any command not\n     already being used somewhere else, so I expect it to work in the same\n     places it was working before (however, let me know if there are some shell\n     compatibility requirements and I'll try to check them).\n\n  3. Regarding unit tests, \"mergetool/vimdiff\" contains instructions on how to\n     run them (just call the script without arguments after making changes, to\n     make sure you didn't break anything).\n     Right now it prints \"OK\" on all test cases (obviously) [2]\n\n  3. The \"git {diff,merge}tool --tool-help\" command now also prints the\n     documentation for each tool (instead of just its name, as before).\n     You can see an example of the output here ([3] and [4])\n\nFinally, let me say that, while I like what this patch series achieves, I would\nalso *completely* understand if you decide not to merge it due to being a\ncomplex solution to a simple problem that can be solved (as I had been doing up\nuntil today) by just adding three lines to one's .gitconfig.\n\n  [mergetool \"supermerge\"]\n        cmd = vim -f -d -c ...(custom complex sequence of vim commands)...\n        trustExitCode = true\n\nLet me know what you think.\n\nThanks.\n\nReferences:\n\n  [1] https://lore.kernel.org/git/20211019212020.25385-1-greenfoo@u92.eu/#r\n  [2] https://pastebin.com/kuQ5pETG\n  [3] https://pastebin.com/yvLWxeiM\n  [4] https://pastebin.com/qNc7qymp\n\n\nNew in v2:\n\n  * Remove deprecation of vimdiff{1,2,3} (they will remain for backwards\n    compatibility, but built on top of the new generic layout mechanism)\n\n  * Remove unnecessary \"IFS=\"\n\n  * Replace DEBUG --> GIT_MERGETOOL_VIMDIFF_DEBUG\n\n  * Stop using \"local\" (turns out it was not necessary)\n\n  * Stop using bash arrays (use arrays of variables instead)\n\n  * Stop using bash substring expansion (use a new \"substring\" function\n    instead).\n\n  * Refactor some of the internal loops to make the code faster. This was needed\n    because the two previous changes (specially the one where I stop using\n    \"substring expansion\") slowed down the script to a point where I had to wait\n    for a few *seconds* before the \"layout\" string was resolved (recursion +\n    bash forks are a recipe for sluggishness). Fortunately we are back to the\n    low hundreds of milliseconds range.\n\n  * Change markers:\n    - File to save: * --> @\n    - New tab     : ; --> +\n    - Vert split  : | --> ,\n    - Horz split  : - --> /\n\n  * Rewrite examples to use as few parenthesis as possible (typically zero)\n    and better explain operators priority.\n\n  * Other fixes to remove problems reported by \"shellcheck --shell=sh\" (which\n    checks syntax agains the POSIX shell spec)\n\n  * Rename \"index_...\" vars to make more obvious what they do.\n\n  * Use \"$\" inside arithmetic expressions $((...))\n    NOTE: \"shellcheck\" issues a warning stating that \"$\" is not needed inside\n    arithmetic expressions.\n\n  * Use \"test -n\" instead of \"! test -z\"\n\n  * Use \"=\" instead of \"==\" in \"test\"\n\n  * Use \"= 0\" instead of \"-eq 0\"\n\n  * Do not use \"eval\" nor \"--\" when copying a file to MERGED\n\n  * Do not use \"-o\" with grep\n\n  * Use <<-\\EOF instead of <<\\ENDOFMESSAGE and remove extra indent in \"here\n    docs\".\n\n  * Also, let me put here some answers to questions made in the replies to\n    version v1 of this patch set:\n\n    > What do backticks do in here?\n    >\n    >     some_var=(\n    >         `# Name`       \"Rick Deckard\"\n    >         `# Age`        \"Unknown\"\n    >         `# Occupation` \"Blade runner\"\n    >     )\n\n    The backticks execute the code inside, which is a comment (everything after\n    a \"#\" is considered a comment by the shell), thus it does nothing.\n\n    The `# ...` trick can be used to insert inline comments in bash. Another\n    example:\n\n        $ ls -l `# long format` -h `# human readable` *.txt\n\n    In any case, as you can see in this new revision, because I'm no longer\n    using bash arrays, this trick to comment each test case is not needed\n    anymore.\n\n    > Why is \"eval\" needed here:\n    >\n    >     eval \"$merge_tool_path\" \\\n    >              -f \"$FINAL_CMD\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n\n    Variable \"$FINAL_CMD\" contains a string that looks like this:\n\n        $ echo $FINAL_CMD\n        -c \"vim cmd 1 | vim cmd 2 | ...\" -c \"tabfirst\"\n\n    We need to call \"vim\" exactly like that, but if we do this...\n\n         $ vim $FINAL_CMD\n\n    ...then \"vim\" will be excev'ed with the following arguments:\n\n        1. -c\n        2. \"vim\n        3. cmd\n        4. 1\n        ...\n\n    ...instead of the desired scenario:\n\n       1. -c\n       2. cmd 1 | cmd 2 | ...\n       3. -c\n       4. tabfirst\n\n     Using \"eval\" fixes this. A shorter example shows how this works:\n\n         $ A=\"1 \\\"2 3\\\"\"\n\n         $ ls $A\n         ls: cannot access '1': No such file or directory\n         ls: cannot access '\"2': No such file or directory\n         ls: cannot access '3\"': No such file or directory\n\n         $ eval ls $A\n         ls: cannot access '1': No such file or directory\n         ls: cannot access '2 3': No such file or directory\n\n  * Finally, I think I have addressed all comments to v1 *except for two\n    things*:\n\n        1. Moving the documentation to \"Documentation/\" instead of having it\n           embedded inside the \"mergetools/vimdiff\" script.\n\n        2. Move unit tests to the \"test suit\"\n\n    For (1) I would like more details. Is the idea not to print any\n    documentation when running \"git mergetool --tool-help\" and have all the\n    details included in \"git help mergetool\" instead?\n    Right now \"git help mergetool\" does not mention any tool specific details\n    and, instead, redirects the user to \"git mergetool --tool-help\" (that's why\n    I originally placed the new documentation there).\n    In any case, all the doc has been placed on its own commit, so once we\n    decide how to proceed its just a matter of reverting it.\n\n    For (2) I still need to investigate how this is done and prepare a \"v3\" if\n    needed :)\n\n\nNew in v3:\n\n  * Rebase on top of latest master\n\n  * Documentation moved to \"Documentation/\". Running \"git mergetool\n    --tool-help\" now works like before (ie. it just lists all available merge\n    tools) except that a one line reference to a \"man\" entry is also printed for\n    those entries providing one (right now, only vimdiff):\n\n        $ git mergetool --tool-help\n        'git mergetool --tool=<tool>' may be set to one of the following:\n                        araxis\n                        meld\n                        vimdiff\n                                Run 'man git-mergetool--vimdiff' for details\n                        vimdiff1\n                                Run 'man git-mergetool--vimdiff' for details\n                        ...\n\n  * New test file \"t/7609-mergetool--lib.sh\" created. Right now it only\n    contains one test which calls \"mergetools/vimdiff\" with a special\n    environment set, causing layout unit tests to run.\n\n\nNew in v4:\n\n  * Rebase on top of latest master\n\n  * Stop using \"$\" inside arithmetic expressions.\n\n  * Remove \"!/bin/bash\" from the top of the \"vimdiff\" script.\n\n  * Update comment explaining how the \"vimdiff\" script can be run.\n\n  * Fix spaces/tabs.\n\n  * Change the way unit tests are run (now the script is directly sourced\n    instead of calling bash)\n\n  * Remove unnecessary \"case/esac\" structure.\n\n  * Fix typo in documentation\n\n\nNew in v5:\n\n  * Rebase on top of latest master\n\n\nNew in v6:\n\n  * Syntax corrections (spaces around parenthesis)\n\n  * Fix layout definition of \"vimdiff1\"\n\n  * Make clear how the old behaviour of the different variants (vimdiffN) is\n    tested in the built in unit tests\n\n  * Move doc into a subsection inside \"git help mergetool\"\n\n\nFernando Ramos (3):\n  vimdiff: new implementation with layout support\n  vimdiff: integrate layout tests in the unit tests framework ('t'\n    folder)\n  vimdiff: add tool documentation\n\n Documentation/config/mergetool.txt   |   5 +\n Documentation/git-mergetool.txt      |   7 +\n Documentation/mergetools/vimdiff.txt | 182 +++++++++\n git-mergetool--lib.sh                |  14 +\n mergetools/vimdiff                   | 553 +++++++++++++++++++++++++--\n t/t7609-mergetool--lib.sh            |  15 +\n 6 files changed, 748 insertions(+), 28 deletions(-)\n create mode 100644 Documentation/mergetools/vimdiff.txt\n create mode 100755 t/t7609-mergetool--lib.sh\n\n-- \n2.35.1\n\n"},{"id":"452432","messageId":"20220327112307.151044-4-greenfoo@u92.eu","threadId":"57623","inReplyTo":"20220327112307.151044-1-greenfoo@u92.eu","subject":"[PATCH v6 3/3] vimdiff: add tool documentation","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-27T11:23:07Z","receivedAt":"2022-03-27T11:23:34Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Running 'git {merge,diff}tool --tool-help' now also prints usage\ninformation about the vimdiff tool (and its variantes) instead of just\nits name.\n\nTwo new functions ('diff_cmd_help()' and 'merge_cmd_help()') have been\nadded to the set of functions that each merge tool (ie. scripts found\ninside \"mergetools/\") can overwrite to provided tool specific\ninformation.\n\nRight now, only 'mergetools/vimdiff' implements these functions, but\nother tools are encouraged to do so in the future, specially if they\ntake configuration options not explained anywhere else (as it is the\ncase with the 'vimdiff' tool and the new 'layout' option)\n\nIn addition, a section has been added to\n\"Documentation/git-mergetool.txt\" to explain the new \"layout\"\nconfiguration option with examples.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n Documentation/config/mergetool.txt   |   5 +\n Documentation/git-mergetool.txt      |   7 ++\n Documentation/mergetools/vimdiff.txt | 182 +++++++++++++++++++++++++++\n git-mergetool--lib.sh                |  14 +++\n mergetools/vimdiff                   |   6 +\n 5 files changed, 214 insertions(+)\n create mode 100644 Documentation/mergetools/vimdiff.txt\n\ndiff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt\nindex cafbbef46a..5973ebd2dc 100644\n--- a/Documentation/config/mergetool.txt\n+++ b/Documentation/config/mergetool.txt\n@@ -45,6 +45,11 @@ mergetool.meld.useAutoMerge::\n \tvalue of `false` avoids using `--auto-merge` altogether, and is the\n \tdefault value.\n \n+mergetool.{n,g,}vimdiff.layout::\n+\tThe vimdiff backend uses this variable to control how its split\n+\twindows look like.  See BACKEND SPECIFIC HINTS section of\n+\tlinkgit:git-mergetool[1] for details.\n+\n mergetool.hideResolved::\n \tDuring a merge Git will automatically resolve as many conflicts as\n \tpossible and write the 'MERGED' file containing conflict markers around\ndiff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt\nindex e587c7763a..6c6aa29c5a 100644\n--- a/Documentation/git-mergetool.txt\n+++ b/Documentation/git-mergetool.txt\n@@ -113,6 +113,13 @@ Setting the `mergetool.keepBackup` configuration variable to `false`\n causes `git mergetool` to automatically remove the backup as files\n are successfully merged.\n \n+BACKEND SPECIFIC HINTS\n+----------------------\n+\n+vimdiff\n+~~~~~~~\n+include::mergetools/vimdiff.txt[]\n+\n GIT\n ---\n Part of the linkgit:git[1] suite\ndiff --git a/Documentation/mergetools/vimdiff.txt b/Documentation/mergetools/vimdiff.txt\nnew file mode 100644\nindex 0000000000..296bc76e98\n--- /dev/null\n+++ b/Documentation/mergetools/vimdiff.txt\n@@ -0,0 +1,182 @@\n+Description\n+^^^^^^^^^^^\n+\n+When specifying `--tool=vimdiff` in `git mergetool` git will open vim with a 4\n+windows layout distributed in the following way:\n+\n+    ------------------------------------------\n+    |             |           |              |\n+    |   LOCAL     |   BASE    |   REMOTE     |\n+    |             |           |              |\n+    ------------------------------------------\n+    |                                        |\n+    |                MERGED                  |\n+    |                                        |\n+    ------------------------------------------\n+\n+\"LOCAL\", \"BASE\" and \"REMOTE\" are read-only buffers showing the contents of the\n+conflicting file in a specific git commit (\"commit you are merging into\",\n+\"common ancestor commit\" and \"commit you are merging from\" respectively)\n+\n+\"MERGED\" is a writable buffer where you have to resolve the conflicts (using the\n+other read-only buffers as a reference). Once you are done, save and exit \"vim\"\n+as usual (\":wq\") or, if you want to abort, exit using \":cq\".\n+\n+Layout configuration\n+^^^^^^^^^^^^^^^^^^^^\n+\n+You can change the windows layout used by vim by setting configuration variable\n+\"mergetool.vimdiff.layout\" which accepts a string where the following separators\n+have special meaning:\n+\n+  - \"+\" is used to \"open a new tab\"\n+  - \",\" is used to \"open a new vertical split\"\n+  - \"/\" is used to \"open a new horizontal split\"\n+  - \"@\" is used to indicate which is the file containing the final version after\n+    solving the conflicts. In not present, \"MERGED\" will be used by default.\n+\n+The precedence of the operators is this one (you can use parenthesis to change\n+it):\n+\n+    @ > + > / > ,\n+\n+Let's see some examples to understand how it works:\n+\n+  * layout = \"(LOCAL,BASE,REMOTE)/MERGED\"\n+\n+    This is exactly the same as the default layout we have already seen.\n+\n+    Note that \"/\" has precedence over \",\" and thus the parenthesis are not\n+    needed in this case. The next layout definition is equivalent:\n+\n+        layout = \"LOCAL,BASE,REMOTE / MERGED\"\n+\n+  * layout = \"LOCAL,MERGED,REMOTE\"\n+\n+    If, for some reason, we are not interested in the \"BASE\" buffer.\n+\n+           ------------------------------------------\n+           |             |           |              |\n+           |             |           |              |\n+           |   LOCAL     |   MERGED  |   REMOTE     |\n+           |             |           |              |\n+           |             |           |              |\n+           ------------------------------------------\n+\n+  * layout = \"MERGED\"\n+\n+    Only the \"MERGED\" buffer will be shown. Note, however, that all the other\n+    ones are still loaded in vim, and you can access them with the \"buffers\"\n+    command. \n+\n+           ------------------------------------------\n+           |                                        |\n+           |                                        |\n+           |                 MERGED                 |\n+           |                                        |\n+           |                                        |\n+           ------------------------------------------\n+\n+  * layout = \"@LOCAL,REMOTE\"\n+\n+    When \"MERGED\" is not present in the layout, you must \"mark\" one of the\n+    buffers with an asterisk. That will become the buffer you need to edit and\n+    save after resolving the conflicts.\n+\n+           ------------------------------------------\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           |     LOCAL         |    REMOTE          |\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           ------------------------------------------\n+\n+  * layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE\"\n+\n+    Three tabs will open: the first one is a copy of the default layout, while\n+    the other two only show the differences between \"BASE\" and \"LOCAL\" and\n+    \"BASE\" and \"REMOTE\" respectively.\n+ \n+           ------------------------------------------\n+           | <TAB #1> |  TAB #2  |  TAB #3  |       |\n+           ------------------------------------------\n+           |             |           |              |\n+           |   LOCAL     |   BASE    |   REMOTE     |\n+           |             |           |              |\n+           ------------------------------------------\n+           |                                        |\n+           |                MERGED                  |\n+           |                                        |\n+           ------------------------------------------\n+\n+           ------------------------------------------\n+           |  TAB #1  | <TAB #2> |  TAB #3  |       |\n+           ------------------------------------------\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           |     BASE          |    LOCAL           |\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           ------------------------------------------\n+\n+           ------------------------------------------\n+           |  TAB #1  |  TAB #2  | <TAB #3> |       |\n+           ------------------------------------------\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           |     BASE          |    REMOTE          |\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           ------------------------------------------\n+\n+  * layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL/BASE/REMOTE),MERGED\"\n+\n+    Same as the previous example, but adds a fourth tab with the same\n+    information as the first tab, with a different layout.\n+ \n+           ---------------------------------------------\n+           |  TAB #1  |  TAB #2  |  TAB #3  | <TAB #4> |\n+           ---------------------------------------------\n+           |       LOCAL         |                     |\n+           |---------------------|                     |\n+           |       BASE          |        MERGED       |\n+           |---------------------|                     |\n+           |       REMOTE        |                     |\n+           ---------------------------------------------\n+\n+    Note how in the third tab definition we need to use parenthesis to make \",\"\n+    have precedence over \"/\".\n+\n+Variants\n+^^^^^^^^\n+\n+Instead of `--tool=vimdiff`, you can also use one of these other variants:\n+\n+  * `--tool=gvimdiff`, to open gvim instead of vim.\n+\n+  * `--tool=nvimdiff`, to open nvim (`neovim`) instead of vim.\n+\n+When using these variants, in order to specify a custom layout you will have to\n+set configuration variables `mergetool.gvimdiff.layout` and\n+`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`\n+\n+In addition, for backwards compatibility with previous git versions, you can\n+also append `1`, `2` or `3` to either `vimdiff` or any of the variants (ex:\n+`vimdiff3`, `nvimdiff1`, etc...) to use a predefined layout.\n+In other words, using `--tool=[g,n,]vimdiffx` is the same as using\n+`--tool=[g,n,]vimdiff` and setting configuration variable\n+`mergetool.[g,n,]vimdiff.layout` to... \n+\n+  * x=1 --> \"@LOCAL, REMOTE\"\n+  * x=2 --> \"LOCAL, MERGED, REMOTE\"\n+  * x=3 --> \"MERGED\"\n+\n+Example: using `--tool=gvimdiff2` will open `gvim` with three columns (LOCAL,\n+MERGED and REMOTE).\n+\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 542a6a75eb..956c276e1d 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -64,6 +64,12 @@ $(list_tool_variants)\"\n \t\t\t\tfi\n \t\t\t\tshown_any=yes\n \t\t\t\tprintf \"%s%s\\n\" \"$per_line_prefix\" \"$toolname\"\n+\n+\t\t\t\t(diff_mode && diff_cmd_help \"$toolname\" || merge_cmd_help \"$toolname\") |\n+\t\t\t\twhile read -r line\n+\t\t\t\tdo\n+\t\t\t\t\tprintf \"%s\\t%s\\n\" \"$per_line_prefix\" \"$line\"\n+\t\t\t\tdone\n \t\t\tfi\n \t\tdone\n \n@@ -162,10 +168,18 @@ setup_tool () {\n \t\treturn 1\n \t}\n \n+\tdiff_cmd_help () {\n+\t\treturn 0\n+\t}\n+\n \tmerge_cmd () {\n \t\treturn 1\n \t}\n \n+\tmerge_cmd_help () {\n+\t\treturn 0\n+\t}\n+\n \thide_resolved_enabled () {\n \t\treturn 0\n \t}\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex e3f442caf3..0380bff302 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -435,6 +435,12 @@ merge_cmd () {\n }\n \n \n+merge_cmd_help () {\n+\techo \"Layout can be customized. Run 'git help mergetool' and check the 'BACKEND SPECIFIC HINTS' section.\"\n+\treturn 0\n+}\n+\n+\n translate_merge_tool_path () {\n \tcase \"$1\" in\n \tnvimdiff*)\n-- \n2.35.1\n\n"},{"id":"452439","messageId":"00463195-5514-bf2b-e733-24e1e24a70cb@gmail.com","threadId":"57623","inReplyTo":"20220327112307.151044-2-greenfoo@u92.eu","subject":"Re: [PATCH v6 1/3] vimdiff: new implementation with layout support","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-27T16:47:57Z","receivedAt":"2022-03-27T16:48:05Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Fernando,\n\nLe 2022-03-27 à 07:23, Fernando Ramos a écrit :\n\n--8<--\n\n> +################################################################################\n> +## Internal functions (not meant to be used outside this script)\n> +################################################################################\n> +\n> +debug_print () { \n> +\t# Send message to stderr if global variable DEBUG is set to \"true\"\n\nThis should also be GIT_MERGETOOL_VIMDIFF_DEBUG, right?\n\n> +\n> +\tif test -n \"$GIT_MERGETOOL_VIMDIFF_DEBUG\"\n> +\tthen\n> +\t\t>&2 echo \"$@\"\n> +\tfi\n> +}\n> +\n\n--8<--\n\n> +gen_cmd () {\n> +\t# This function returns (in global variable FINAL_CMD) the string that\n> +\t# you can use when invoking \"vim\" (as shown next) to obtain a given\n> +\t# layout:\n> +\t#\n> +\t#   $ vim -f $FINAL_CMD \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n> +\t#\n> +\t# It takes one single argument: a string containing the desired layout\n> +\t# definition.\n> +\t#\n> +\t# The syntax of the \"layout definitions\" is explained in ... (TODO)...\n\nIs this still TODO ?\n\n> +\t# but you can already intuitively understand how it works by knowing\n> +\t# that...\n> +\t#\n> +\t#   * \";\" means \"a new vim tab\"\n> +\t#   * \"-\" means \"a new vim horizontal split\"\n> +\t#   * \"|\" means \"a new vim vertical split\"\n> +\t#\n> +\t# It also returns (in global variable FINAL_TARGET) the name (\"LOCAL\",\n> +\t# \"BASE\", \"REMOTE\" or \"MERGED\") of the file that is marked with an \"@\",\n> +\t# or \"MERGED\" if none of them is.\n> +\t#\n> +\t# Example:\n> +\t#\n> +\t#     gen_cmd \"@LOCAL , REMOTE\"\n> +\t#     |\n> +\t#     `-> FINAL_CMD    == \"-c \\\"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n> +\t#         FINAL_TARGET == \"LOCAL\"\n"},{"id":"452440","messageId":"YkCpCJfX/xdp+P7r@zacax395.localdomain","threadId":"57623","inReplyTo":"00463195-5514-bf2b-e733-24e1e24a70cb@gmail.com","subject":"Re: [PATCH v6 1/3] vimdiff: new implementation with layout support","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-27T18:12:24Z","receivedAt":"2022-03-27T18:12:36Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"> > +################################################################################\n> > +## Internal functions (not meant to be used outside this script)\n> > +################################################################################\n> > +\n> > +debug_print () { \n> > +\t# Send message to stderr if global variable DEBUG is set to \"true\"\n> \n> This should also be GIT_MERGETOOL_VIMDIFF_DEBUG, right?\n\nGood catch! I'll fix it in v7.\n\n\n> > +gen_cmd () {\n> > +\t# This function returns (in global variable FINAL_CMD) the string that\n> > +\t# you can use when invoking \"vim\" (as shown next) to obtain a given\n> > +\t# layout:\n> > +\t#\n> > +\t#   $ vim -f $FINAL_CMD \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n> > +\t#\n> > +\t# It takes one single argument: a string containing the desired layout\n> > +\t# definition.\n> > +\t#\n> > +\t# The syntax of the \"layout definitions\" is explained in ... (TODO)...\n> \n> Is this still TODO ?\n\nNo. I need to point to \"Documentation/mergetools/vimdiff.txt\".\n\nI also noticed that the next paragraph was also not updated after the delimiters\nwere changed (from \";\", \"-\" and \"|\" to \"+\", \"/\" and \",\").\n\nI'll fix both issues in v7.\n\nThanks!\n"},{"id":"452441","messageId":"001d3ecd-e1bd-39f4-5123-4a8b1bd1b5a8@gmail.com","threadId":"57623","inReplyTo":"20220327112307.151044-4-greenfoo@u92.eu","subject":"Re: [PATCH v6 3/3] vimdiff: add tool documentation","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-27T18:28:23Z","receivedAt":"2022-03-27T18:32:20Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Fernando,\n\nLe 2022-03-27 à 07:23, Fernando Ramos a écrit :\n> Running 'git {merge,diff}tool --tool-help' now also prints usage\n> information about the vimdiff tool (and its variantes) instead of just\n> its name.\n> \n> Two new functions ('diff_cmd_help()' and 'merge_cmd_help()') have been\n> added to the set of functions that each merge tool (ie. scripts found\n> inside \"mergetools/\") can overwrite to provided tool specific\n> information.\n> \n> Right now, only 'mergetools/vimdiff' implements these functions, but\n> other tools are encouraged to do so in the future, specially if they\n> take configuration options not explained anywhere else (as it is the\n> case with the 'vimdiff' tool and the new 'layout' option)\n\nThis is a very nice addition, which should help new users understanding\nwhat these merge tools are. I remember myself looking for executables\nname 'vimdiff2' or 'vimdiff3' on my system and not finding them :)\n\n> \n> In addition, a section has been added to\n> \"Documentation/git-mergetool.txt\" to explain the new \"layout\"\n> configuration option with examples.\n> \n> Signed-off-by: Fernando Ramos <greenfoo@u92.eu>\n> ---\n>  Documentation/config/mergetool.txt   |   5 +\n>  Documentation/git-mergetool.txt      |   7 ++\n>  Documentation/mergetools/vimdiff.txt | 182 +++++++++++++++++++++++++++\n>  git-mergetool--lib.sh                |  14 +++\n>  mergetools/vimdiff                   |   6 +\n>  5 files changed, 214 insertions(+)\n>  create mode 100644 Documentation/mergetools/vimdiff.txt\n> \n> diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt\n> index cafbbef46a..5973ebd2dc 100644\n> --- a/Documentation/config/mergetool.txt\n> +++ b/Documentation/config/mergetool.txt\n> @@ -45,6 +45,11 @@ mergetool.meld.useAutoMerge::\n>  \tvalue of `false` avoids using `--auto-merge` altogether, and is the\n>  \tdefault value.\n>  \n> +mergetool.{n,g,}vimdiff.layout::\n> +\tThe vimdiff backend uses this variable to control how its split\n> +\twindows look like.  See BACKEND SPECIFIC HINTS section of\n> +\tlinkgit:git-mergetool[1] for details.\n> +\n\nI generated the man page for 'git-mergetool' and this bit is included in the \nConfiguration section, that's great. However, it feels a little weird to read\n\"see BACKEND SPECIFIC HINTS section of linkgit:git-mergetool[1]\" there, since\nthat's the help page I'm already reading. So maybe it would be nice to use an\nAsciidoc 'ifndef::git-mergetool[]' directive here to hide the \"of linkgit:git-mergetool[1]\"\nbit if the current page is git-mergetool[1] ?\n\n>  mergetool.hideResolved::\n>  \tDuring a merge Git will automatically resolve as many conflicts as\n>  \tpossible and write the 'MERGED' file containing conflict markers around\n> diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt\n> index e587c7763a..6c6aa29c5a 100644\n> --- a/Documentation/git-mergetool.txt\n> +++ b/Documentation/git-mergetool.txt\n> @@ -113,6 +113,13 @@ Setting the `mergetool.keepBackup` configuration variable to `false`\n>  causes `git mergetool` to automatically remove the backup as files\n>  are successfully merged.\n>  \n> +BACKEND SPECIFIC HINTS\n> +----------------------\n> +\n> +vimdiff\n> +~~~~~~~\n> +include::mergetools/vimdiff.txt[]\n> +\n>  GIT\n>  ---\n>  Part of the linkgit:git[1] suite\n> diff --git a/Documentation/mergetools/vimdiff.txt b/Documentation/mergetools/vimdiff.txt\n> new file mode 100644\n> index 0000000000..296bc76e98\n> --- /dev/null\n> +++ b/Documentation/mergetools/vimdiff.txt\n> @@ -0,0 +1,182 @@\n> +Description\n> +^^^^^^^^^^^\n> +\n> +When specifying `--tool=vimdiff` in `git mergetool` git will open vim with a 4\n\ns/git/Git/, s/vim/Vim/  (here and below) ?\n\n> +windows layout distributed in the following way:\n> +\n> +    ------------------------------------------\n> +    |             |           |              |\n> +    |   LOCAL     |   BASE    |   REMOTE     |\n> +    |             |           |              |\n> +    ------------------------------------------\n> +    |                                        |\n> +    |                MERGED                  |\n> +    |                                        |\n> +    ------------------------------------------\n> +\n> +\"LOCAL\", \"BASE\" and \"REMOTE\" are read-only buffers showing the contents of the\n> +conflicting file in a specific git commit \n\n\"in specific commits\" would read sightly better, I think.\n\n> (\"commit you are merging into\",\n> +\"common ancestor commit\" and \"commit you are merging from\" respectively)\n> +\n> +\"MERGED\" is a writable buffer where you have to resolve the conflicts (using the\n> +other read-only buffers as a reference). Once you are done, save and exit \"vim\"\n> +as usual (\":wq\") or, if you want to abort, exit using \":cq\".\n> +\n> +Layout configuration\n> +^^^^^^^^^^^^^^^^^^^^\n> +\n> +You can change the windows layout used by vim by setting configuration variable\n> +\"mergetool.vimdiff.layout\"\n\nwe prefer backticks for configuration variables: `mergetool.vimdiff.layout`\n\n which accepts a string where the following separators\n> +have special meaning:\n> +\n> +  - \"+\" is used to \"open a new tab\"\n> +  - \",\" is used to \"open a new vertical split\"\n> +  - \"/\" is used to \"open a new horizontal split\"\n> +  - \"@\" is used to indicate which is the file containing the final version after\n> +    solving the conflicts. In not present, \"MERGED\" will be used by default.\n\ns/In/If/\n\nAlso, I would use backticks instead of double quotes for the separator:\n\n  - `+` is used to \"open a new tab\"\n\netc.\n\n> +The precedence of the operators is this one (you can use parenthesis \n\nparentheses\n\n> to change\n> +it):\n> +\n> +    @ > + > / > ,\n> +\n\nI think it would be slightly better for the separators to be individually formatted, \nlike this:\n\n`@` > `+` > `/` > `,`\n\nthis way the angle brackets are typefaced differently (at least in HTML).\n\n> +Let's see some examples to understand how it works:\n> +\n> +  * layout = \"(LOCAL,BASE,REMOTE)/MERGED\"\n> +\n> +    This is exactly the same as the default layout we have already seen.\n> +\n> +    Note that \"/\" has precedence over \",\" and thus the parenthesis are not\n> +    needed in this case. The next layout definition is equivalent:\n> +\n> +        layout = \"LOCAL,BASE,REMOTE / MERGED\"\n> +\n> +  * layout = \"LOCAL,MERGED,REMOTE\"\n> +\n> +    If, for some reason, we are not interested in the \"BASE\" buffer.\n> +\n> +           ------------------------------------------\n> +           |             |           |              |\n> +           |             |           |              |\n> +           |   LOCAL     |   MERGED  |   REMOTE     |\n> +           |             |           |              |\n> +           |             |           |              |\n> +           ------------------------------------------\n> +\n> +  * layout = \"MERGED\"\n> +\n> +    Only the \"MERGED\" buffer will be shown. Note, however, that all the other\n> +    ones are still loaded in vim, and you can access them with the \"buffers\"\n> +    command. \n> +\n> +           ------------------------------------------\n> +           |                                        |\n> +           |                                        |\n> +           |                 MERGED                 |\n> +           |                                        |\n> +           |                                        |\n> +           ------------------------------------------\n> +\n> +  * layout = \"@LOCAL,REMOTE\"\n> +\n> +    When \"MERGED\" is not present in the layout, you must \"mark\" one of the\n> +    buffers with an asterisk. That will become the buffer you need to edit and\n> +    save after resolving the conflicts.\n> +\n> +           ------------------------------------------\n> +           |                   |                    |\n> +           |                   |                    |\n> +           |                   |                    |\n> +           |     LOCAL         |    REMOTE          |\n> +           |                   |                    |\n> +           |                   |                    |\n> +           |                   |                    |\n> +           ------------------------------------------\n> +\n> +  * layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE\"\n> +\n> +    Three tabs will open: the first one is a copy of the default layout, while\n> +    the other two only show the differences between \"BASE\" and \"LOCAL\" and\n> +    \"BASE\" and \"REMOTE\" respectively.\n> + \n> +           ------------------------------------------\n> +           | <TAB #1> |  TAB #2  |  TAB #3  |       |\n> +           ------------------------------------------\n> +           |             |           |              |\n> +           |   LOCAL     |   BASE    |   REMOTE     |\n> +           |             |           |              |\n> +           ------------------------------------------\n> +           |                                        |\n> +           |                MERGED                  |\n> +           |                                        |\n> +           ------------------------------------------\n> +\n> +           ------------------------------------------\n> +           |  TAB #1  | <TAB #2> |  TAB #3  |       |\n> +           ------------------------------------------\n> +           |                   |                    |\n> +           |                   |                    |\n> +           |                   |                    |\n> +           |     BASE          |    LOCAL           |\n> +           |                   |                    |\n> +           |                   |                    |\n> +           |                   |                    |\n> +           ------------------------------------------\n> +\n> +           ------------------------------------------\n> +           |  TAB #1  |  TAB #2  | <TAB #3> |       |\n> +           ------------------------------------------\n> +           |                   |                    |\n> +           |                   |                    |\n> +           |                   |                    |\n> +           |     BASE          |    REMOTE          |\n> +           |                   |                    |\n> +           |                   |                    |\n> +           |                   |                    |\n> +           ------------------------------------------\n> +\n> +  * layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL/BASE/REMOTE),MERGED\"\n> +\n> +    Same as the previous example, but adds a fourth tab with the same\n> +    information as the first tab, with a different layout.\n> + \n> +           ---------------------------------------------\n> +           |  TAB #1  |  TAB #2  |  TAB #3  | <TAB #4> |\n> +           ---------------------------------------------\n> +           |       LOCAL         |                     |\n> +           |---------------------|                     |\n> +           |       BASE          |        MERGED       |\n> +           |---------------------|                     |\n> +           |       REMOTE        |                     |\n> +           ---------------------------------------------\n> +\n> +    Note how in the third tab definition we need to use parenthesis to make \",\"\n> +    have precedence over \"/\".\n> +\n\nThis whole section above needs some indentation work to format nicely in Asciidoc/\nAsciidoctor. I've fixed it and will send a 'fixup' patch as a reply.\n\n> +Variants\n> +^^^^^^^^\n> +\n> +Instead of `--tool=vimdiff`, you can also use one of these other variants:\n> +\n> +  * `--tool=gvimdiff`, to open gvim instead of vim.\n> +\n> +  * `--tool=nvimdiff`, to open nvim (`neovim`) instead of vim.\n> +\n> +When using these variants, in order to specify a custom layout you will have to\n> +set configuration variables `mergetool.gvimdiff.layout` and\n> +`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`\n> +\n> +In addition, for backwards compatibility with previous git versions,> you can\n> +also append `1`, `2` or `3` to either `vimdiff` or any of the variants (ex:\n> +`vimdiff3`, `nvimdiff1`, etc...) to use a predefined layout.\n> +In other words, using `--tool=[g,n,]vimdiffx` is the same as using\n> +`--tool=[g,n,]vimdiff` and setting configuration variable\n> +`mergetool.[g,n,]vimdiff.layout` to... \n> +\n> +  * x=1 --> \"@LOCAL, REMOTE\"\n> +  * x=2 --> \"LOCAL, MERGED, REMOTE\"\n> +  * x=3 --> \"MERGED\"\n\nThis '-->' arrow also causes trouble with Asciidoc's HTML generator. I've also\nfixed it in the patch I'll send as a reply.\n\n> +\n> +Example: using `--tool=gvimdiff2` will open `gvim` with three columns (LOCAL,\n> +MERGED and REMOTE).\n> +\n> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\n> index 542a6a75eb..956c276e1d 100644\n> --- a/git-mergetool--lib.sh\n> +++ b/git-mergetool--lib.sh\n> @@ -64,6 +64,12 @@ $(list_tool_variants)\"\n>  \t\t\t\tfi\n>  \t\t\t\tshown_any=yes\n>  \t\t\t\tprintf \"%s%s\\n\" \"$per_line_prefix\" \"$toolname\"\n> +\n> +\t\t\t\t(diff_mode && diff_cmd_help \"$toolname\" || merge_cmd_help \"$toolname\") |\n> +\t\t\t\twhile read -r line\n> +\t\t\t\tdo\n> +\t\t\t\t\tprintf \"%s\\t%s\\n\" \"$per_line_prefix\" \"$line\"\n> +\t\t\t\tdone\n>  \t\t\tfi\n>  \t\tdone\n>  \n\nI've tried the option and it gives something like this:\n\n$ ./bin-wrappers/git mergetool --tool-help\n'git mergetool --tool=<tool>' may be set to one of the following:\n\t\temerge\n\t\topendiff\n\t\tvimdiff\n\t\t\tLayout can be customized. Run 'git help mergetool' and check the 'BACKEND SPECIFIC HINTS' section.\n\t\tvimdiff1\n\t\t\tLayout can be customized. Run 'git help mergetool' and check the 'BACKEND SPECIFIC HINTS' section.\n\t\t# etc.\n\nThis is OK, but adds a lot of lines to the output. Maybe we could display the help\non the same line ? Something like:\n\n$ ./bin-wrappers/git mergetool --tool-help\n'git mergetool --tool=<tool>' may be set to one of the following:\n\t\temerge\n\t\topendiff\n\t\tvimdiff\t\tLayout can be customized. Run 'git help mergetool' and check the 'BACKEND SPECIFIC HINTS' section.\n\t\tvimdiff1\tLayout can be customized. Run 'git help mergetool' and check the 'BACKEND SPECIFIC HINTS' section.\n\t\t# etc.\n\n> diff --git a/mergetools/vimdiff b/mergetools/vimdiff\n> index e3f442caf3..0380bff302 100644\n> --- a/mergetools/vimdiff\n> +++ b/mergetools/vimdiff\n> @@ -435,6 +435,12 @@ merge_cmd () {\n>  }\n>  \n>  \n> +merge_cmd_help () {\n> +\techo \"Layout can be customized. Run 'git help mergetool' and check the 'BACKEND SPECIFIC HINTS' section.\"\n> +\treturn 0\n> +}\n> +\n> +\n\nMaybe a simple \"Use Vim. \" before \"Layout can be customized.\" would \nbe nice, as then other tools whose names in 'git mergetool' are not \ndirectly related to the executable named could then be listed similarly:\n\n$ ./bin-wrappers/git mergetool --tool-help\n'git mergetool --tool=<tool>' may be set to one of the following:\n\t\temerge\t\tUse Emacs' Emerge.\n\t\topendiff\tUse FileMerge.\n\t\tvimdiff\t\tUse Vim. Layout can be customized. Run 'git help mergetool' and check the 'BACKEND SPECIFIC HINTS' section.\n\t\tvimdiff1\tUse Vim. Layout can be customized. Run 'git help mergetool' and check the 'BACKEND SPECIFIC HINTS' section.\n\t\t# etc.\n"},{"id":"452442","messageId":"20220327185044.20781-1-levraiphilippeblain@gmail.com","threadId":"57623","inReplyTo":"001d3ecd-e1bd-39f4-5123-4a8b1bd1b5a8@gmail.com","subject":"[PATCH] fixup! vimdiff: add tool documentation","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-27T18:50:44Z","receivedAt":"2022-03-27T18:50:52Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"- Use Asciidoc's syntax for \"list continuation\" and \"open block\" [1]\n- Remove '-->' which mixes up the parser\n\n[1] https://docs.asciidoctor.org/asciidoc/latest/lists/continuation/#list-continuation\n\nSigned-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n---\n Documentation/mergetools/vimdiff.txt | 81 +++++++++++++++-------------\n 1 file changed, 44 insertions(+), 37 deletions(-)\n\ndiff --git a/Documentation/mergetools/vimdiff.txt b/Documentation/mergetools/vimdiff.txt\nindex 296bc76e98..1017527e7d 100644\n--- a/Documentation/mergetools/vimdiff.txt\n+++ b/Documentation/mergetools/vimdiff.txt\n@@ -42,18 +42,20 @@ it):\n \n Let's see some examples to understand how it works:\n \n-  * layout = \"(LOCAL,BASE,REMOTE)/MERGED\"\n+* `layout = \"(LOCAL,BASE,REMOTE)/MERGED\"`\n++\n+--\n+This is exactly the same as the default layout we have already seen.\n \n-    This is exactly the same as the default layout we have already seen.\n-\n-    Note that \"/\" has precedence over \",\" and thus the parenthesis are not\n-    needed in this case. The next layout definition is equivalent:\n+Note that \"/\" has precedence over \",\" and thus the parenthesis are not\n+needed in this case. The next layout definition is equivalent:\n \n         layout = \"LOCAL,BASE,REMOTE / MERGED\"\n-\n-  * layout = \"LOCAL,MERGED,REMOTE\"\n-\n-    If, for some reason, we are not interested in the \"BASE\" buffer.\n+--\n+* `layout = \"LOCAL,MERGED,REMOTE\"`\n++\n+--\n+If, for some reason, we are not interested in the \"BASE\" buffer.\n \n            ------------------------------------------\n            |             |           |              |\n@@ -62,12 +64,13 @@ Let's see some examples to understand how it works:\n            |             |           |              |\n            |             |           |              |\n            ------------------------------------------\n-\n-  * layout = \"MERGED\"\n-\n-    Only the \"MERGED\" buffer will be shown. Note, however, that all the other\n-    ones are still loaded in vim, and you can access them with the \"buffers\"\n-    command. \n+--\n+* `layout = \"MERGED\"`\n++\n+--\n+Only the \"MERGED\" buffer will be shown. Note, however, that all the other\n+ones are still loaded in vim, and you can access them with the \"buffers\"\n+command.\n \n            ------------------------------------------\n            |                                        |\n@@ -76,12 +79,13 @@ Let's see some examples to understand how it works:\n            |                                        |\n            |                                        |\n            ------------------------------------------\n-\n-  * layout = \"@LOCAL,REMOTE\"\n-\n-    When \"MERGED\" is not present in the layout, you must \"mark\" one of the\n-    buffers with an asterisk. That will become the buffer you need to edit and\n-    save after resolving the conflicts.\n+--\n+* `layout = \"@LOCAL,REMOTE\"`\n++\n+--\n+When \"MERGED\" is not present in the layout, you must \"mark\" one of the\n+buffers with an asterisk. That will become the buffer you need to edit and\n+save after resolving the conflicts.\n \n            ------------------------------------------\n            |                   |                    |\n@@ -92,12 +96,13 @@ Let's see some examples to understand how it works:\n            |                   |                    |\n            |                   |                    |\n            ------------------------------------------\n-\n-  * layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE\"\n-\n-    Three tabs will open: the first one is a copy of the default layout, while\n-    the other two only show the differences between \"BASE\" and \"LOCAL\" and\n-    \"BASE\" and \"REMOTE\" respectively.\n+--\n+* `layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE\"`\n++\n+--\n+Three tabs will open: the first one is a copy of the default layout, while\n+the other two only show the differences between \"BASE\" and \"LOCAL\" and\n+\"BASE\" and \"REMOTE\" respectively.\n  \n            ------------------------------------------\n            | <TAB #1> |  TAB #2  |  TAB #3  |       |\n@@ -134,11 +139,12 @@ Let's see some examples to understand how it works:\n            |                   |                    |\n            |                   |                    |\n            ------------------------------------------\n-\n-  * layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL/BASE/REMOTE),MERGED\"\n-\n-    Same as the previous example, but adds a fourth tab with the same\n-    information as the first tab, with a different layout.\n+--\n+* `layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL/BASE/REMOTE),MERGED\"`\n++\n+--\n+Same as the previous example, but adds a fourth tab with the same\n+information as the first tab, with a different layout.\n  \n            ---------------------------------------------\n            |  TAB #1  |  TAB #2  |  TAB #3  | <TAB #4> |\n@@ -150,8 +156,9 @@ Let's see some examples to understand how it works:\n            |       REMOTE        |                     |\n            ---------------------------------------------\n \n-    Note how in the third tab definition we need to use parenthesis to make \",\"\n-    have precedence over \"/\".\n+Note how in the third tab definition we need to use parenthesis to make \",\"\n+have precedence over \"/\".\n+--\n \n Variants\n ^^^^^^^^\n@@ -173,9 +180,9 @@ In other words, using `--tool=[g,n,]vimdiffx` is the same as using\n `--tool=[g,n,]vimdiff` and setting configuration variable\n `mergetool.[g,n,]vimdiff.layout` to... \n \n-  * x=1 --> \"@LOCAL, REMOTE\"\n-  * x=2 --> \"LOCAL, MERGED, REMOTE\"\n-  * x=3 --> \"MERGED\"\n+  * `x=1`: `\"@LOCAL, REMOTE\"`\n+  * `x=2`: `\"LOCAL, MERGED, REMOTE\"`\n+  * `x=3`: `\"MERGED\"`\n \n Example: using `--tool=gvimdiff2` will open `gvim` with three columns (LOCAL,\n MERGED and REMOTE).\n-- \n2.29.2\n\n"},{"id":"452443","messageId":"YkDS3CJEPYpzRoVG@zacax395.localdomain","threadId":"57623","inReplyTo":"001d3ecd-e1bd-39f4-5123-4a8b1bd1b5a8@gmail.com","subject":"Re: [PATCH v6 3/3] vimdiff: add tool documentation","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-27T21:10:52Z","receivedAt":"2022-03-27T21:11:04Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"> > +mergetool.{n,g,}vimdiff.layout::\n> > +\tThe vimdiff backend uses this variable to control how its split\n> > +\twindows look like.  See BACKEND SPECIFIC HINTS section of\n> > +\tlinkgit:git-mergetool[1] for details.\n> > +\n> \n> I generated the man page for 'git-mergetool' and this bit is included in the \n> Configuration section, that's great. However, it feels a little weird to read\n> \"see BACKEND SPECIFIC HINTS section of linkgit:git-mergetool[1]\" there, since\n> that's the help page I'm already reading. So maybe it would be nice to use an\n> Asciidoc 'ifndef::git-mergetool[]' directive here to hide the \"of linkgit:git-mergetool[1]\"\n> bit if the current page is git-mergetool[1] ?\n\nGood call. I tried this:\n\n    mergetool.{n,g,}vimdiff.layout::\n    \tThe vimdiff backend uses this variable to control how its split\n    \twindows look like.  See BACKEND SPECIFIC HINTS section\n    ifndef::git-mergetool[] \n    \t(on linkgit:git-mergetool[1])\n    endif::[]\n    \tfor details.\n\n...does it look good?\n\nI'm asking because I ran \"make doc\" and the generated man page always contains\nthe extra piece. When are those asciidoc directives processed? Should two\nversions of the same man page be generated?\n\n\n> This whole section above needs some indentation work to format nicely in Asciidoc/\n> Asciidoctor. I've fixed it and will send a 'fixup' patch as a reply.\n\nThanks! I will include your patch in v7\n\n\n> This is OK, but adds a lot of lines to the output. Maybe we could display the help\n> on the same line ? Something like:\n> \n> $ ./bin-wrappers/git mergetool --tool-help\n> 'git mergetool --tool=<tool>' may be set to one of the following:\n> \t\temerge\n> \t\topendiff\n> \t\tvimdiff\t\tLayout can be customized. Run 'git help mergetool' and check the 'BACKEND SPECIFIC HINTS' section.\n> \t\tvimdiff1\tLayout can be customized. Run 'git help mergetool' and check the 'BACKEND SPECIFIC HINTS' section.\n> \t\t# etc.\n\nYes. It looks nicer in one line. In addition, right now it doesn't offer enough\ninformation to figure out the difference among variants (vimdiff vs vimdiff1 vs\n...) that's why I'm going to update v7 to print something like this following\nyour advice:\n\n    $ ./bin-wrappers/git mergetool --tool-help\n    'git mergetool --tool=<tool>' may be set to one of the following:\n                    araxis\n                    meld\n                    vimdiff    Use Vim with a custom layout (see `git help mergetool`'s `BACKEND SPECIFIC HINTS` section).\n                    vimdiff1   Use Vim with a 2 panes layout (LOCAL and REMOTE)\n                    vimdiff2   Use Vim with a 3 panes layout (LOCAL, MERGED and REMOTE)\n                    vimdiff3   Use Vim where only the MERGED file is shown\n                    ...\n\n"},{"id":"452444","messageId":"xmqqv8vz5b86.fsf@gitster.g","threadId":"57623","inReplyTo":"20220327112307.151044-2-greenfoo@u92.eu","subject":"Re: [PATCH v6 1/3] vimdiff: new implementation with layout support","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-27T21:36:41Z","receivedAt":"2022-03-27T21:36:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I see these from \"git apply\".\n\n<stdin>:102: trailing whitespace.\ndebug_print () { \n<stdin>:114: trailing whitespace.\n\t# \n<stdin>:132: trailing whitespace.\n\tLAYOUT=$1 \n<stdin>:133: trailing whitespace.\n\tCMD=$2  # This is a second (hidden) argument used for recursion  \n<stdin>:159: trailing whitespace.\n\t#   - AFTER :  ( LOCAL , BASE ) / MERGED \n"},{"id":"452445","messageId":"xmqqr16n5b75.fsf@gitster.g","threadId":"57623","inReplyTo":"20220327112307.151044-3-greenfoo@u92.eu","subject":"Re: [PATCH v6 2/3] vimdiff: integrate layout tests in the unit tests framework ('t' folder)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-27T21:37:18Z","receivedAt":"2022-03-27T21:37:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Fernando Ramos <greenfoo@u92.eu> writes:\n\n> Create a new test case file for the different available merge tools.\n> Right now it only tests the 'mergetool.vimdiff.layout' option. Other\n> merge tools might be interested in adding their own tests here too.\n>\n> Signed-off-by: Fernando Ramos <greenfoo@u92.eu>\n> ---\n\n.git/rebase-apply/patch:21: trailing whitespace.\n\t. $GIT_BUILD_DIR/mergetools/vimdiff && \n.git/rebase-apply/patch:26: new blank line at EOF.\n+\n"},{"id":"452446","messageId":"xmqqmthb5aw8.fsf@gitster.g","threadId":"57623","inReplyTo":"YkDS3CJEPYpzRoVG@zacax395.localdomain","subject":"Re: [PATCH v6 3/3] vimdiff: add tool documentation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-27T21:43:51Z","receivedAt":"2022-03-27T21:43:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Fernando Ramos <greenfoo@u92.eu> writes:\n\n> Good call. I tried this:\n>\n>     mergetool.{n,g,}vimdiff.layout::\n\nIt is not like we have infinite variants of these.  Spelling them\nout like\n\n\tmergetool.vimdiff.layout::\n\tmergetool.gvimdiff.layout::\n\tmergetool.nvimdiff.layout::\n\nwould probably be a better idea.\n\n\n>     \tThe vimdiff backend uses this variable to control how its split\n>     \twindows look like.  See BACKEND SPECIFIC HINTS section\n>     ifndef::git-mergetool[] \n>     \t(on linkgit:git-mergetool[1])\n>     endif::[]\n>     \tfor details.\n>\n> ...does it look good?\n>\n> I'm asking because I ran \"make doc\" and the generated man page always contains\n> the extra piece. When are those asciidoc directives processed? Should two\n> versions of the same man page be generated?\n\nAre you signalling the above part that it is (or isn't) included in\ngit-mergetool.txt by defining\n\n\t:git-mergetool: 1\n\nbefore the piece gets included with\n\n\tinclude::config/mergetool.txt\n\nSee for example how git-rev-list.txt tweaks what gets included from\nrev-list-description.txt by doing:\n\n    'git rev-list' [<options>] <commit>... [[--] <path>...]\n\n    DESCRIPTION\n    -----------\n\n    :git-rev-list: 1\n    include::rev-list-description.txt[]\n\n    'rev-list' is a very essential Git command, since it\n\n"},{"id":"452447","messageId":"YkDijfPgoiVObrFD@zacax395.localdomain","threadId":"57623","inReplyTo":"xmqqmthb5aw8.fsf@gitster.g","subject":"Re: [PATCH v6 3/3] vimdiff: add tool documentation","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-27T22:17:49Z","receivedAt":"2022-03-27T22:18:00Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"> Are you signalling the above part that it is (or isn't) included in\n> git-mergetool.txt by defining\n> \n> \t:git-mergetool: 1\n> \n> before the piece gets included with\n> \n> \tinclude::config/mergetool.txt\n> \n> See for example how git-rev-list.txt tweaks what gets included from\n> rev-list-description.txt by doing:\n> \n>     'git rev-list' [<options>] <commit>... [[--] <path>...]\n> \n>     DESCRIPTION\n>     -----------\n> \n>     :git-rev-list: 1\n>     include::rev-list-description.txt[]\n> \n>     'rev-list' is a very essential Git command, since it\n> \n\nThanks for the hint. It is now working as expected. I'll include the fix in v7\ntogether with the other fixes that prevent `git apply` from executing cleanly.\n"},{"id":"452450","messageId":"2d1b3c6d-4345-8b7d-b8b8-4baf1edd91f0@gmail.com","threadId":"57623","inReplyTo":"20220327112307.151044-4-greenfoo@u92.eu","subject":"Re: [PATCH v6 3/3] vimdiff: add tool documentation","fromName":"Bagas Sanjaya","fromEmail":"bagasdotme@gmail.com","sentAt":"2022-03-28T04:48:08Z","receivedAt":"2022-03-28T04:48:19Z","isPatch":true,"sender":{"key":"bagasdotme@gmail.com","avatar":"https://avatars.githubusercontent.com/u/40219486?v=4"},"body":"On 27/03/22 18.23, Fernando Ramos wrote:\n> +When using these variants, in order to specify a custom layout you will have to\n> +set configuration variables `mergetool.gvimdiff.layout` and\n> +`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`\n> +\n\nWhat about this wording?\n\n\"These variants also have corresponding layout configuration named\n  `mergetool.gvimdiff.layout` and `mergetool.nvimdiff.layout`, respectively.\"\n\n-- \nAn old man doll... just what I always wanted! - Clara\n"},{"id":"452452","messageId":"xmqqbkxq639i.fsf@gitster.g","threadId":"57623","inReplyTo":"2d1b3c6d-4345-8b7d-b8b8-4baf1edd91f0@gmail.com","subject":"Re: [PATCH v6 3/3] vimdiff: add tool documentation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-28T05:43:21Z","receivedAt":"2022-03-28T05:43:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Bagas Sanjaya <bagasdotme@gmail.com> writes:\n\n> On 27/03/22 18.23, Fernando Ramos wrote:\n>> +When using these variants, in order to specify a custom layout you will have to\n>> +set configuration variables `mergetool.gvimdiff.layout` and\n>> +`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`\n>> +\n>\n> What about this wording?\n>\n> \"These variants also have corresponding layout configuration named\n>  `mergetool.gvimdiff.layout` and `mergetool.nvimdiff.layout`, respectively.\"\n\nHmph.  The wording aside, is it a good design that you have to set\ngvimdiff.layout if you use gvim and your setting to vimdiff.layout\nhas no effect when you are using nvim or gvim?\n\nWhat is the reason why a user may want to specify them separately?\n\n * I want to use this layout when using plain vim but gvim is so\n   different that I want to use a different one from usability's\n   point of view.\n\n * The layout I want to use with plain vim, when fed to gvim or\n   nvim, would totally make them misbehave.  I cannot reuse the same\n   layout even if I wanted to.\n\n * Depending on the kind of conflict I deal with, I want to use\n   different layouts, but there is no easy mechanism to choose\n   between multiple values I give to mergetool.vimdiff.layout, so I\n   use one layout for vimdiff and another for gvimdiff, and\n   depending on the layout I want to use, I switch between vimdiff\n   and gvimdiff.\n\n * Something else?\n\nIf on the other hand, a user may want to stick to a single layout no\nmatter which variant of vim is used, it may make more sense to just\nuse a single mergetool.vimdiff.layout across all the different\nvariants of vim implementations, and possibly, have their own one\noverride the most generic \"vimdiff\" one.  E.g. gvimdiff would use\nmergetool.gvimdiff.layout if exists, or mergetool.vimdiff.layout\notherwise.\n\nI dunno.\n"},{"id":"452501","messageId":"YkIKV7aqKpvBCFvN@zacax395.localdomain","threadId":"57623","inReplyTo":"xmqqbkxq639i.fsf@gitster.g","subject":"Re: [PATCH v6 3/3] vimdiff: add tool documentation","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-28T19:19:51Z","receivedAt":"2022-03-28T19:20:02Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"> What is the reason why a user may want to specify them separately?\n> \n>  * I want to use this layout when using plain vim but gvim is so\n>    different that I want to use a different one from usability's\n>    point of view.\n> \n>  * The layout I want to use with plain vim, when fed to gvim or\n>    nvim, would totally make them misbehave.  I cannot reuse the same\n>    layout even if I wanted to.\n> \n>  * Depending on the kind of conflict I deal with, I want to use\n>    different layouts, but there is no easy mechanism to choose\n>    between multiple values I give to mergetool.vimdiff.layout, so I\n>    use one layout for vimdiff and another for gvimdiff, and\n>    depending on the layout I want to use, I switch between vimdiff\n>    and gvimdiff.\n> \n>  * Something else?\n> \n> If on the other hand, a user may want to stick to a single layout no\n> matter which variant of vim is used, it may make more sense to just\n> use a single mergetool.vimdiff.layout across all the different\n> variants of vim implementations, and possibly, have their own one\n> override the most generic \"vimdiff\" one.  E.g. gvimdiff would use\n> mergetool.gvimdiff.layout if exists, or mergetool.vimdiff.layout\n> otherwise.\n\nI think I agree. From the three reasons you mention, only the third one makes\nsome sense, and even that one is too weak to justify having different\nconfiguration option names.\n\nI'll only leave `mergetool.vimdiff.layout` in v7, which will affect all three\nvariants.\n\n"}]}