25 lines
826 B
Raw Normal View History

#ifndef SPARSE_INDEX_H__
#define SPARSE_INDEX_H__
struct index_state;
int convert_to_sparse(struct index_state *istate, int flags);
sparse-index: expand_to_path() Some users of the index API have a specific path they are looking for, but choose to use index_file_exists() to rely on the name-hash hashtable instead of doing binary search with index_name_pos(). These users only need to know a yes/no answer, not a position within the cache array. When the index is sparse, the name-hash hash table does not contain the full list of paths within sparse directories. It _does_ contain the directory names for the sparse-directory entries. Create a helper function, expand_to_path(), for intended use with the name-hash hashtable functions. The integration with name-hash.c will follow in a later change. The solution here is to use ensure_full_index() when we determine that the requested path is within a sparse directory entry. This will populate the name-hash hashtable as the index is recomputed from scratch. There may be cases where the caller is trying to find an untracked path that is not in the index but also is not within a sparse directory entry. We want to minimize the overhead for these requests. If we used index_name_pos() to find the insertion order of the path, then we could determine from that position if a sparse-directory exists. (In fact, just calling index_name_pos() in that case would lead to expanding the index to a full index.) However, this takes O(log N) time where N is the number of cache entries. To keep the performance of this call based mostly on the input string, use index_file_exists() to look for the ancestors of the path. Using the heuristic that a sparse directory is likely to have a small number of parent directories, we start from the bottom and build up. Use a string buffer to allow mutating the path name to terminate after each slash for each hashset test. Signed-off-by: Derrick Stolee <> Reviewed-by: Elijah Newren <> Signed-off-by: Junio C Hamano <>
2021-04-12 23:08:16 +02:00
* Some places in the codebase expect to search for a specific path.
* This path might be outside of the sparse-checkout definition, in
* which case a sparse-index may not contain a path for that index.
* Given an index and a path, check to see if a leading directory for
* 'path' exists in the index as a sparse directory. In that case,
* expand that sparse directory to a full range of cache entries and
* populate the index accordingly.
void expand_to_path(struct index_state *istate,
const char *path, size_t pathlen, int icase);
struct repository;
int set_sparse_index_config(struct repository *repo, int enable);