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

[PATCH 7/6] Fix thinko in subproject entry sorting

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Apr 11, 2007, 21:39 UTC
Message-ID
<Pine.LNX.4.64.0704111423420.6730@woody.linux-foundation.org>

This fixes a total thinko in my original series: subprojects do *not* sort like directories, because the index is sorted purely by full pathname, and since a subproject shows up in the index as a normal NUL-terminated string, it never has the issues with sorting with the '/' at the end.

So if you have a subproject "proj" and a file "proj.c", the subproject sorts alphabetically before the file in the index (and must thus also sort that way in a tree object, since trees sort as the index).

In contrast, it you have two files "proj/file" and "proj.c", the "proj.c" will sort alphabetically before "proj/file" in the index. The index itself, of course, does not actually contain an entry "proj/", but in the *tree* that gets written out, the tree entry "proj" will sort before the file entry "proj.c", which is the only real magic sorting rule.

In other words: the magic sorting rule only affects tree entries, and *only* affects tree entries that point to other trees (ie are of the type S_IFDIR).

Anyway, that thinko just means that we should remove the special case to make S_ISDIRLNK entries sort like S_ISDIR entries. They don't. They sort like normal files.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

Junio, you could just fix the patch that I sent out and rebase, but you seem to have merged it into "next" already, and besides, I think it's ok to have this separate correction patch just to explain *why* I was wrong to add that special case in the first place. Normally, I don't like leaving errors in the history - if they teach anybody anything, it is just to make more errors - but this may be one of the rare cases where the error was actually instructive.

		Linus
---
diff --git a/read-cache.c b/read-cache.c
index fde2427..795fc5d 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -280,9 +280,9 @@ int base_name_compare(const char *name1, int len1, int mode1,
 		return cmp;
 	c1 = name1[len];
 	c2 = name2[len];
-	if (!c1 && (S_ISDIR(mode1) || S_ISDIRLNK(mode1)))
+	if (!c1 && S_ISDIR(mode1))
 		c1 = '/';
-	if (!c2 && (S_ISDIR(mode2) || S_ISDIRLNK(mode2)))
+	if (!c2 && S_ISDIR(mode2))
 		c2 = '/';
 	return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
 }
Next: Linus Torvalds
Message 1 of 2 in “Fix thinko in subproject entry sorting”
  1. 7/6 Fix thinko in subproject entry sortingLinus Torvalds, Apr 11, 2007
  2. Linus TorvaldsApr 11, 2007

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.