Re: [PATCH v2] fixup! mergetool: add automerge configuration

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

 



David Aguilar <davvid@xxxxxxxxx> writes:

> "\r\?" in sed is not portable to macOS and possibly others.
> "\r" is not valid on Linux with POSIXLY_CORRECT.
>
> Replace "\r" with a substituted variable that contains "\r".
> Replace "\?" with "\{0,1\}".
>
> Helped-by: brian m. carlson <sandals@xxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: David Aguilar <davvid@xxxxxxxxx>
> ---
> This is based on top of fc/mergetool-automerge and can be squashed in
> (with the addition of my sign-off) if desired.
>
> Changes since last time:
> - printf '\r' instead of printf '\x0d'
> - The commit message now mentions POSIXLY_CORRECT.
>
>  git-mergetool.sh | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/git-mergetool.sh b/git-mergetool.sh
> index a44afd3822..9029a79431 100755
> --- a/git-mergetool.sh
> +++ b/git-mergetool.sh
> @@ -243,9 +243,16 @@ auto_merge () {
>  	git merge-file --diff3 --marker-size=7 -q -p "$LOCAL" "$BASE" "$REMOTE" >"$DIFF3"
>  	if test -s "$DIFF3"
>  	then
> -		sed -e '/^<<<<<<< /,/^||||||| /d' -e '/^=======\r\?$/,/^>>>>>>> /d' "$DIFF3" >"$BASE"
> -		sed -e '/^||||||| /,/^>>>>>>> /d' -e '/^<<<<<<< /d' "$DIFF3" >"$LOCAL"
> -		sed -e '/^<<<<<<< /,/^=======\r\?$/d' -e '/^>>>>>>> /d' "$DIFF3" >"$REMOTE"
> +		cr=$(printf '\r')
> +		sed -e '/^<<<<<<< /,/^||||||| /d' \
> +			-e "/^=======$cr\{0,1\}$/,/^>>>>>>> /d" \
> +			"$DIFF3" >"$BASE"
> +		sed -e '/^||||||| /,/^>>>>>>> /d' \
> +			-e '/^<<<<<<< /d' \
> +			"$DIFF3" >"$LOCAL"
> +		sed -e "/^<<<<<<< /,/^=======$cr\{0,1\}$/d" \
> +			-e '/^>>>>>>> /d' \
> +			"$DIFF3" >"$REMOTE"
>  	fi
>  	rm -- "$DIFF3"
>  }

I was hoping that we can avoid repetition that can cause bugs with
something like

diff --git i/git-mergetool.sh w/git-mergetool.sh
index a44afd3822..e07dabbf72 100755
--- i/git-mergetool.sh
+++ w/git-mergetool.sh
@@ -243,9 +243,13 @@ auto_merge () {
 	git merge-file --diff3 --marker-size=7 -q -p "$LOCAL" "$BASE" "$REMOTE" >"$DIFF3"
 	if test -s "$DIFF3"
 	then
-		sed -e '/^<<<<<<< /,/^||||||| /d' -e '/^=======\r\?$/,/^>>>>>>> /d' "$DIFF3" >"$BASE"
-		sed -e '/^||||||| /,/^>>>>>>> /d' -e '/^<<<<<<< /d' "$DIFF3" >"$LOCAL"
-		sed -e '/^<<<<<<< /,/^=======\r\?$/d' -e '/^>>>>>>> /d' "$DIFF3" >"$REMOTE"
+		C0="^<<<<<<< "
+		C1="^||||||| "
+		C2="^=======$(printf '\015')*\$"
+		C3="^>>>>>>> "
+		sed -e "/$C0/,/$C1/d" -e "/$C2/,/$C3/d" "$DIFF3" >"$BASE"
+		sed -e "/$C1/,/$C3/d" -e "/$C0/d" "$DIFF3" >"$LOCAL"
+		sed -e "/$C0/,/$C2/d" -e "/$C3 /d" "$DIFF3" >"$REMOTE"
 	fi
 	rm -- "$DIFF3"
 }



[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