[PATCH v4] Enable auto-merge for meld to follow the vim-diff beharior

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "lin.sun" <lin.sun@xxxxxxx>

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 <lin.sun@xxxxxxx>
---
    Enable auto-merge for meld to follow the vimdiff beharior
    
    Hi, the mergetool "meld" does NOT merge the no-conflict changes, while
    the mergetool "vimdiff" will merge the no-conflict changes and highlight
    the conflict parts. This patch will make the mergetool "meld" similar to
    "vimdiff", auto-merge the no-conflict changes, highlight conflict parts.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-781%2Fsunlin7%2Fmaster-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-781/sunlin7/master-v4
Pull-Request: https://github.com/git/git/pull/781

Range-diff vs v3:

 1:  3b70fd0bfc ! 1:  93ae3ec011 Enable auto-merge for meld to follow the vim-diff beharior
     @@ Metadata
       ## Commit message ##
          Enable auto-merge for meld to follow the vim-diff beharior
      
     -    The mergetool "meld" does NOT merge the no-conflict changes, while the
     -    mergetool "vimdiff" will merge the no-conflict parts and highlight the
     -    conflict parts.
     -    This patch will make the mergetool "meld" similar to "vimdiff",
     -    auto-merge the no-conflict parts, highlight conflict parts.
     +    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 <lin.sun@xxxxxxx>
     +    Signed-off-by: lin.sun <lin.sun@xxxxxxx>
      
       ## mergetools/meld ##
     -@@ mergetools/meld: merge_cmd () {
     - 	then
     - 		check_meld_for_output_version
     - 	fi
     -+	if test -z "${meld_has_auto_merge_option:+set}"
     -+	then
     -+		check_meld_for_auto_merge_version
     -+	fi
     +@@ mergetools/meld: 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
     + 	then
     +-		check_meld_for_output_version
      +		option_auto_merge="--auto-merge"
     -+	fi
     + 	fi
       
       	if test "$meld_has_output_option" = true
       	then
     @@ mergetools/meld: merge_cmd () {
       	fi
       }
       
     -@@ mergetools/meld: check_meld_for_output_version () {
     - 		meld_has_output_option=false
     - 	fi
     - }
     -+
     -+# Check whether we should use 'meld --auto-merge ...'
     -+check_meld_for_auto_merge_version () {
     -+	meld_path="$(git config mergetool.meld.path)"
     -+	meld_path="${meld_path:-meld}"
     +-# Check whether we should use 'meld --output <file>'
     +-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 <file>'
     ++	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 meld_has_auto_merge_option=$(git config --bool mergetool.meld.hasAutoMerge)
     -+	then
     -+		: use configured value
     -+	elif "$meld_path" --help 2>&1 |
     -+		grep -e '--auto-merge' -e '\[OPTION\.\.\.\]' >/dev/null
     -+	then
     -+		: old ones mention --auto-merge and new ones just say OPTION...
     -+		meld_has_auto_merge_option=true
     -+	else
     -+		meld_has_auto_merge_option=false
     ++			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
     + }


 mergetools/meld | 73 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 57 insertions(+), 16 deletions(-)

diff --git a/mergetools/meld b/mergetools/meld
index 7a08470f88..1b92771228 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 <file>'
-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 <file>'
+	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
 }

base-commit: 07d8ea56f2ecb64b75b92264770c0a664231ce17
-- 
gitgitgadget



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux