From: lin.sun@zoom.us Date: Tue, 30 Jun 2020 11:25:07 GMT Subject: RE: [PATCH v3] Enable auto-merge for meld to follow the vim-diff beharior Message-ID: In-Reply-To: <20200630074204.GA2144485@gmail.com> Hi David, Junio, Appreciate for your comments, I rewrite the "mergetool/meld" to follow your comments and suggestions. It will respect the git config first, then detect the options if no configuration for them, and also reduce the subprocess calling. Both the modified-file and patch-file are appended. Please review again. Thanks Regards Lin Sun From 93ae3ec011e7b55cc9971f91345cb4aab5189cb4 Mon Sep 17 00:00:00 2001 From: "lin.sun" Date: Thu, 7 May 2020 07:31:14 +0800 Subject: [PATCH] Enable auto-merge for meld to follow the vim-diff beharior Make the mergetool used with "meld" backend behave similarly to how "vimdiff" beheaves by telling it to auto-merge parts without conflicts and highlight the parts with conflicts. Signed-off-by: lin.sun --- mergetools/meld | 73 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/mergetools/meld b/mergetools/meld index 7a08470..1b92771 100644 --- a/mergetools/meld +++ b/mergetools/meld @@ -3,34 +3,75 @@ diff_cmd () { } merge_cmd () { - if test -z "${meld_has_output_option:+set}" + check_meld_for_features + + option_auto_merge= + if test "$meld_has_auto_merge_option" = true then - check_meld_for_output_version + option_auto_merge="--auto-merge" fi if test "$meld_has_output_option" = true then - "$merge_tool_path" --output="$MERGED" \ + "$merge_tool_path" $option_auto_merge --output="$MERGED" \ "$LOCAL" "$BASE" "$REMOTE" else - "$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE" + "$merge_tool_path" $option_auto_merge "$LOCAL" "$MERGED" "$REMOTE" fi } -# Check whether we should use 'meld --output ' -check_meld_for_output_version () { - meld_path="$(git config mergetool.meld.path)" - meld_path="${meld_path:-meld}" +# Get meld help message +get_meld_help_msg () { + meld_path="$(git config mergetool.meld.path || echo meld)" + $meld_path --help 2>&1 +} - if meld_has_output_option=$(git config --bool mergetool.meld.hasOutput) +# Check the features and set flags +check_meld_for_features () { + # Check whether we should use 'meld --output ' + if test -z "${meld_has_output_option:+set}" then - : use configured value - elif "$meld_path" --help 2>&1 | - grep -e '--output=' -e '\[OPTION\.\.\.\]' >/dev/null + meld_has_output_option=$(git config --bool mergetool.meld.hasOutput) + if test "$meld_has_output_option" = true -o \ + "$meld_has_output_option" = false + then + : use configured value + else # treat meld_has_output_option as "auto" + if test -z "$meld_help_msg" + then + meld_help_msg="$(get_meld_help_msg)" + fi + + if echo "$meld_help_msg" | + grep -e '--output=' -e '\[OPTION\.\.\.\]' >/dev/null + then + : old ones mention --output and new ones just say OPTION... + meld_has_output_option=true + else + meld_has_output_option=false + fi + fi + fi + # Check whether we should use 'meld --auto-merge ...' + if test -z "${meld_has_auto_merge_option:+set}" then - : old ones mention --output and new ones just say OPTION... - meld_has_output_option=true - else - meld_has_output_option=false + meld_has_auto_merge_option=$(git config --bool mergetool.meld.hasAutoMerge) + if test "$meld_has_auto_merge_option" = true -o \ + "$meld_has_auto_merge_option" = false + then + : use configured value + else # treat meld_has_auto_merge_option as "auto" + if test -z "$meld_help_msg" + then + meld_help_msg="$(get_meld_help_msg)" + fi + + if echo "$meld_help_msg" | grep -e '--auto-merge' >/dev/null + then + meld_has_auto_merge_option=true + else + meld_has_auto_merge_option=false + fi + fi fi } -- 2.2.0