Skip to content

Commit a98f7fb

Browse files
rscharfegitster
authored andcommitted
read-cache: remove bogus shortcut
has_dir_name() has some optimizations for the case where entries are added to an index in the correct order. They kick in if the new entry sorts after the last one. One of them exits early if the last entry has a longer name than the directory of the new entry. Here's its comment: /* * The directory prefix lines up with part of * a longer file or directory name, but sorts * after it, so this sub-directory cannot * collide with a file. * * last: xxx/yy-file (because '-' sorts before '/') * this: xxx/yy/abc */ However, a file named xxx/yy would be sorted before xxx/yy-file because '-' sorts after NUL, so the length check against the last entry is not sufficient to rule out a collision. Remove it. Reported-by: SZEDER Gábor <[email protected]> Suggested-by: SZEDER Gábor <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af6b65d commit a98f7fb

File tree

1 file changed

+0
-14
lines changed

1 file changed

+0
-14
lines changed

read-cache.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,20 +1171,6 @@ static int has_dir_name(struct index_state *istate,
11711171
return retval;
11721172
}
11731173

1174-
if (istate->cache_nr > 0 &&
1175-
ce_namelen(istate->cache[istate->cache_nr - 1]) > len) {
1176-
/*
1177-
* The directory prefix lines up with part of
1178-
* a longer file or directory name, but sorts
1179-
* after it, so this sub-directory cannot
1180-
* collide with a file.
1181-
*
1182-
* last: xxx/yy-file (because '-' sorts before '/')
1183-
* this: xxx/yy/abc
1184-
*/
1185-
return retval;
1186-
}
1187-
11881174
/*
11891175
* This is a possible collision. Fall through and
11901176
* let the regular search code handle it.

0 commit comments

Comments
 (0)