[PATCH v2 3/9] mergetools: vimdiff: add get_buf() helper

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

 



Now the single window mode can avoid gen_cmd_aux() altogether.

No functional changes.

Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 mergetools/vimdiff | 51 +++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/mergetools/vimdiff b/mergetools/vimdiff
index 9805d139bc..103729b6a6 100644
--- a/mergetools/vimdiff
+++ b/mergetools/vimdiff
@@ -55,6 +55,30 @@ substring () {
 	echo "$STRING" | cut -c$(( START + 1 ))-$(( START + $LEN ))
 }
 
+get_buf () {
+	target=$(echo "$1" | sed 's:[ @();|-]::g')
+	buf="1"
+
+	if test "$target" = "LOCAL"
+	then
+		buf="1"
+
+	elif test "$target" = "BASE"
+	then
+		buf="2"
+
+	elif test "$target" = "REMOTE"
+	then
+		buf="3"
+
+	elif test "$target" = "MERGED"
+	then
+		buf="4"
+	fi
+
+	echo "$buf"
+}
+
 gen_cmd_aux () {
 	# Auxiliary function used from "gen_cmd()".
 	# Read that other function documentation for more details.
@@ -257,27 +281,8 @@ gen_cmd_aux () {
 	# If we reach this point, it means there are no separators and we just
 	# need to print the command to display the specified buffer
 
-	target=$(substring "$LAYOUT" "$start" "$(( end - start ))" | sed 's:[ @();|-]::g')
-
-	if test "$target" = "LOCAL"
-	then
-		CMD="$CMD | 1b"
-
-	elif test "$target" = "BASE"
-	then
-		CMD="$CMD | 2b"
-
-	elif test "$target" = "REMOTE"
-	then
-		CMD="$CMD | 3b"
-
-	elif test "$target" = "MERGED"
-	then
-		CMD="$CMD | 4b"
-
-	else
-		CMD="$CMD | ERROR: >$target<"
-	fi
+	buf=$(get_buf $(substring "$LAYOUT" "$start" "$(( end - start ))"))
+	CMD="$CMD | ${buf}b"
 
 	echo "$CMD"
 	return
@@ -319,8 +324,8 @@ gen_cmd () {
 
 	if ! echo "$LAYOUT" | grep ",\|/" >/dev/null
 	then
-		CMD=$(gen_cmd_aux "$LAYOUT")
-		FINAL_CMD="-c \"$CMD | bufdo diffthis\" -c \"tabfirst\""
+		buf=$(get_buf "$LAYOUT")
+		FINAL_CMD="-c \"echo | ${buf}b | bufdo diffthis\" -c \"tabfirst\""
 		return
 	fi
 
-- 
2.37.1.378.g3f95da6bac




[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