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>
This commit is contained in:

committed by
Junio C Hamano

parent
3964fc2aae
commit
4300f8442a
13
cache.h
13
cache.h
@ -204,6 +204,8 @@ struct cache_entry {
|
||||
#error "CE_EXTENDED_FLAGS out of range"
|
||||
#endif
|
||||
|
||||
#define S_ISSPARSEDIR(m) ((m) == S_IFDIR)
|
||||
|
||||
/* Forward structure decls */
|
||||
struct pathspec;
|
||||
struct child_process;
|
||||
@ -319,7 +321,14 @@ struct index_state {
|
||||
drop_cache_tree : 1,
|
||||
updated_workdir : 1,
|
||||
updated_skipworktree : 1,
|
||||
fsmonitor_has_run_once : 1;
|
||||
fsmonitor_has_run_once : 1,
|
||||
|
||||
/*
|
||||
* sparse_index == 1 when sparse-directory
|
||||
* entries exist. Requires sparse-checkout
|
||||
* in cone mode.
|
||||
*/
|
||||
sparse_index : 1;
|
||||
struct hashmap name_hash;
|
||||
struct hashmap dir_hash;
|
||||
struct object_id oid;
|
||||
@ -722,6 +731,8 @@ int read_index_from(struct index_state *, const char *path,
|
||||
const char *gitdir);
|
||||
int is_index_unborn(struct index_state *);
|
||||
|
||||
void ensure_full_index(struct index_state *istate);
|
||||
|
||||
/* For use with `write_locked_index()`. */
|
||||
#define COMMIT_LOCK (1 << 0)
|
||||
#define SKIP_IF_UNCHANGED (1 << 1)
|
||||
|
Reference in New Issue
Block a user