diff mbox series

fixup! mergetool: add automerge configuration

Message ID 20210109214922.33972-1-davvid@gmail.com (mailing list archive)
State Superseded
Headers show
Series fixup! mergetool: add automerge configuration | expand

Commit Message

David Aguilar Jan. 9, 2021, 9:49 p.m. UTC
The use of "\r\?" in sed is not portable to macOS and possibly
other unix flavors.

Replace "\r" with a substituted variable that contains "\r".
Replace "\?" with "\{0,1\}".

Signed-off-by: David Aguilar <davvid@gmail.com>
---
This is based on top of fc/mergetool-automerge and can be squashed in
(with the addition of my sign-off) if desired.

Let me know if you'd prefer a separate patch. I figured we'd want
a squash to preserve bisectability.

 git-mergetool.sh | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

brian m. carlson Jan. 9, 2021, 9:59 p.m. UTC | #1
On 2021-01-09 at 21:49:22, David Aguilar wrote:
> The use of "\r\?" in sed is not portable to macOS and possibly
> other unix flavors.
> 
> Replace "\r" with a substituted variable that contains "\r".
> Replace "\?" with "\{0,1\}".

Ah, yes, this is true.  The statement about "\r" is also true for Linux
with POSIXLY_CORRECT, IIRC.

> Signed-off-by: David Aguilar <davvid@gmail.com>
> ---
> This is based on top of fc/mergetool-automerge and can be squashed in
> (with the addition of my sign-off) if desired.
> 
> Let me know if you'd prefer a separate patch. I figured we'd want
> a squash to preserve bisectability.
> 
>  git-mergetool.sh | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/git-mergetool.sh b/git-mergetool.sh
> index a44afd3822..12c3e83aa7 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 '\x0d')

Unfortunately, printf is not specified by POSIX to take hex escapes, so
this, too is nonportable.  We are unfortunately allowed to use only
octal escapes (yuck).  However, we can write this:

  cr=$(printf '\r')

or

  cr=$(printf '\015')

I think the former is clearer, since that's what we were writing before.
Junio C Hamano Jan. 9, 2021, 11:21 p.m. UTC | #2
"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> Ah, yes, this is true.  The statement about "\r" is also true for Linux
> with POSIXLY_CORRECT, IIRC.

It's nice to have a way to reproduce without having a separate
toolchain.  Thanks for the suggestion.

> Unfortunately, printf is not specified by POSIX to take hex escapes, so
> this, too is nonportable.  We are unfortunately allowed to use only
> octal escapes (yuck).  However, we can write this:
>
>   cr=$(printf '\r')
>
> or
>
>   cr=$(printf '\015')
>
> I think the former is clearer, since that's what we were writing before.

The latter however appears more portable at least to traditionalists
;-)
diff mbox series

Patch

diff --git a/git-mergetool.sh b/git-mergetool.sh
index a44afd3822..12c3e83aa7 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 '\x0d')
+		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"
 }