summaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-04-30 04:50:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-30 04:50:26 (GMT)
commit8e97852919fa422bc5fe57bc7e71826cf2b5224d (patch)
tree9a19699763f51c205f04fe05f67282c1cccde28b /cache-tree.c
parentd250f903596ee149dffcd65e3794dbd00b62f97e (diff)
parent4589bca829a2ace58bc98876cccd7dbd2e89f732 (diff)
downloadgit-8e97852919fa422bc5fe57bc7e71826cf2b5224d.zip
git-8e97852919fa422bc5fe57bc7e71826cf2b5224d.tar.gz
git-8e97852919fa422bc5fe57bc7e71826cf2b5224d.tar.bz2
Merge branch 'ds/sparse-index-protections'
Builds on top of the sparse-index infrastructure to mark operations that are not ready to mark with the sparse index, causing them to fall back on fully-populated index that they always have worked with. * ds/sparse-index-protections: (47 commits) name-hash: use expand_to_path() sparse-index: expand_to_path() name-hash: don't add directories to name_hash revision: ensure full index resolve-undo: ensure full index read-cache: ensure full index pathspec: ensure full index merge-recursive: ensure full index entry: ensure full index dir: ensure full index update-index: ensure full index stash: ensure full index rm: ensure full index merge-index: ensure full index ls-files: ensure full index grep: ensure full index fsck: ensure full index difftool: ensure full index commit: ensure full index checkout: ensure full index ...
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/cache-tree.c b/cache-tree.c
index add1f07..45e5866 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -6,6 +6,7 @@
#include "object-store.h"
#include "replace-object.h"
#include "promisor-remote.h"
+#include "sparse-index.h"
#ifndef DEBUG_CACHE_TREE
#define DEBUG_CACHE_TREE 0
@@ -255,6 +256,24 @@ static int update_one(struct cache_tree *it,
*skip_count = 0;
+ /*
+ * If the first entry of this region is a sparse directory
+ * entry corresponding exactly to 'base', then this cache_tree
+ * struct is a "leaf" in the data structure, pointing to the
+ * tree OID specified in the entry.
+ */
+ if (entries > 0) {
+ const struct cache_entry *ce = cache[0];
+
+ if (S_ISSPARSEDIR(ce->ce_mode) &&
+ ce->ce_namelen == baselen &&
+ !strncmp(ce->name, base, baselen)) {
+ it->entry_count = 1;
+ oidcpy(&it->oid, &ce->oid);
+ return 1;
+ }
+ }
+
if (0 <= it->entry_count && has_object_file(&it->oid))
return it->entry_count;
@@ -442,6 +461,8 @@ int cache_tree_update(struct index_state *istate, int flags)
if (i)
return i;
+ ensure_full_index(istate);
+
if (!istate->cache_tree)
istate->cache_tree = cache_tree();
@@ -787,6 +808,19 @@ int cache_tree_matches_traversal(struct cache_tree *root,
return 0;
}
+static void verify_one_sparse(struct repository *r,
+ struct index_state *istate,
+ struct cache_tree *it,
+ struct strbuf *path,
+ int pos)
+{
+ struct cache_entry *ce = istate->cache[pos];
+
+ if (!S_ISSPARSEDIR(ce->ce_mode))
+ BUG("directory '%s' is present in index, but not sparse",
+ path->buf);
+}
+
static void verify_one(struct repository *r,
struct index_state *istate,
struct cache_tree *it,
@@ -809,6 +843,12 @@ static void verify_one(struct repository *r,
if (path->len) {
pos = index_name_pos(istate, path->buf, path->len);
+
+ if (pos >= 0) {
+ verify_one_sparse(r, istate, it, path, pos);
+ return;
+ }
+
pos = -pos - 1;
} else {
pos = 0;