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

Re: Why doesn't `git log -m` imply `-p`?

From
Sergey Organov <sorganov@gmail.com>
Date
May 3, 2021, 17:42 UTC
Message-ID
<87czu7u32v.fsf@osv.gnss.ru>
In-Reply-To
<xmqqzgxfb80r.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 15 quoted lines
> Sergey Organov <sorganov@gmail.com> writes:
>
>>> Luckily,
>>>
>>>     $ git log [--stat] --diff-merges=first-parent master..seen
>>>
>>> seems to do almost the right thing, with respect to the "It is
>>> probably OK to special case" I gave above.
>>
>> I believe any special-casing is to be a last resort, and definitely is
>> not the right thing to do in this particular case.
>
> I do not know if I get it.  "log --diff-merges=<kind>" giving the
> same output as "log" (i.e. no trace of any kind of diff) would be
> puzzling to users, and to help them, it is OK to say that

I thought (apparently wrong) that the idea was to special-case "-m", and only "-m". I.e., if -m is alone, let it imply -p, otherwise not. That was the thing I was in opposition to.

>
>  * "--diff-merges=<kind>" enables some kind of diff output
>    automatially (for both merges and non-merges), and

No, I don't think this is OK, sorry. I fail to see why --diff-merges should affect non-merge commits. I believe it shouldn't.

>
>  * when there is no user preference given as to what kind of diff is
>    desired, we default to "-p".

What kind of diff "-p" gives for merge commits, exactly? As far as I can tell, it's "none".

Show 5 quoted lines
>
> As it is natural to expect "--stat --diff-merges=<kind> would give
> only the diffstat without patch, we end up "special casing"
> "--diff-merges=<kind>" that is given alone, without specifying what
> kind of diff is desired, and behave as if "-p" was given.

In general, I hate dependencies between options. The only thing that is actually needed for convenience is an ability for an option to imply other options. What's currently there is already too complex for my personal taste, and I'd hate to add even more complexity on top.

Right now --diff-merges is pretty simple and straightforward: it specifies diff output for merge commits, and only for merge commits. If any other option disables diff machinery altogether, it will disable diff for merges as well.

OTOH, we have --patch that deals with non-merge commits.

Personally, I don't like the resulting interface very much, but it's historical, and can't be easily changed.

> So I would have expected you to call this kind of "special casing" a
> good thing.

Well, even though I was originally commenting about -m only, I must admit I'm in general against any "special casing", unless there is extremely strong reason to consider it.

>
>>> It only "enables diff" for merge commits, which does not quite feel
>>> right and we may want to do the same "enable diff" for single parent
>>> commits,

I fail to see why --diff-merges should ever affect non-merge commits. It'd be at least counter-intuitive, not to say directly opposite to the original design goal.

>>> but the good part is that it does not blindly imply "-p".
Yep.
Show 30 quoted lines
>>>
>>> It seems to do the "enable diff" the right way by honoring other
>>> command line options that specify the format of the diff, so with
>>> "--stat" included in the sample command line above, we get the
>>> diffstat for single parent commits (because we ask for "--stat" from
>>> the command line to show it throughout the history) and also for
>>> merge commits (because --diff-merges=first-parent does *not* blindly
>>> turn the textual patch '-p' on).
>>
>> Good to know! I must admit I did nothing special in this regard, just
>> paid attention to avoid breaking any existing logic, at least knowingly.
>>
>>>
>>>> [Footnote]
>>>>
>>>> *1* They are not limited to "-p", "--stat" and "--summary", but
>>>> you'd need to also pay attention to "--raw", "--name-only", etc.)
>>>
>>> I've merged the so/log-diff-merge topic to 'master', with this
>>> (possibly) known breakage that it does not do anything for single
>>> parent commits.  We may want to fix this last mile before the
>>> release that is scheduled to happen around early June.
>>
>> I have no idea what the breakage is or could be.
>
> Because I view
>
>  * "--diff-merges" is a way to specify how merge commits are passed
>    to the diff machinery (e.g. pass nothing to the diff machinery,
>    compare only with the first parent, etc.), and

As I see it, it only defines the way they are to be represented by the diff machinery once passed to it, though it obviously depends on where we put the margin of "diff machinery".

>
>  * "--patch", "--stat", "--cc" etc are to specify if we use the diff
>    machinery and what kind of output is desired.
So, in your view, --cc output is not a product of "diff machinery"?
Show 8 quoted lines
> but we are conflating the "enable diff" feature into the former to
> match end-user expectation, if "--diff-merges" without any of the
> "--patch", "--stat", etc. enables the "--patch" output for merge
> commits, it would be confusing if we do not give the same "--patch"
> output for single-parent commits, too.
>
> But the current code gives "--patch" output only for merge commits,
> doesn't it?  E.g.

No, as far as I understand it, "--patch" output is for non-merge commits only. One can't sensibly use patch utility to pick merge commits anyway, so "--patch" makes no sense for merge commits and doesn't affect them, at least for now.

>
>     $ git log --diff-merges=first-parent master..next
>
> would give patches only for merge commits, but

It will give the output similar to what "--patch" would give for non-merge commits, yes, but in fact it's not "--patch" output, I think, so I doubt it should be called "give patches". It's just happens to be the same diff format.

Show 5 quoted lines
>
>     $ git log --stat --diff-merges=first-parent master..next
>
> would give us diffstat for all commits, including merges (against
> their first parents).

Yep, but I think it just matches the old behavior that has been always there, see below.

I'd start from the behavior even before my patches. Let's see:
  git log -n1 -p <merge_commit>
  git log -n1 --stat <merge_commit>
  git log -n1 --stat -p <merge_commit>

all give no diff no stat. No surprise for diff, though not that sure about stat, but it could be argued either way.

  git log -n1 -c <merge_commit>
does give diff output in particular format, nice!
  git log -n1 --stat -c <merge_commit>

gives stat output, but no diff! That's not what I expected at all. Effectively, this looks like --stat *disables* -c/-cc output?

Finally, the way to get both diff and stat for merge commits is... who'd guess, adding -p to the command, and that provided -p is already supposedly implied by -c (!):

  git log -n1 --stat -c -p <merge_commit>

In particular, this means that contrary to documentation, -c does not imply -p in the common sense of the word "imply", and interdependencies between all these options are already too complex to easily grok for a human being.

As for newer --diff-merges, they behave similar to -c here that seems reasonable. Overall, I still don't see any breakage introduced by --diff-merges, and it seems to behave according to its documentation, so shouldn't break any expectations either.

Getting back to the original question of letting -m imply -p, it shouldn't behave differently than -c/-cc, that do imply -p, so I don't see any significant problem that'd be added to the current status.

Right now the following two give exactly the same output:
  git log -n1 --stat -c <merge_commit>
  git log -n1 --stat -m <merge_commit>

the stat to the first parent, and it shouldn't change if we let -m "imply" -p the same way -c "implies" -p, whatever it actually means.

Best Regards,
-- Sergey Organov
Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 129 in “Why doesn't `git log -m` imply `-p`?”
  1. Alex HenrieApr 29, 2021
  2. Junio C HamanoApr 29, 2021
  3. Sergey OrganovApr 29, 2021
  4. Alex HenrieApr 29, 2021
  5. Sergey OrganovApr 29, 2021
  6. Alex HenrieApr 29, 2021
  7. Sergey OrganovApr 29, 2021
  8. Felipe ContrerasMay 4, 2021
  9. Sergey OrganovMay 4, 2021
  10. Junio C HamanoApr 29, 2021
  11. Junio C HamanoApr 30, 2021
  12. Sergey OrganovApr 30, 2021
  13. Junio C HamanoMay 1, 2021
  14. Sergey OrganovMay 3, 2021
  15. Junio C HamanoMay 4, 2021
  16. Sergey OrganovMay 4, 2021
  17. Junio C HamanoMay 4, 2021
  18. Sergey OrganovMay 4, 2021
  19. Junio C HamanoMay 5, 2021
  20. Sergey OrganovMay 5, 2021
  21. Junio C HamanoMay 6, 2021
  22. Sergey OrganovMay 6, 2021
  23. Junio C HamanoMay 6, 2021
  24. Sergey OrganovMay 6, 2021
  25. Alex HenrieMay 7, 2021
  26. Sergey OrganovMay 10, 2021
  27. Alex HenrieMay 10, 2021
  28. 0/6 diff-merges: let -m imply -pSergey Organov, May 10, 2021
  29. 1/6 t4013: add test for "git diff-index -m"Sergey Organov, May 10, 2021
  30. 2/6 diff-merges: move specific diff-index "-m" handling to diff-indexSergey Organov, May 10, 2021
  31. Junio C HamanoMay 11, 2021
  32. Junio C HamanoMay 11, 2021
  33. Junio C HamanoMay 11, 2021
  34. Sergey OrganovMay 11, 2021
  35. 3/6 git-svn: stop passing "-m" to "git rev-list"Sergey Organov, May 10, 2021
  36. 4/6 stash list: stop passing "-m" to "git list"Sergey Organov, May 10, 2021
  37. 5/6 diff-merges: rename "combined_imply_patch" to "merges_imply_patch"Sergey Organov, May 10, 2021
  38. 6/6 diff-merges: let -m imply -pSergey Organov, May 10, 2021
  39. Junio C HamanoMay 11, 2021
  40. Junio C HamanoMay 11, 2021
  41. Sergey OrganovMay 11, 2021
  42. Alex HenrieMay 11, 2021
  43. Sergey OrganovMay 11, 2021
  44. Alex HenrieMay 11, 2021
  45. Sergey OrganovMay 11, 2021
  46. Felipe ContrerasMay 12, 2021
  47. Elijah NewrenMay 11, 2021
  48. Sergey OrganovMay 11, 2021
  49. Elijah NewrenMay 11, 2021
  50. Sergey OrganovMay 11, 2021
  51. Junio C HamanoMay 11, 2021
  52. Sergey OrganovMay 11, 2021
  53. Junio C HamanoMay 11, 2021
  54. Jonathan NiederMay 19, 2021
  55. Sergey OrganovMay 20, 2021
  56. Felipe ContrerasMay 21, 2021
  57. Sergey OrganovMay 11, 2021
  58. Sergey OrganovMay 17, 2021
  59. Sergey OrganovMay 11, 2021
  60. Jonathan NiederMay 19, 2021
  61. Sergey OrganovMay 19, 2021
  62. Junio C HamanoMay 19, 2021
  63. Sergey OrganovMay 20, 2021
  64. Jonathan NiederMay 20, 2021
  65. Sergey OrganovMay 20, 2021
  66. 0/9 diff-merges: let -m imply -pSergey Organov, May 17, 2021
  67. 1/9 t4013: test that "-m" alone has no effect in "git log"Sergey Organov, May 17, 2021
  68. 4/9 t4013: test "git diff-index -m"Sergey Organov, May 17, 2021
  69. 3/9 t4013: test "git -m --stat"Sergey Organov, May 17, 2021
  70. 2/9 t4013: test "git -m --raw"Sergey Organov, May 17, 2021
  71. Bagas SanjayaMay 18, 2021
  72. Sergey OrganovMay 18, 2021
  73. 6/9 git-svn: stop passing "-m" to "git rev-list"Sergey Organov, May 17, 2021
  74. 8/9 diff-merges: rename "combined_imply_patch" to "merges_imply_patch"Sergey Organov, May 17, 2021
  75. 5/9 diff-merges: move specific diff-index "-m" handling to diff-indexSergey Organov, May 17, 2021
  76. Junio C HamanoMay 17, 2021
  77. Sergey OrganovMay 17, 2021
  78. Junio C HamanoMay 17, 2021
  79. Sergey OrganovMay 17, 2021
  80. 9/9 diff-merges: let "-m" imply "-p"Sergey Organov, May 17, 2021
  81. 7/9 stash list: stop passing "-m" to "git list"Sergey Organov, May 17, 2021
  82. Junio C HamanoMay 17, 2021
  83. Sergey OrganovMay 17, 2021
  84. Bagas SanjayaMay 18, 2021
  85. Sergey OrganovMay 18, 2021
  86. Sergey OrganovMay 18, 2021
  87. Junio C HamanoMay 18, 2021
  88. Sergey OrganovMay 18, 2021
  89. 0/9 diff-merges: let -m imply -pSergey Organov, May 19, 2021
  90. 1/9 t4013: test that "-m" alone has no effect in "git log"Sergey Organov, May 19, 2021
  91. 2/9 t4013: test "git log -m --raw"Sergey Organov, May 19, 2021
  92. 3/9 t4013: test "git log -m --stat"Sergey Organov, May 19, 2021
  93. 4/9 t4013: test "git diff-index -m"Sergey Organov, May 19, 2021
  94. 5/9 diff-merges: move specific diff-index "-m" handling to diff-indexSergey Organov, May 19, 2021
  95. 6/9 git-svn: stop passing "-m" to "git rev-list"Sergey Organov, May 19, 2021
  96. 7/9 stash list: stop passing "-m" to "git log"Sergey Organov, May 19, 2021
  97. 8/9 diff-merges: rename "combined_imply_patch" to "merges_imply_patch"Sergey Organov, May 19, 2021
  98. 9/9 diff-merges: let "-m" imply "-p"Sergey Organov, May 19, 2021
  99. 00/10 diff-merges: let -m imply -pSergey Organov, May 20, 2021
  100. 02/10 t4013: test "git log -m --raw"Sergey Organov, May 20, 2021
  101. 01/10 t4013: test that "-m" alone has no effect in "git log"Sergey Organov, May 20, 2021
  102. 03/10 t4013: test "git log -m --stat"Sergey Organov, May 20, 2021
  103. 04/10 t4013: test "git diff-tree -m"Sergey Organov, May 20, 2021
  104. 05/10 t4013: test "git diff-index -m"Sergey Organov, May 20, 2021
  105. 06/10 diff-merges: move specific diff-index "-m" handling to diff-indexSergey Organov, May 20, 2021
  106. 07/10 git-svn: stop passing "-m" to "git rev-list"Sergey Organov, May 20, 2021
  107. 08/10 stash list: stop passing "-m" to "git log"Sergey Organov, May 20, 2021
  108. 09/10 diff-merges: rename "combined_imply_patch" to "merges_imply_patch"Sergey Organov, May 20, 2021
  109. 10/10 diff-merges: let "-m" imply "-p"Sergey Organov, May 20, 2021
  110. Jonathan NiederAug 5, 2021
  111. Revert 'diff-merges: let "-m" imply "-p"'Jonathan Nieder, Aug 6, 2021
  112. Junio C HamanoAug 6, 2021
  113. Junio C HamanoAug 6, 2021
  114. Jonathan NiederAug 6, 2021
  115. Junio C HamanoAug 8, 2021
  116. Sergey OrganovAug 17, 2021
  117. Junio C HamanoAug 17, 2021
  118. Sergey OrganovAug 18, 2021
  119. Junio C HamanoAug 19, 2021
  120. Junio C HamanoAug 19, 2021
  121. Sergey OrganovAug 20, 2021
  122. Jonathan NiederAug 7, 2021
  123. Johannes SixtAug 7, 2021
  124. Jonathan NiederAug 7, 2021
  125. Junio C HamanoAug 7, 2021
  126. Jonathan NiederAug 7, 2021
  127. Junio C HamanoAug 8, 2021
  128. Sergey OrganovAug 17, 2021
  129. Sergey OrganovAug 16, 2021

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.