git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Felipe Contreras <felipe.contreras@gmail.com>, git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	David Aguilar <davvid@gmail.com>, Johannes Sixt <j6t@kdbg.org>,
	Seth House <seth@eseth.com>
Subject: Re: [PATCH v4 1/1] mergetool: add automerge configuration
Date: Sat, 19 Dec 2020 11:14:51 +0000	[thread overview]
Message-ID: <b338a9f4-6e34-c5c6-16ef-097aadc3f3a8@gmail.com> (raw)
In-Reply-To: <20201218124905.1072514-2-felipe.contreras@gmail.com>

Hi Felipe

On 18/12/2020 12:49, Felipe Contreras wrote:
> It doesn't make sense to display lines without conflicts in the
> different views of all mergetools.
> 
> Only the lines that warrant conflict markers should be displayed.
> 
> Most people would want this behavior on, but in case some don't; add a
> new configuration: mergetool.autoMerge.
> 
> See Seth House's blog post [1] for the idea, and the rationale.
> 
> [1] https://www.eseth.org/2020/mergetools.html

I would be good to have a summary of the idea in this commit message so 
people do not have to go and find a blog post which may well disappear 
in the future

> Original-idea-by: Seth House <seth@eseth.com>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>   Documentation/config/mergetool.txt |  3 +++
>   git-mergetool.sh                   | 17 +++++++++++++++++
>   t/t7610-mergetool.sh               | 18 ++++++++++++++++++
>   3 files changed, 38 insertions(+)
> 
> diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt
> index 16a27443a3..7ce6d0d3ac 100644
> --- a/Documentation/config/mergetool.txt
> +++ b/Documentation/config/mergetool.txt
> @@ -61,3 +61,6 @@ mergetool.writeToTemp::
>   
>   mergetool.prompt::
>   	Prompt before each invocation of the merge resolution program.
> +
> +mergetool.autoMerge::
> +	Remove lines without conflicts from all the files. Defaults to `true`.
> diff --git a/git-mergetool.sh b/git-mergetool.sh
> index e3f6d543fb..f4db0cac8d 100755
> --- a/git-mergetool.sh
> +++ b/git-mergetool.sh
> @@ -239,6 +239,17 @@ checkout_staged_file () {
>   	fi
>   }
>   
> +auto_merge () {
> +	git merge-file --diff3 --marker-size=7 -q -p "$LOCAL" "$BASE" "$REMOTE" >"$DIFF3"

I've been wondering if we want to recreate the merge or just get the 
merged BASE LOCAL and REMOTE from the merged file in the working tree. 
If the user wants to resolve the conflicts in stages, or opens the file 
in a editor and fixes some conflicts and then realizes they want to use 
a merge tool that work is thrown away if we recreate the merge. They can 
always use `checkout --merge` to throw away their changes and start 
again with a mergetool. It would mean checking the size of the conflict 
markers and using 
'/^<{$conflict_marker_size}/,^|{$conflict_marker_size}/' for sed. 
Getting the merged BASE would be tricky if the user does not have diff3 
conflicts enabled, I'm not sure if we can safely get BASE from `git 
merge-file ...` and LOCAL and REMOTE from the working tree.

> +	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"
> +	fi
> +	rm -- "$DIFF3"
> +}
> +
>   merge_file () {
>   	MERGED="$1"
>   
> @@ -274,6 +285,7 @@ merge_file () {
>   		BASE=${BASE##*/}
>   	fi
>   
> +	DIFF3="$MERGETOOL_TMPDIR/${BASE}_DIFF3_$$$ext"
>   	BACKUP="$MERGETOOL_TMPDIR/${BASE}_BACKUP_$$$ext"
>   	LOCAL="$MERGETOOL_TMPDIR/${BASE}_LOCAL_$$$ext"
>   	REMOTE="$MERGETOOL_TMPDIR/${BASE}_REMOTE_$$$ext"
> @@ -322,6 +334,11 @@ merge_file () {
>   	checkout_staged_file 2 "$MERGED" "$LOCAL"
>   	checkout_staged_file 3 "$MERGED" "$REMOTE"
>   
> +	if test "$(git config --bool mergetool.autoMerge)" != "false"

If I run `git config --bool mergetool.autoMerge` it returns an empty 
string so I think you need to test it is actually equal to "true".

I also share the view that this should be per tool. Your demand that 
someone comes up with an example that breaks assumes that we have access 
to all the tools that users are using. Seth has done a great job of 
surveying the popular tools but given the size of git's user-base and 
the diversity of uses it is very likely that there will be people using 
in-house or proprietary tools that no one on the list has access to. I 
would much prefer to avoid breaking them rather than waiting for a bug 
report before implementing a per-tool setting. It is quite possible 
people are using different tools for different files in the same way as 
they use different merge drivers for different files and want the 
setting disabled for a tool that does semantic merging but enabled 
textual merges.

Best Wishes

Phillip

> +	then
> +		auto_merge
> +	fi
> +
>   	if test -z "$local_mode" || test -z "$remote_mode"
>   	then
>   		echo "Deleted merge conflict for '$MERGED':"
> diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
> index 70afdd06fa..ccabd04823 100755
> --- a/t/t7610-mergetool.sh
> +++ b/t/t7610-mergetool.sh
> @@ -828,4 +828,22 @@ test_expect_success 'mergetool -Oorder-file is honored' '
>   	test_cmp expect actual
>   '
>   
> +test_expect_success 'mergetool automerge' '
> +	test_config mergetool.automerge true &&
> +	test_when_finished "git reset --hard" &&
> +	git checkout -b test${test_count}_b master &&
> +	test_write_lines >file1 base "" a &&
> +	git commit -a -m "base" &&
> +	test_write_lines >file1 base "" c &&
> +	git commit -a -m "remote update" &&
> +	git checkout -b test${test_count}_a HEAD~ &&
> +	test_write_lines >file1 local "" b &&
> +	git commit -a -m "local update" &&
> +	test_must_fail git merge test${test_count}_b &&
> +	yes "" | git mergetool file1 &&
> +	test_write_lines >expect local "" c &&
> +	test_cmp expect file1 &&
> +	git commit -m "test resolved with mergetool"
> +'
> +
>   test_done
> 


  reply	other threads:[~2020-12-19 11:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-18 12:49 [PATCH v4 0/1] mergetool: add configuration to remove unconflicted lines Felipe Contreras
2020-12-18 12:49 ` [PATCH v4 1/1] mergetool: add automerge configuration Felipe Contreras
2020-12-19 11:14   ` Phillip Wood [this message]
2020-12-19 12:53     ` Felipe Contreras
2020-12-20 19:21       ` Phillip Wood
2020-12-21  3:04         ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b338a9f4-6e34-c5c6-16ef-097aadc3f3a8@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=davvid@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=seth@eseth.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).