[RFC/PATCH] mergetool: use resolved conflicts in all the views

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

 



It doesn't make sense to display already-resolved conflicts in the
different views of all mergetools.

We already have the best version in MERGED, with annotations that can
be used to extract a pruned version of LOCAL and REMOTE. If we are using
the diff3 conflict-style, we can even extract BASE.

Let's use these annotations instead of using the original files before
the conflict resolution.

TODO: There may be a better way to extract these files that doesn't rely
on the user's conflict-style configuration.

See Seth House's blog post [1] for the idea and the rationale.

[1] https://www.eseth.org/2020/mergetools.html

Cc: Seth House <seth@xxxxxxxxx>
Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 git-mergetool.sh | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/git-mergetool.sh b/git-mergetool.sh
index e3f6d543fb..4759433d46 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -227,18 +227,6 @@ stage_submodule () {
 	git update-index --add --replace --cacheinfo 160000 "$submodule_sha1" "${work_rel_path%/}" || die
 }
 
-checkout_staged_file () {
-	tmpfile="$(git checkout-index --temp --stage="$1" "$2" 2>/dev/null)" &&
-	tmpfile=${tmpfile%%'	'*}
-
-	if test $? -eq 0 && test -n "$tmpfile"
-	then
-		mv -- "$(git rev-parse --show-cdup)$tmpfile" "$3"
-	else
-		>"$3"
-	fi
-}
-
 merge_file () {
 	MERGED="$1"
 
@@ -318,9 +306,10 @@ merge_file () {
 	# where the base's directory no longer exists.
 	mkdir -p "$(dirname "$MERGED")"
 
-	checkout_staged_file 1 "$MERGED" "$BASE"
-	checkout_staged_file 2 "$MERGED" "$LOCAL"
-	checkout_staged_file 3 "$MERGED" "$REMOTE"
+	# TODO: How do we get $MERGED always with diff3?
+	sed -e '/^<<<<<<< /,/^||||||| /d' -e '/^=======$/,/^>>>>>>> /d' "$MERGED" > "$BASE"
+	sed -e '/^<<<<<<< /,/^=======$/d' -e '/^>>>>>>> /d' "$MERGED" > "$LOCAL"
+	sed -e '/^||||||| /,/^>>>>>>> /d' -e '/^<<<<<<< /d' "$MERGED" > "$REMOTE"
 
 	if test -z "$local_mode" || test -z "$remote_mode"
 	then
-- 
2.30.0.rc0




[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