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

Re: [PATCH v2 8/8] show, log: include conflict/warning messages in --remerge-diff headers

From
Elijah Newren <newren@gmail.com>
Date
Dec 28, 2021, 23:42 UTC
Message-ID
<CABPp-BFP5Oc3vDQVJYZ4L=4ivSYuZBNk+Y9RHioJuSZKVzW0Dg@mail.gmail.com>
In-Reply-To
<20211228105755.zgahkoxn6ewjpdol@gmail.com>
On Tue, Dec 28, 2021 at 2:57 AM Johannes Altmanninger <aclopte@gmail.com> wrote:
>
> On Sat, Dec 25, 2021 at 07:59:19AM +0000, Elijah Newren via GitGitGadget wrote:
...
Show 7 quoted lines
> > +test_expect_success 'remerge-diff with non-content conflicts' '
> > +     git log -1 --oneline resolution >tmp &&
> > +     cat <<-EOF >>tmp &&
> > +     diff --git a/file_or_directory~HASH (side1) b/wanted_content
>
> the "~HASH (side1)" suffix will probably mess with some programs that extract
> the filename from the diff.

"~HASH (side1)" is part of the filename, so this won't mess those programs up at all (unless those programs can't deal with filenames containing spaces or parentheses or something).

> I don't know what programs are supposed to expect.  I can see arguments for
> either dropping the suffix or including only "~HASH" since that's part of
> the actual filename that's left in the worktree.

When there are conflicts that prevent the file from being recorded in the tree, such as file/directory conflicts, we have to rename the file elsewhere. We want the new name to be something that the user can find and reason about. So, both merge-recursive and merge-ort use ${filename}~${branchname}, where ${branchname} is defined in the struct merge_options (opt->branch1 or opt->branch2) that were passed in to the function.

For a regular `git merge` we just use opt->branch1 = "HEAD" and opt->branch2 = <name of branch/commit typed on command line to merge>.

Neither of those strings make sense for remerge-diff. We could just use hashes, but why are users going to be familiar with the hashes of the parents of a merge commit when looking at --remerge-diff output? Parents are not part of the output by default. So, log-tree.c uses this bit of logic

    format_commit_message(parent1, "%h (%s)", &parent1_desc, &ctx);
    format_commit_message(parent2, "%h (%s)", &parent2_desc, &ctx);
    o.branch1 = parent1_desc.buf;
    o.branch2 = parent2_desc.buf;

which means that the branch name is of the form "$HASH ($EXTRA_DESCRIPTION)", and thus that files in file/directory conflicts (or add/add + file/symlink conflicts or file/submodule conflicts) will get renamed to a file of the form "$FILENAME~$HASH ($EXTRA_DESCRIPTION)"

Note that these branch names also appear in CONFLICT messages, in conflict markers, etc., and in fact are used much more frequently in those locations. In those places it's perhaps even more important to attempt to provide meaningful names, so dropping the extra description doesn't make sense.

Show 13 quoted lines
> The file/link typechange conflict test I'll add below exposes what looks
> like an accidental interaction with the trailing tab characters that we emit
> on --- and +++ lines if the "filename" contains a space (since 1a9eb3b9d5
> (git-diff/git-apply: make diff output a bit friendlier to GNU patch (part
> 2), 2006-09-22)).
>
>         index 70885e4..0000000
>         --- a/typechange~738109f (side1)        <-- git diff adds a trailing tab!
>         +++ /dev/null
>
> I haven't formed an opinion yet, but since Tig uses the --- and +++ lines
> to extract file names, I'd drop the " (side1)" suffix from at least the ---
> and +++ lines. Maybe also the ^diff lines, I'm not sure
As above, " (side1)" is part of the filename and thus belongs here.
Show 7 quoted lines
> > +     similarity index 100%
> > +     rename from file_or_directory~HASH (side1)
> > +     rename to wanted_content
> > +     CONFLICT (file/directory): directory in the way of file_or_directory from HASH (side1); moving it to file_or_directory~HASH (side1) instead.
>
> I wonder if it's better to have this line further up, before the "rename"
> resolution, to correct the temporal order.

Yeah, I've gone back and forth about where these would best be placed. You make a good point, even if the code is slightly uglier to move earlier. However, I do really like having the CONFLICT notices being close to the file text being shown, which makes me conflicted (no pun intended) about moving it earlier. Hmm....

Show 38 quoted lines
> > +     diff --git a/letters b/letters
> > +     CONFLICT (rename/rename): letters renamed to letters_side1 in HASH (side1) and to letters_side2 in HASH (side2).
> > +     diff --git a/letters_side2 b/letters_side2
> > +     deleted file mode 100644
> > +     index b236ae5..0000000
> > +     --- a/letters_side2
> > +     +++ /dev/null
> > +     @@ -1,9 +0,0 @@
> > +     -a
> > +     -b
> > +     -c
> > +     -d
> > +     -e
> > +     -f
> > +     -g
> > +     -h
> > +     -i
> > +     diff --git a/numbers b/numbers
> > +     CONFLICT (modify/delete): numbers deleted in HASH (side2) and modified in HASH (side1).  Version HASH (side1) of numbers left in tree.
> > +     EOF
>
> Took me some time to grok these but the output makes sense (it's loud and
> ugly but that's okay since these are serious conflicts).
>
> > +     # We still have some sha1 hashes above; rip them out so test works
> > +     # with sha256
> > +     sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
> > +
> > +     git show --oneline --remerge-diff resolution >tmp &&
> > +     sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
> > +     test_cmp expect actual
> > +'
> > +
> >  test_done
> > --
> > gitgitgadget
>
> We're missing a test case for typechange.

<grin> ...and a testcase for an add/add conflict, and a file/submodule conflict, and file/symlink, and symlink/submodule, and submodule/submodule (different submodules both added at same path), and binary merge conflict, and a variety of failure-to-merge-submodule-updates, and at least half a dozen regular rename-based conflict types, and several directory-rename-based conflict types...and that's just beginning to scratch the surface once you start dreaming of combinations of the different conflict types occurring for the same path (in particular, I'm thinking of examples from the testcases found in t6416, t6422, t6423 -- or at least sections 7, 9, & 12 of t6423).

I don't think providing a comprehensive set of possible conflicts is useful here; we just need a representative sample. I was curious whether that was best served with just two examples or three, but ultimately decided on 3. I would have been more likely to pick 2 than 4, though.

However, while I fail to see how typechange stresses --remerge-diff in ways the other conflict types don't, or how it might help clarify the output for users, I might be overlooking something. Is there a particular reason you wanted to see the typechange conflict included?

Show 11 quoted lines
>  Here's is a quick draft I've been
> playing around with. Seems ugly that the "diff --git a/typechange b/typechange"
> is doubled but okay.
>
> Maybe a rename/delete conflict is interesting as well, I'm not sure.  (Also I
> wonder if switching the order of parents will give any interesting difference,
> I guess not)
>
> test_expect_success 'remerge-diff with file/link conflict' '
>         git branch -d base side1 side2 &&
>         git switch --orphan base &&

I'd rather have subdirectories with git repositories (much like t6416, t6422, and t6423) if we're going to be adding many more tests here.

Show 61 quoted lines
>         echo base >typechange &&
>         git add typechange &&
>         git commit -m base &&
>
>         git branch side1 &&
>         git branch side2 &&
>
>         git checkout side1 &&
>         echo orig-file-contents >typechange &&
>         git commit -a -m side1 &&
>
>         git checkout side2 &&
>         ln -sf . typechange &&
>         git add typechange &&
>         git commit -m side2 &&
>
>         git checkout -b resolution2 side1 &&
>         test_must_fail git merge side2 &&
>         rm typechange &&
>         mv typechange~HEAD typechange &&
>         echo resolved >>typechange &&
>         git add typechange~HEAD typechange &&
>         git merge --continue &&
>
>         git show --oneline --remerge-diff resolution2 >tmp &&
>         sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
>
>         cat <<-EOF >tmp &&
>         7759b27 Merge branch ${SQ}side2${SQ} into resolution2
>         diff --git a/typechange b/typechange
>         deleted file mode 120000
>         CONFLICT (distinct types): typechange had different types on each side; renamed one of them so each can be recorded somewhere.
>         index 945c9b4..0000000
>         --- a/typechange
>         +++ /dev/null
>         @@ -1 +0,0 @@
>         -.
>         \ No newline at end of file
>         diff --git a/typechange b/typechange
>         new file mode 100644
>         CONFLICT (distinct types): typechange had different types on each side; renamed one of them so each can be recorded somewhere.
>         index 0000000..70885e4
>         --- /dev/null
>         +++ b/typechange
>         @@ -0,0 +1,2 @@
>         +orig-file-contents
>         +resolved
>         diff --git a/typechange~738109f (side1) b/typechange~738109f (side1)
>         deleted file mode 100644
>         index 70885e4..0000000
>         --- a/typechange~738109f (side1)
>         +++ /dev/null
>         @@ -1 +0,0 @@
>         -orig-file-contents
>         EOF
>         # We still have some sha1 hashes above; rip them out so test works
>         # with sha256
>         sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
>
>         test_cmp expect actual
> '
but otherwise the testcase looks good, if we want it.
Previous: Johannes AltmanningerNext: Ævar Arnfjörð Bjarmason
Message 61 of 113 in “Add a new --remerge-diff capability to show & log”
  1. 0/9 Add a new --remerge-diff capability to show & logElijah Newren via GitGitGadget, Dec 21, 2021
  2. 1/9 tmp_objdir: add a helper function for discarding all contained objectsElijah Newren via GitGitGadget, Dec 21, 2021
  3. Junio C HamanoDec 21, 2021
  4. Elijah NewrenDec 21, 2021
  5. Junio C HamanoDec 22, 2021
  6. Elijah NewrenDec 25, 2021
  7. 2/9 ll-merge: make callers responsible for showing warningsElijah Newren via GitGitGadget, Dec 21, 2021
  8. Ævar Arnfjörð BjarmasonDec 21, 2021
  9. Elijah NewrenDec 21, 2021
  10. Ævar Arnfjörð BjarmasonDec 21, 2021
  11. Elijah NewrenDec 21, 2021
  12. Junio C HamanoDec 21, 2021
  13. Elijah NewrenDec 23, 2021
  14. 3/9 merge-ort: capture and print ll-merge warnings in our preferred fashionElijah Newren via GitGitGadget, Dec 21, 2021
  15. Junio C HamanoDec 22, 2021
  16. Elijah NewrenDec 23, 2021
  17. 4/9 merge-ort: mark a few more conflict messages as omittableElijah Newren via GitGitGadget, Dec 21, 2021
  18. Junio C HamanoDec 22, 2021
  19. Elijah NewrenDec 23, 2021
  20. 5/9 merge-ort: make path_messages available to external callersElijah Newren via GitGitGadget, Dec 21, 2021
  21. 6/9 diff: add ability to insert additional headers for pathsElijah Newren via GitGitGadget, Dec 21, 2021
  22. Junio C HamanoDec 22, 2021
  23. Elijah NewrenDec 25, 2021
  24. 7/9 merge-ort: format messages slightly different for use in headersElijah Newren via GitGitGadget, Dec 21, 2021
  25. 8/9 show, log: provide a --remerge-diff capabilityElijah Newren via GitGitGadget, Dec 21, 2021
  26. Ævar Arnfjörð BjarmasonDec 21, 2021
  27. Elijah NewrenDec 21, 2021
  28. 9/9 doc/diff-options: explain the new --remerge-diff optionElijah Newren via GitGitGadget, Dec 21, 2021
  29. Ævar Arnfjörð BjarmasonDec 21, 2021
  30. Elijah NewrenDec 21, 2021
  31. Ævar Arnfjörð BjarmasonDec 21, 2021
  32. Elijah NewrenDec 22, 2021
  33. Junio C HamanoDec 21, 2021
  34. Elijah NewrenDec 21, 2021
  35. Junio C HamanoDec 22, 2021
  36. 0/8 Add a new --remerge-diff capability to show & logElijah Newren via GitGitGadget, Dec 25, 2021
  37. 1/8 show, log: provide a --remerge-diff capabilityElijah Newren via GitGitGadget, Dec 25, 2021
  38. Johannes AltmanningerDec 28, 2021
  39. Elijah NewrenDec 28, 2021
  40. brian m. carlsonDec 28, 2021
  41. Elijah NewrenDec 28, 2021
  42. 2/8 log: clean unneeded objects during `log --remerge-diff`Elijah Newren via GitGitGadget, Dec 25, 2021
  43. 3/8 ll-merge: make callers responsible for showing warningsElijah Newren via GitGitGadget, Dec 25, 2021
  44. Johannes AltmanningerDec 28, 2021
  45. Elijah NewrenDec 28, 2021
  46. Johannes AltmanningerDec 28, 2021
  47. 4/8 merge-ort: capture and print ll-merge warnings in our preferred fashionElijah Newren via GitGitGadget, Dec 25, 2021
  48. 5/8 merge-ort: mark a few more conflict messages as omittableElijah Newren via GitGitGadget, Dec 25, 2021
  49. 6/8 merge-ort: format messages slightly different for use in headersElijah Newren via GitGitGadget, Dec 25, 2021
  50. In-tree strbuf "in-place" search/replace (was: [PATCH v2 6/8] merge-ort: format messages slightly different for use in headers)Ævar Arnfjörð Bjarmason, Dec 26, 2021
  51. Johannes AltmanningerDec 28, 2021
  52. Elijah NewrenDec 28, 2021
  53. 7/8 diff: add ability to insert additional headers for pathsElijah Newren via GitGitGadget, Dec 25, 2021
  54. Johannes AltmanningerDec 28, 2021
  55. Elijah NewrenDec 28, 2021
  56. Johannes AltmanningerDec 29, 2021
  57. Elijah NewrenDec 30, 2021
  58. Johannes AltmanningerDec 31, 2021
  59. 8/8 show, log: include conflict/warning messages in --remerge-diff headersElijah Newren via GitGitGadget, Dec 25, 2021
  60. Johannes AltmanningerDec 28, 2021
  61. Elijah NewrenDec 28, 2021
  62. Ævar Arnfjörð BjarmasonDec 26, 2021
  63. Elijah NewrenDec 27, 2021
  64. Ævar Arnfjörð BjarmasonJan 10, 2022
  65. Johannes AltmanningerDec 28, 2021
  66. 0/9 Add a new --remerge-diff capability to show & logElijah Newren via GitGitGadget, Dec 30, 2021
  67. 1/9 show, log: provide a --remerge-diff capabilityElijah Newren via GitGitGadget, Dec 30, 2021
  68. Ævar Arnfjörð BjarmasonJan 19, 2022
  69. Elijah NewrenJan 20, 2022
  70. Elijah NewrenJan 20, 2022
  71. Ævar Arnfjörð BjarmasonJan 19, 2022
  72. Elijah NewrenJan 20, 2022
  73. 2/9 log: clean unneeded objects during `log --remerge-diff`Elijah Newren via GitGitGadget, Dec 30, 2021
  74. 3/9 ll-merge: make callers responsible for showing warningsElijah Newren via GitGitGadget, Dec 30, 2021
  75. Ævar Arnfjörð BjarmasonJan 19, 2022
  76. Elijah NewrenJan 20, 2022
  77. 4/9 merge-ort: capture and print ll-merge warnings in our preferred fashionElijah Newren via GitGitGadget, Dec 30, 2021
  78. 5/9 merge-ort: mark a few more conflict messages as omittableElijah Newren via GitGitGadget, Dec 30, 2021
  79. 6/9 merge-ort: format messages slightly different for use in headersElijah Newren via GitGitGadget, Dec 30, 2021
  80. 7/9 diff: add ability to insert additional headers for pathsElijah Newren via GitGitGadget, Dec 30, 2021
  81. 8/9 show, log: include conflict/warning messages in --remerge-diff headersElijah Newren via GitGitGadget, Dec 30, 2021
  82. Ævar Arnfjörð BjarmasonJan 19, 2022
  83. Elijah NewrenJan 21, 2022
  84. Elijah NewrenJan 21, 2022
  85. 9/9 merge-ort: mark conflict/warning messages from inner merges as omittableElijah Newren via GitGitGadget, Dec 30, 2021
  86. Junio C HamanoDec 31, 2021
  87. 00/10 Add a new --remerge-diff capability to show & logElijah Newren via GitGitGadget, Jan 21, 2022
  88. 01/10 show, log: provide a --remerge-diff capabilityElijah Newren via GitGitGadget, Jan 21, 2022
  89. Ævar Arnfjörð BjarmasonFeb 1, 2022
  90. Elijah NewrenFeb 1, 2022
  91. 02/10 log: clean unneeded objects during `log --remerge-diff`Elijah Newren via GitGitGadget, Jan 21, 2022
  92. Ævar Arnfjörð BjarmasonFeb 1, 2022
  93. Elijah NewrenFeb 1, 2022
  94. Ævar Arnfjörð BjarmasonFeb 2, 2022
  95. 03/10 ll-merge: make callers responsible for showing warningsElijah Newren via GitGitGadget, Jan 21, 2022
  96. 04/10 merge-ort: capture and print ll-merge warnings in our preferred fashionElijah Newren via GitGitGadget, Jan 21, 2022
  97. 05/10 merge-ort: mark a few more conflict messages as omittableElijah Newren via GitGitGadget, Jan 21, 2022
  98. 06/10 merge-ort: format messages slightly different for use in headersElijah Newren via GitGitGadget, Jan 21, 2022
  99. 07/10 diff: add ability to insert additional headers for pathsElijah Newren via GitGitGadget, Jan 21, 2022
  100. 08/10 show, log: include conflict/warning messages in --remerge-diff headersElijah Newren via GitGitGadget, Jan 21, 2022
  101. 09/10 merge-ort: mark conflict/warning messages from inner merges as omittableElijah Newren via GitGitGadget, Jan 21, 2022
  102. 10/10 diff-merges: avoid history simplifications when diffing mergesElijah Newren via GitGitGadget, Jan 21, 2022
  103. 00/10 Add a new --remerge-diff capability to show & logElijah Newren via GitGitGadget, Feb 2, 2022
  104. 01/10 show, log: provide a --remerge-diff capabilityElijah Newren via GitGitGadget, Feb 2, 2022
  105. 02/10 log: clean unneeded objects during `log --remerge-diff`Elijah Newren via GitGitGadget, Feb 2, 2022
  106. 03/10 ll-merge: make callers responsible for showing warningsElijah Newren via GitGitGadget, Feb 2, 2022
  107. 04/10 merge-ort: capture and print ll-merge warnings in our preferred fashionElijah Newren via GitGitGadget, Feb 2, 2022
  108. 05/10 merge-ort: mark a few more conflict messages as omittableElijah Newren via GitGitGadget, Feb 2, 2022
  109. 07/10 diff: add ability to insert additional headers for pathsElijah Newren via GitGitGadget, Feb 2, 2022
  110. 10/10 diff-merges: avoid history simplifications when diffing mergesElijah Newren via GitGitGadget, Feb 2, 2022
  111. 08/10 show, log: include conflict/warning messages in --remerge-diff headersElijah Newren via GitGitGadget, Feb 2, 2022
  112. 06/10 merge-ort: format messages slightly different for use in headersElijah Newren via GitGitGadget, Feb 2, 2022
  113. 09/10 merge-ort: mark conflict/warning messages from inner merges as omittableElijah Newren via GitGitGadget, Feb 2, 2022

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.