| 1365 | } |
| 1366 | |
| 1367 | static struct cache_entry *find_cache_entry(struct traverse_info *info, |
| 1368 | const struct name_entry *p) |
| 1369 | { |
| 1370 | const char *path; |
| 1371 | int pos = find_cache_pos(info, p->path, p->pathlen); |
| 1372 | struct unpack_trees_options *o = info->data; |
| 1373 | |
| 1374 | if (0 <= pos) |
| 1375 | return o->src_index->cache[pos]; |
| 1376 | |
| 1377 | /* |
| 1378 | * Check for a sparse-directory entry named "path/". |
| 1379 | * Due to the input p->path not having a trailing |
| 1380 | * slash, the negative 'pos' value overshoots the |
| 1381 | * expected position, hence "-2" instead of "-1". |
| 1382 | */ |
| 1383 | pos = -pos - 2; |
| 1384 | |
| 1385 | if (pos < 0 || pos >= o->src_index->cache_nr) |
| 1386 | return NULL; |
| 1387 | |
| 1388 | /* |
| 1389 | * Due to lexicographic sorting and sparse directory |
| 1390 | * entries ending with a trailing slash, our path as a |
| 1391 | * sparse directory (e.g "subdir/") and our path as a |
| 1392 | * file (e.g. "subdir") might be separated by other |
| 1393 | * paths (e.g. "subdir-"). |
| 1394 | */ |
| 1395 | while (pos >= 0) { |
| 1396 | struct cache_entry *ce = o->src_index->cache[pos]; |
| 1397 | |
| 1398 | if (!skip_prefix(ce->name, info->traverse_path, &path) || |
| 1399 | strncmp(path, p->path, p->pathlen) || |
| 1400 | path[p->pathlen] != '/') |
| 1401 | return NULL; |
| 1402 | |
| 1403 | if (S_ISSPARSEDIR(ce->ce_mode) && |
| 1404 | sparse_dir_matches_path(ce, info, p)) |
| 1405 | return ce; |
| 1406 | |
| 1407 | pos--; |
| 1408 | } |
| 1409 | |
| 1410 | return NULL; |
| 1411 | } |
| 1412 | |
| 1413 | static void debug_path(struct traverse_info *info) |
| 1414 | { |
no test coverage detected