1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-04 21:46:12 +02:00

sparse-index: add guard to ensure full index

Upcoming changes will introduce modifications to the index format that
allow sparse directories. It will be useful to have a mechanism for
converting those sparse index files into full indexes by walking the
tree at those sparse directories. Name this method ensure_full_index()
as it will guarantee that the index is fully expanded.

This method is not implemented yet, and instead we focus on the
scaffolding to declare it and call it at the appropriate time.

Add a 'command_requires_full_index' member to struct repo_settings. This
will be an indicator that we need the index in full mode to do certain
index operations. This starts as being true for every command, then we
will set it to false as some commands integrate with sparse indexes.

If 'command_requires_full_index' is true, then we will immediately
expand a sparse index to a full one upon reading from disk. This
suffices for now, but we will want to add more callers to
ensure_full_index() later.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Derrick Stolee 2021-03-30 13:10:47 +00:00 committed by Junio C Hamano
parent 4b3f765a2f
commit 3964fc2aae
6 changed files with 36 additions and 1 deletions

View File

@ -985,6 +985,7 @@ LIB_OBJS += setup.o
LIB_OBJS += shallow.o
LIB_OBJS += sideband.o
LIB_OBJS += sigchain.o
LIB_OBJS += sparse-index.o
LIB_OBJS += split-index.o
LIB_OBJS += stable-qsort.o
LIB_OBJS += strbuf.o

View File

@ -77,4 +77,12 @@ void prepare_repo_settings(struct repository *r)
UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP);
UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_DEFAULT);
/*
* This setting guards all index reads to require a full index
* over a sparse index. After suitable guards are placed in the
* codebase around uses of the index, this setting will be
* removed.
*/
r->settings.command_requires_full_index = 1;
}

View File

@ -10,6 +10,7 @@
#include "object.h"
#include "lockfile.h"
#include "submodule-config.h"
#include "sparse-index.h"
/* The main repository */
static struct repository the_repo;
@ -261,6 +262,8 @@ void repo_clear(struct repository *repo)
int repo_read_index(struct repository *repo)
{
int res;
if (!repo->index)
repo->index = xcalloc(1, sizeof(*repo->index));
@ -270,7 +273,13 @@ int repo_read_index(struct repository *repo)
else if (repo->index->repo != repo)
BUG("repo's index should point back at itself");
return read_index_from(repo->index, repo->index_file, repo->gitdir);
res = read_index_from(repo->index, repo->index_file, repo->gitdir);
prepare_repo_settings(repo);
if (repo->settings.command_requires_full_index)
ensure_full_index(repo->index);
return res;
}
int repo_hold_locked_index(struct repository *repo,

View File

@ -41,6 +41,8 @@ struct repo_settings {
enum fetch_negotiation_setting fetch_negotiation_algorithm;
int core_multi_pack_index;
unsigned command_requires_full_index:1;
};
struct repository {

8
sparse-index.c Normal file
View File

@ -0,0 +1,8 @@
#include "cache.h"
#include "repository.h"
#include "sparse-index.h"
void ensure_full_index(struct index_state *istate)
{
/* intentionally left blank */
}

7
sparse-index.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef SPARSE_INDEX_H__
#define SPARSE_INDEX_H__
struct index_state;
void ensure_full_index(struct index_state *istate);
#endif