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

Re: an option to make "git-diff Z A" prints Z's diff before A's

From
Junio C Hamano <junkio@cox.net>
Date
Oct 25, 2006, 19:16 UTC
Message-ID
<7vd58g9pfs.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<871wowzx15.fsf@rho.meyering.net>
Jim Meyering <jim@meyering.net> writes:
Show 8 quoted lines
> In a recent patch set I prepared, I placed the names of the
> more relevant files at the front of the list given to "git-diff".
>...
> I know about the -O<orderfile> option, and it can make git-diff do
> what I want, but only if I first create a separate file containing
> the names that I'm already providing to git-diff in the very same order.
>
> Is there an easier way?
No, not right now.
> If not, would you be amenable to a new option enabling this behavior
> without requiring a temporary file?
The thing is, "git diff -- Z A" does *not* mean:
	I know I have a file called Z and a file called A;
	please give diff for these files.
What it means is:
	Please give me the diff as usual, but I care about paths
	that match these patterns, Z or A.

So "git diff -- Documentation" names all changed files in that directory; you could also spell it "Documentation/" for clarity.

git-diff traverses two tree-like things (either tree-vs-tree, tree-vs-index, or tree-vs-working tree) in parallel in the canonical order, but skips comparing paths that do not match the list of patterns you gave on the command line. While it does so, we do not record which pattern caused the path to be included in the output anywhere, so there currently is no way to tell which ones matched an earlier pattern and which ones matched a later one.

If somebody wants to do this, the place to modify would be the following:

 - add a new parameter, "int match_number", to change_fn_t and
   add_remove_fn_t functions, and add a new member to struct
   diff_filepair to record it.
 - update all callers of diff_addremove, diff_change, and
   diff_unmerge to pass which pathspec the user gave on the
   command line matched the path to be included (in your example
   if both Z and A were directory, file Z/foo gets number 1 and
   file A/bar gets number 2).
 - update diff_addremove, diff_change and diff_unmerge to pass
   that match_number to diff_queue(), and make diff_queue()
   record the number in the new diff_filepair it creates.
 - in places where an existing filepair is split into two and
   two existing filepairs are merged into one (e.g. "break" and
   "rename"), make sure match_number is propagated sensibly from
   the original filepairs to the modified ones.
 - in diffcore_std(), if orderfile is not in use, use the
   match_number to sort the queued filepairs.
Previous: Jim MeyeringNext: Karl Hasselström
Message 2 of 4 in “an option to make "git-diff Z A" prints Z's diff before A's”
  1. Jim MeyeringOct 25, 2006
  2. Junio C HamanoOct 25, 2006
  3. Karl HasselströmOct 26, 2006
  4. Linus TorvaldsOct 26, 2006

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.