summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2021-03-30 13:10:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-03-30 19:57:45 (GMT)
commit4300f8442a276aa48d327b8371af9c2917bd3d5a (patch)
tree66e142051f6b9ec8cdc7a56306a043b5d14fea55 /read-cache.c
parent3964fc2aae7c7420a4c5da1b9530e8e8de1ed367 (diff)
downloadgit-4300f8442a276aa48d327b8371af9c2917bd3d5a.zip
git-4300f8442a276aa48d327b8371af9c2917bd3d5a.tar.gz
git-4300f8442a276aa48d327b8371af9c2917bd3d5a.tar.bz2
sparse-index: implement ensure_full_index()
We will mark an in-memory index_state as having sparse directory entries with the sparse_index bit. These currently cannot exist, but we will add a mechanism for collapsing a full index to a sparse one in a later change. That will happen at write time, so we must first allow parsing the format before writing it. Commands or methods that require a full index in order to operate can call ensure_full_index() to expand that index in-memory. This requires parsing trees using that index's repository. Sparse directory entries have a specific 'ce_mode' value. The macro S_ISSPARSEDIR(ce->ce_mode) can check if a cache_entry 'ce' has this type. This ce_mode is not possible with the existing index formats, so we don't also verify all properties of a sparse-directory entry, which are: 1. ce->ce_mode == 0040000 2. ce->flags & CE_SKIP_WORKTREE is true 3. ce->name[ce->namelen - 1] == '/' (ends in dir separator) 4. ce->oid references a tree object. These are all semi-enforced in ensure_full_index() to some extent. Any deviation will cause a warning at minimum or a failure in the worst case. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c
index 1e9a50c..dd3980c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -101,6 +101,9 @@ static const char *alternate_index_output;
static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
{
+ if (S_ISSPARSEDIR(ce->ce_mode))
+ istate->sparse_index = 1;
+
istate->cache[nr] = ce;
add_name_hash(istate, ce);
}
@@ -2273,6 +2276,12 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
trace2_data_intmax("index", the_repository, "read/cache_nr",
istate->cache_nr);
+ if (!istate->repo)
+ istate->repo = the_repository;
+ prepare_repo_settings(istate->repo);
+ if (istate->repo->settings.command_requires_full_index)
+ ensure_full_index(istate);
+
return istate->cache_nr;
unmap: