@matheusbsbs / matheus-bagliano / commits / a98f7fb366
Fork 0

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 <szeder.dev@gmail.com> Suggested-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 16, 2020 at 19:11 UTC a98f7fb36679a98caa0b804d567b6b2fa8f8ef41
1 file changed -14
read-cache.c
-14
@@ -1171,20 +1171,6 @@ static int has_dir_name(struct index_state *istate,
1171 return retval;
1172 }
1173
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 -
1174 /*
1175 * This is a possible collision. Fall through and
1176 * let the regular search code handle it.