| 59 | } |
| 60 | |
| 61 | static struct dir_entry *hash_dir_entry(struct index_state *istate, |
| 62 | struct cache_entry *ce, int namelen) |
| 63 | { |
| 64 | /* |
| 65 | * Throw each directory component in the hash for quick lookup |
| 66 | * during a git status. Directory components are stored without their |
| 67 | * closing slash. Despite submodules being a directory, they never |
| 68 | * reach this point, because they are stored |
| 69 | * in index_state.name_hash (as ordinary cache_entries). |
| 70 | */ |
| 71 | struct dir_entry *dir; |
| 72 | |
| 73 | /* get length of parent directory */ |
| 74 | while (namelen > 0 && !is_dir_sep(ce->name[namelen - 1])) |
| 75 | namelen--; |
| 76 | if (namelen <= 0) |
| 77 | return NULL; |
| 78 | namelen--; |
| 79 | |
| 80 | /* lookup existing entry for that directory */ |
| 81 | dir = find_dir_entry(istate, ce->name, namelen); |
| 82 | if (!dir) { |
| 83 | /* not found, create it and add to hash table */ |
| 84 | FLEX_ALLOC_MEM(dir, name, ce->name, namelen); |
| 85 | hashmap_entry_init(&dir->ent, memihash(ce->name, namelen)); |
| 86 | dir->namelen = namelen; |
| 87 | hashmap_add(&istate->dir_hash, &dir->ent); |
| 88 | |
| 89 | /* recursively add missing parent directories */ |
| 90 | dir->parent = hash_dir_entry(istate, ce, namelen); |
| 91 | } |
| 92 | return dir; |
| 93 | } |
| 94 | |
| 95 | static void add_dir_entry(struct index_state *istate, struct cache_entry *ce) |
| 96 | { |
no test coverage detected