git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 16, 2020, 22:24 UTC
Message-ID
<xmqqa6ud2xuw.fsf@gitster.c.googlers.com>
In-Reply-To
<20201216174345.28146-1-felipe.contreras@gmail.com>
Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 19 quoted lines
> 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@eseth.com>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>

Hmph, I got what Seth showed, but I do not quite see how the ideas in the post relate to what this patch does. The patch just avoids grabbing the contents of each stage out to a file for three stages using "git checkout-index" and instead does the same by munging the diff3 output, which ought to have the same information at least for text files, using "sed", or is there something I am not seeing?

If there is none, then what is the benefit of doing the same thing without running 3 checkout-index? Performance?

Also using checkout-index to grab the raw contents without relying on the textual context marker would mean that a custom mergetool backend could be used to merge non-text files. So if this optimization (I am still assuming this is "doing the same without running three checkout-index to gain performance" I read out of the patch text) is worth doing, there needs a knob to allow users to opt out of it somehow to avoid regressing on the feature front.

If the mergetool were in control to (re)start the merge process that would result in the conflicted state, we could override the end-user preference on the conflict style (either 'GNU merge'-style or 'diff3'-style) and conflict-marker-length to be used in showing textual conflicts, but as I understand "mergetool" is handed an already conflicted state and asked to resolve it, it would not be possible without at least looking at the stage #1 to recover the base for folks who do not use diff3 style.

Show 39 quoted lines
> ---
>  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"
>  

Style (lose SP after '>' redirection; I looked at the existing code and spotted one existing violation but that is not an excuse to make things even less consistent).

Also, conflict-marker-size=<N> attributes can change the length, so hardcoding these patterns would not work for everybody.

>  	if test -z "$local_mode" || test -z "$remote_mode"
>  	then
Thanks.
Previous: Felipe ContrerasNext: Seth House
Message 2 of 70 in “mergetool: use resolved conflicts in all the views”
  1. mergetool: use resolved conflicts in all the viewsFelipe Contreras, Dec 16, 2020
  2. Junio C HamanoDec 16, 2020
  3. Seth HouseDec 16, 2020
  4. Junio C HamanoDec 17, 2020
  5. Felipe ContrerasDec 17, 2020
  6. Johannes SixtDec 17, 2020
  7. Felipe ContrerasDec 17, 2020
  8. Johannes SixtDec 17, 2020
  9. Felipe ContrerasDec 18, 2020
  10. Seth HouseDec 17, 2020
  11. Felipe ContrerasDec 17, 2020
  12. Seth HouseDec 17, 2020
  13. Junio C HamanoDec 17, 2020
  14. Felipe ContrerasDec 18, 2020
  15. Felipe ContrerasDec 18, 2020
  16. Seth HouseDec 18, 2020
  17. Felipe ContrerasDec 18, 2020
  18. Seth HouseDec 18, 2020
  19. Felipe ContrerasDec 18, 2020
  20. Seth HouseDec 19, 2020
  21. Felipe ContrerasDec 19, 2020
  22. Junio C HamanoDec 19, 2020
  23. Felipe ContrerasDec 19, 2020
  24. Junio C HamanoDec 19, 2020
  25. Felipe ContrerasDec 19, 2020
  26. Seth HouseDec 21, 2020
  27. Felipe ContrerasDec 21, 2020
  28. Seth HouseDec 21, 2020
  29. Felipe ContrerasDec 21, 2020
  30. David AguilarDec 21, 2020
  31. Code of conduct violation?Felipe Contreras, Dec 21, 2020
  32. Junio C HamanoDec 22, 2020
  33. Felipe ContrerasDec 22, 2020
  34. Pratyush YadavDec 22, 2020
  35. Felipe ContrerasDec 23, 2020
  36. Junio C HamanoDec 23, 2020
  37. Felipe ContrerasDec 23, 2020
  38. Nobody is THE one making contributionJunio C Hamano, Dec 23, 2020
  39. Felipe ContrerasDec 23, 2020
  40. Junio C HamanoDec 23, 2020
  41. Felipe ContrerasDec 24, 2020
  42. Ævar Arnfjörð BjarmasonDec 24, 2020
  43. Felipe ContrerasDec 24, 2020
  44. Ævar Arnfjörð BjarmasonDec 24, 2020
  45. Felipe ContrerasDec 24, 2020
  46. Junio C HamanoDec 24, 2020
  47. Felipe ContrerasDec 27, 2020
  48. Junio C HamanoDec 27, 2020
  49. Felipe ContrerasDec 27, 2020
  50. Junio C HamanoDec 28, 2020
  51. Felipe ContrerasDec 28, 2020
  52. Randall S. BeckerDec 24, 2020
  53. Felipe ContrerasDec 24, 2020
  54. Junio C HamanoDec 24, 2020
  55. David AguilarDec 24, 2020
  56. Felipe ContrerasDec 24, 2020
  57. Junio C HamanoDec 18, 2020
  58. Felipe ContrerasDec 18, 2020
  59. Junio C HamanoDec 19, 2020
  60. Felipe ContrerasDec 19, 2020
  61. David AguilarDec 20, 2020
  62. Felipe ContrerasDec 20, 2020
  63. David AguilarDec 20, 2020
  64. Felipe ContrerasDec 21, 2020
  65. Seth HouseDec 19, 2020
  66. Felipe ContrerasDec 16, 2020
  67. Junio C HamanoDec 17, 2020
  68. Felipe ContrerasDec 17, 2020
  69. mergetool: use resolved conflicts in all the viewsFelipe Contreras, Dec 17, 2020
  70. Felipe ContrerasDec 21, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.