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

Re: "git-diff-tree -R A B == git-diff-tree B A"?

From
Linus Torvalds <torvalds@osdl.org>
Date
May 20, 2005, 15:53 UTC
Message-ID
<Pine.LNX.4.58.0505200844090.2206@ppc970.osdl.org>
In-Reply-To
<7vzmupud54.fsf@assigned-by-dhcp.cox.net>
On Fri, 20 May 2005, Junio C Hamano wrote:
>
> Keep git-diff-tree output sorted in cache order on dir/file swap.
No, this is wrong.

Or rather, it is incomplete - it gets only a small subset of the interesting cases right.

You need to really teach diff-tree about directory sorting, because it is more complicated than you think.

The sorting does _not_ just affect files/directories with the same names. It affects files and directories that have the same _beginning_.

The only correct way to do name sorting is the one that fsck does in "verify_order()". To realize why, you need to realize that "A" (the directory) sorts _after_ a filename "A file", because '/' sorts after ' '.

In contrast, "A" (the directory) sorts _before_ "ABBA" (the band), because '/' sorts before 'B'.

-- 
Side note:

Btw, right now I depend on "memcmp()" doing comparisons as "unsigned
char", which is supposed to be true, but I don't know whether it's 
entirely portable. So it might be that I should implement my own 
"namecmp()" entirely from scratch.

Does anybody know if some broken system does "memcmp" ordering on signed 
chars?

		Linus
Previous: Junio C HamanoNext: Linus Torvalds
Message 5 of 9 in “"git-diff-tree -R A B == git-diff-tree B A"?”
  1. Junio C HamanoMay 20, 2005
  2. Linus TorvaldsMay 20, 2005
  3. Junio C HamanoMay 20, 2005
  4. Junio C HamanoMay 20, 2005
  5. Linus TorvaldsMay 20, 2005
  6. Linus TorvaldsMay 20, 2005
  7. Linus TorvaldsMay 20, 2005
  8. Junio C HamanoMay 20, 2005
  9. Simplify "reverse-diff" logic in the diff core.Junio C Hamano, May 20, 2005

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.