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:
authorDerrick Stolee <dstolee@microsoft.com>2021-03-30 16:10:47 +0300
committerJunio C Hamano <gitster@pobox.com>2021-03-30 22:57:45 +0300
commit3964fc2aae7c7420a4c5da1b9530e8e8de1ed367 (patch)
tree6b4872a266678c396757fcaa36c89351671a23b9
parent4b3f765a2f38064c0bb221c76c7bb4f28f94a9dc (diff)
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>
-rw-r--r--Makefile1
-rw-r--r--repo-settings.c8
-rw-r--r--repository.c11
-rw-r--r--repository.h2
-rw-r--r--sparse-index.c8
-rw-r--r--sparse-index.h7
6 files changed, 36 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index dfb0f1000f..89b1d53741 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/repo-settings.c b/repo-settings.c
index f7fff0f5ab..d63569e404 100644
--- a/repo-settings.c
+++ b/repo-settings.c
@@ -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;
}
diff --git a/repository.c b/repository.c
index c98298acd0..a8acae002f 100644
--- a/repository.c
+++ b/repository.c
@@ -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,
diff --git a/repository.h b/repository.h
index b385ca3c94..e06a230156 100644
--- a/repository.h
+++ b/repository.h
@@ -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 {
diff --git a/sparse-index.c b/sparse-index.c
new file mode 100644
index 0000000000..82183ead56
--- /dev/null
+++ b/sparse-index.c
@@ -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 */
+}
diff --git a/sparse-index.h b/sparse-index.h
new file mode 100644
index 0000000000..09a20d036c
--- /dev/null
+++ b/sparse-index.h
@@ -0,0 +1,7 @@
+#ifndef SPARSE_INDEX_H__
+#define SPARSE_INDEX_H__
+
+struct index_state;
+void ensure_full_index(struct index_state *istate);
+
+#endif