Commit 1833a925 authored by Linus Torvalds's avatar Linus Torvalds Committed by Junio C Hamano

Fix thinko in subproject entry sorting

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 after 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

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: default avatarLinus Torvalds <>
Signed-off-by: default avatarJunio C Hamano <>
parent f35a6d3b
......@@ -277,9 +277,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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment