summaryrefslogtreecommitdiff
path: root/sparse-index.h
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2021-04-12 21:08:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-14 20:47:54 (GMT)
commit71f82d032f34f7aa3708b4cdaeb12db617449606 (patch)
tree1bee2c9735b6930ba12df0e06337ced48b71f253 /sparse-index.h
parent5f116695864788d1fe45ff06bfad7a71a8d98d0a (diff)
downloadgit-71f82d032f34f7aa3708b4cdaeb12db617449606.zip
git-71f82d032f34f7aa3708b4cdaeb12db617449606.tar.gz
git-71f82d032f34f7aa3708b4cdaeb12db617449606.tar.bz2
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 <dstolee@microsoft.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sparse-index.h')
-rw-r--r--sparse-index.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/sparse-index.h b/sparse-index.h
index 0268f38..1115a0d 100644
--- a/sparse-index.h
+++ b/sparse-index.h
@@ -4,6 +4,19 @@
struct index_state;
int convert_to_sparse(struct index_state *istate);
+/*
+ * 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);