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
This commit is contained in:
27
read-cache.c
27
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;
|
||||
|
Reference in New Issue
Block a user