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

Re: Can we clarify the purpose of `git diff -s`?

From
Junio C Hamano <gitster@pobox.com>
Date
May 11, 2023, 16:26 UTC
Message-ID
<xmqqpm76ygum.fsf@gitster.g>
In-Reply-To
<871qjn2i63.fsf@osv.gnss.ru>
Sergey Organov <sorganov@gmail.com> writes:
Show 5 quoted lines
> That said, there is another mystery in the diff interface as well: why
> do we have --patch-with-raw and --patch-with-stat, yet no
> --raw-with-stat, --numstat-with-shortstat, --patch-with-numstat, etc.?
> If, say, --patch turned off everything except usual diff output, then
> these combinatorical options would make sense, but currently they don't.

I can explain the mystery but the explanation may or may not justify it, depending on how lenient you are to developers of old days, with less experience than they have today ;-).

Back when we started, "--raw" was the only thing there, and then we were to pass the raw-to-patch external filter, when you wanted a patch output. I then updated this arrangement to work in a single process [*] without having to produce textual hexadecimal output (raw) and piping it to another process, and that is how "--patch" mode was created [*].

After I added "--patch", without having foresight of the risk of the combinatorial explosion, "--patch-with-raw" was born. "--stat" and other niceties came much later, and made me finally realize the risk of the combinatorial explosion. "--patch-with-raw" stopped gaining siblings as a consequence.

Yes, I was slow and inexperienced, but one has to do with the capability one has at the time.

Show 5 quoted lines
> Finally, there is another intrinsic problem in current Git CI: the
> "defaults to" part, as in "git show" that defaults to --patch for simple
> commits, --cc for merge commits, etc., except that it doesn't behave as
> if these options were explicitly provided at the beginning of the
> command-line.

Yes, as you said in your message after this part, this is pretty much deliberate and is done for the sake of usability. Essentially the logic is to achieve two distinct goals:

 * we want to be able to combine the basic things like --patch,
   --raw, --stat to specify exact format (but some things may not
   mix well with others).
 * when the user does not give a specific preference, we want to
   give a reasonable default.

So, when the user wants "--stat", we do not want to combine it with "--patch" that the user may have gotten by default if they did not give "--stat". If we implemented the default logic like the way (I guess) you are suggesting, i.e.

 * there is a default set of options, "--patch".
 * the user can add or subtract options with "--[no-]foo" where the
   value of foo may be patch, stat, etc.

it would turn it to "--patch --stat" if the user gave "--stat" on the command line. The user needs to say "--no-patch --stat" if they want to see only the diffstat (which by itself is not necessarily bad; if it is more common to want --patch-with-stat than --stat, it may even be better), but the bad part is that the user need to remember what the built-in default is.

[Footnote]
* Not exactly a "single process"; until Linus imported xdiff
  machinery to make the textual patch generation in-process, we
  forked "diff -u" as a subprocess inside "git diff-*".  But the end
  user no longer had to construct the "git diff-files | raw-to-patch"
  pipeline themselves.
* Eventually it would become the in-process "diffcore transformation
  pipeline" to compute diff_queue, which is a moral equivalent of
  the input to "raw-to-patch filter", then transform the result of
  the previous step (e.g. rename detection) and then format the
  result of the previous step into various output, but none of that
  existed back then.
Previous: Sergey OrganovNext: Junio C Hamano
Message 3 of 39 in “Can we clarify the purpose of `git diff -s`?”
  1. Felipe ContrerasMay 11, 2023
  2. Sergey OrganovMay 11, 2023
  3. Junio C HamanoMay 11, 2023
  4. Junio C HamanoMay 11, 2023
  5. Sergey OrganovMay 11, 2023
  6. Junio C HamanoMay 11, 2023
  7. Felipe ContrerasMay 11, 2023
  8. Felipe ContrerasMay 11, 2023
  9. Felipe ContrerasMay 11, 2023
  10. Sergey OrganovMay 11, 2023
  11. Felipe ContrerasMay 11, 2023
  12. Sergey OrganovMay 11, 2023
  13. Felipe ContrerasMay 11, 2023
  14. Sergey OrganovMay 11, 2023
  15. Felipe ContrerasMay 11, 2023
  16. Sergey OrganovMay 11, 2023
  17. Felipe ContrerasMay 11, 2023
  18. Sergey OrganovMay 12, 2023
  19. Felipe ContrerasMay 12, 2023
  20. Matthieu MoyMay 12, 2023
  21. Junio C HamanoMay 12, 2023
  22. Sergey OrganovMay 12, 2023
  23. Junio C HamanoMay 12, 2023
  24. Junio C HamanoMay 12, 2023
  25. Felipe ContrerasMay 12, 2023
  26. Junio C HamanoMay 12, 2023
  27. Felipe ContrerasMay 12, 2023
  28. Junio C HamanoMay 12, 2023
  29. Junio C HamanoMay 12, 2023
  30. Felipe ContrerasMay 12, 2023
  31. Sergey OrganovMay 12, 2023
  32. Junio C HamanoMay 12, 2023
  33. Sergey OrganovMay 12, 2023
  34. Felipe ContrerasMay 12, 2023
  35. Philip OakleyMay 13, 2023
  36. Sergey OrganovMay 13, 2023
  37. Felipe ContrerasMay 12, 2023
  38. Felipe ContrerasMay 12, 2023
  39. Felipe ContrerasMay 12, 2023

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.