]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sparse-index: add guard to ensure full index
authorDerrick Stolee <dstolee@microsoft.com>
Tue, 30 Mar 2021 13:10:47 +0000 (13:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Mar 2021 19:57:45 +0000 (12:57 -0700)
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>
Makefile
repo-settings.c
repository.c
repository.h
sparse-index.c [new file with mode: 0644]
sparse-index.h [new file with mode: 0644]

index dfb0f1000fa311baf10292f6b7e7a1cf7c4902c8..89b1d5374107b36b6a3978e388d200b2c3c5add8 100644 (file)
--- 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
index f7fff0f5ab837e05cd369ed7630e8e2648e9aba8..d63569e4041eca4946a23903309ca5d40bab7dea 100644 (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;
 }
index c98298acd017b551894f838e2000b253b271202e..a8acae002f712cafaf57c5954ccdc44c53c6e5a4 100644 (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,
index b385ca3c94b62b2095b0ddb1b2b7adcce037da9a..e06a23015697228b8070c806a60cb12468ef7e92 100644 (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 {
diff --git a/sparse-index.c b/sparse-index.c
new file mode 100644 (file)
index 0000000..82183ea
--- /dev/null
@@ -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 (file)
index 0000000..09a20d0
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef SPARSE_INDEX_H__
+#define SPARSE_INDEX_H__
+
+struct index_state;
+void ensure_full_index(struct index_state *istate);
+
+#endif