Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-01-18 01:31:26 +0300
committerJunio C Hamano <gitster@pobox.com>2023-01-18 01:31:26 +0300
commit73f69f22e590c2ddc2c6fb678a5b11d9d0ba39fa (patch)
tree3009eb67c05e69ccb782d7234cda170e24a9c459 /read-cache.c
parenta7caae2729742fc80147bca1c02ae848cb55921a (diff)
parent2f6b1eb794ee1f152c1a4b519e3b6dcecd0b487f (diff)
Merge branch 'ab/cache-api-cleanup' into ab/cache-api-cleanup-users
* ab/cache-api-cleanup: cache API: add a "INDEX_STATE_INIT" macro/function, add release_index() read-cache.c: refactor set_new_index_sparsity() for subsequent commit sparse-index API: BUG() out on NULL ensure_full_index() sparse-index.c: expand_to_path() can assume non-NULL "istate" builtin/difftool.c: { 0 }-initialize rather than using memset()
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/read-cache.c b/read-cache.c
index cf87ad7097..d191741f60 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2300,12 +2300,12 @@ static void set_new_index_sparsity(struct index_state *istate)
* If the index's repo exists, mark it sparse according to
* repo settings.
*/
- if (istate->repo) {
- prepare_repo_settings(istate->repo);
- if (!istate->repo->settings.command_requires_full_index &&
- is_sparse_index_allowed(istate, 0))
- istate->sparse_index = 1;
- }
+ if (!istate->repo)
+ return;
+ prepare_repo_settings(istate->repo);
+ if (!istate->repo->settings.command_requires_full_index &&
+ is_sparse_index_allowed(istate, 0))
+ istate->sparse_index = 1;
}
/* remember to discard_cache() before reading a different cache! */
@@ -2498,9 +2498,10 @@ int read_index_from(struct index_state *istate, const char *path,
trace_performance_enter();
if (split_index->base)
- discard_index(split_index->base);
+ release_index(split_index->base);
else
- CALLOC_ARRAY(split_index->base, 1);
+ ALLOC_ARRAY(split_index->base, 1);
+ index_state_init(split_index->base);
base_oid_hex = oid_to_hex(&split_index->base_oid);
base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
@@ -2539,7 +2540,13 @@ int is_index_unborn(struct index_state *istate)
return (!istate->cache_nr && !istate->timestamp.sec);
}
-void discard_index(struct index_state *istate)
+void index_state_init(struct index_state *istate)
+{
+ struct index_state blank = INDEX_STATE_INIT;
+ memcpy(istate, &blank, sizeof(*istate));
+}
+
+void release_index(struct index_state *istate)
{
/*
* Cache entries in istate->cache[] should have been allocated
@@ -2551,20 +2558,12 @@ void discard_index(struct index_state *istate)
validate_cache_entries(istate);
resolve_undo_clear_index(istate);
- istate->cache_nr = 0;
- istate->cache_changed = 0;
- istate->timestamp.sec = 0;
- istate->timestamp.nsec = 0;
free_name_hash(istate);
cache_tree_free(&(istate->cache_tree));
- istate->initialized = 0;
- istate->fsmonitor_has_run_once = 0;
- FREE_AND_NULL(istate->fsmonitor_last_update);
- FREE_AND_NULL(istate->cache);
- istate->cache_alloc = 0;
+ free(istate->fsmonitor_last_update);
+ free(istate->cache);
discard_split_index(istate);
free_untracked_cache(istate->untracked);
- istate->untracked = NULL;
if (istate->sparse_checkout_patterns) {
clear_pattern_list(istate->sparse_checkout_patterns);
@@ -2577,6 +2576,12 @@ void discard_index(struct index_state *istate)
}
}
+void discard_index(struct index_state *istate)
+{
+ release_index(istate);
+ index_state_init(istate);
+}
+
/*
* Validate the cache entries of this index.
* All cache entries associated with this index