aboutsummaryrefslogtreecommitdiffstats
path: root/read-cache.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-12-10 14:35:12 -0800
committerJunio C Hamano <gitster@pobox.com>2021-12-10 14:35:12 -0800
commitf0850875fd44a58cd1eae349244327b2eff29fa7 (patch)
tree184c87add4c1e39e25a289f6aed8199215e52fa6 /read-cache.c
parent4ee5cacc16ee7779017f207e496eeb75b0fa5721 (diff)
parentf2a454e0a5e26c0f7b840970f69d195c37b16565 (diff)
downloadgit-f0850875fd44a58cd1eae349244327b2eff29fa7.tar.gz
Merge branch 'vd/sparse-reset'
Various operating modes of "git reset" have been made to work better with the sparse index. * vd/sparse-reset: unpack-trees: improve performance of next_cache_entry reset: make --mixed sparse-aware reset: make sparse-aware (except --mixed) reset: integrate with sparse index reset: expand test coverage for sparse checkouts sparse-index: update command for expand/collapse test reset: preserve skip-worktree bit in mixed reset reset: rename is_missing to !is_in_reset_tree
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/read-cache.c b/read-cache.c
index d999fff9e4..cbe73f14e5 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -68,6 +68,11 @@
*/
#define CACHE_ENTRY_PATH_LENGTH 80
+enum index_search_mode {
+ NO_EXPAND_SPARSE = 0,
+ EXPAND_SPARSE = 1
+};
+
static inline struct cache_entry *mem_pool__ce_alloc(struct mem_pool *mem_pool, size_t len)
{
struct cache_entry *ce;
@@ -551,7 +556,10 @@ int cache_name_stage_compare(const char *name1, int len1, int stage1, const char
return 0;
}
-static int index_name_stage_pos(struct index_state *istate, const char *name, int namelen, int stage)
+static int index_name_stage_pos(struct index_state *istate,
+ const char *name, int namelen,
+ int stage,
+ enum index_search_mode search_mode)
{
int first, last;
@@ -570,7 +578,7 @@ static int index_name_stage_pos(struct index_state *istate, const char *name, in
first = next+1;
}
- if (istate->sparse_index &&
+ if (search_mode == EXPAND_SPARSE && istate->sparse_index &&
first > 0) {
/* Note: first <= istate->cache_nr */
struct cache_entry *ce = istate->cache[first - 1];
@@ -586,7 +594,7 @@ static int index_name_stage_pos(struct index_state *istate, const char *name, in
ce_namelen(ce) < namelen &&
!strncmp(name, ce->name, ce_namelen(ce))) {
ensure_full_index(istate);
- return index_name_stage_pos(istate, name, namelen, stage);
+ return index_name_stage_pos(istate, name, namelen, stage, search_mode);
}
}
@@ -595,7 +603,12 @@ static int index_name_stage_pos(struct index_state *istate, const char *name, in
int index_name_pos(struct index_state *istate, const char *name, int namelen)
{
- return index_name_stage_pos(istate, name, namelen, 0);
+ return index_name_stage_pos(istate, name, namelen, 0, EXPAND_SPARSE);
+}
+
+int index_entry_exists(struct index_state *istate, const char *name, int namelen)
+{
+ return index_name_stage_pos(istate, name, namelen, 0, NO_EXPAND_SPARSE) >= 0;
}
int remove_index_entry_at(struct index_state *istate, int pos)
@@ -1237,7 +1250,7 @@ static int has_dir_name(struct index_state *istate,
*/
}
- pos = index_name_stage_pos(istate, name, len, stage);
+ pos = index_name_stage_pos(istate, name, len, stage, EXPAND_SPARSE);
if (pos >= 0) {
/*
* Found one, but not so fast. This could
@@ -1337,7 +1350,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
strcmp(ce->name, istate->cache[istate->cache_nr - 1]->name) > 0)
pos = index_pos_to_insert_pos(istate->cache_nr);
else
- pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
+ pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce), EXPAND_SPARSE);
/* existing match? Just replace it. */
if (pos >= 0) {
@@ -1372,7 +1385,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
if (!ok_to_replace)
return error(_("'%s' appears as both a file and as a directory"),
ce->name);
- pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
+ pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce), EXPAND_SPARSE);
pos = -pos-1;
}
return pos + 1;