Skip to content

[DO NOT MERGE] sparse index prototype #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
e21f62a
t6407: modernise tests
agrn Nov 24, 2020
4155a98
t6060: modify multiple files to expose a possible issue with merge-index
agrn Nov 24, 2020
6c0f49d
update-index: move add_cacheinfo() to read-cache.c
agrn Nov 24, 2020
db3215f
merge-one-file: rewrite in C
agrn Nov 24, 2020
43b10e3
merge-index: libify merge_one_path() and merge_all()
agrn Nov 24, 2020
9139526
merge-index: don't fork if the requested program is `git-merge-one-file'
agrn Nov 24, 2020
778da2d
merge-resolve: rewrite in C
agrn Nov 24, 2020
eb73c32
merge-recursive: move better_branch_name() to merge.c
agrn Nov 24, 2020
72a7464
merge-octopus: rewrite in C
agrn Nov 24, 2020
c4f3e45
merge: use the "resolve" strategy without forking
agrn Nov 24, 2020
9dccc61
merge: use the "octopus" strategy without forking
agrn Nov 24, 2020
c4ba24e
sequencer: use the "resolve" strategy without forking
agrn Nov 24, 2020
3da8920
sequencer: use the "octopus" merge strategy without forking
agrn Nov 24, 2020
0e500c8
tree-walk: report recursion counts
derrickstolee Dec 23, 2020
4157b91
unpack-trees: add trace2 regions
derrickstolee Dec 30, 2020
8959d57
cache-tree: use trace2 in cache_tree_update()
derrickstolee Dec 30, 2020
1d8a797
cache-tree: trace regions for I/O
derrickstolee Dec 30, 2020
2b2e70b
cache-tree: trace regions for prime_cache_tree
derrickstolee Dec 30, 2020
da8be8c
tree-walk: report recursion counts
derrickstolee Jan 4, 2021
c338898
unpack-trees: add trace2 regions
derrickstolee Jan 4, 2021
fa7ca5d
cache-tree: use trace2 in cache_tree_update()
derrickstolee Jan 4, 2021
5ccc464
mv: remove index compatibility macros
derrickstolee Dec 31, 2020
e715c70
rm: remove compatilibity macros
derrickstolee Dec 31, 2020
2d7b18c
index-format: use 'cache tree' over 'cached tree'
derrickstolee Jan 7, 2021
c5cffb5
index-format: update preamble to cache tree extension
derrickstolee Dec 30, 2020
97c06c8
index-format: discuss recursion of cached-tree better
derrickstolee Dec 30, 2020
2532f5c
cache-tree: use ce_namelen() instead of strlen()
rscharfe Jan 2, 2021
7c1c206
cache-tree: speed up consecutive path comparisons
derrickstolee Jan 4, 2021
f60f34a
update-index: drop the_index, the_repository
derrickstolee Dec 31, 2020
b8fcdd8
update-index: use istate->cache over active_cache
derrickstolee Dec 31, 2020
586371e
update-index: use istate->cache_nr over active_nr
derrickstolee Dec 31, 2020
f450f43
update-index: use istate->cache_changed
derrickstolee Dec 31, 2020
fc640ae
update-index: use index_name_pos() over cache_name_pos()
derrickstolee Dec 31, 2020
2eead83
update-index: use remove_file_from_index()
derrickstolee Dec 31, 2020
8016b08
update-index: use add_index_entry()
derrickstolee Dec 31, 2020
efe9fdd
update-index: replace several compatibility macros
derrickstolee Dec 31, 2020
e9d4fa6
update-index: remove ce_match_stat(), all macros
derrickstolee Dec 31, 2020
4754a92
update-index: reduce static globals, part 1
derrickstolee Jan 5, 2021
a9185af
update-index: reduce static globals, part 2
derrickstolee Jan 5, 2021
414ef81
update-index: remove static globals from callbacks
derrickstolee Jan 5, 2021
620fd40
Merge branch 'cache-tree/basics' into sparse-index/base
derrickstolee Jan 8, 2021
4c3e187
cache-tree: trace regions for I/O
derrickstolee Jan 4, 2021
0e5c950
cache-tree: trace regions for prime_cache_tree
derrickstolee Jan 4, 2021
845d15d
index-format: use 'cache tree' over 'cached tree'
derrickstolee Jan 7, 2021
22ad860
index-format: update preamble to cache tree extension
derrickstolee Jan 7, 2021
4bdde33
index-format: discuss recursion of cache-tree better
derrickstolee Jan 7, 2021
0b72536
cache-tree: use ce_namelen() instead of strlen()
rscharfe Jan 7, 2021
a4b6d20
cache-tree: speed up consecutive path comparisons
derrickstolee Jan 7, 2021
4c29a84
Merge branch 'sparse-index/base' into sparse-index/vfs
derrickstolee Jan 20, 2021
e4e702d
move t1092 to t9910
derrickstolee Jan 20, 2021
bdc8ecc
cache-tree: clean up cache_tree_update()
derrickstolee Jan 8, 2021
1b8b568
cache-tree: simplify verify_cache() prototype
derrickstolee Jan 23, 2021
314b6b3
cache-tree: extract subtree_pos()
derrickstolee Jan 12, 2021
4e688d2
fsmonitor: de-duplicate BUG()s around dirty bits
derrickstolee Dec 30, 2020
6373997
repository: add repo reference to index_state
derrickstolee Jan 8, 2021
9b545d7
name-hash: use trace2 regions for init
derrickstolee Jan 11, 2021
554cc76
sparse-checkout: load sparse-checkout patterns
derrickstolee Jan 8, 2021
b37181b
test-lib: test_region looks for trace2 regions
derrickstolee Jan 11, 2021
72f9253
t1092: test interesting sparse-checkout scenarios
derrickstolee Jan 8, 2021
3e5328e
sparse-index: add guard to ensure full index
derrickstolee Jan 8, 2021
7da4398
sparse-index: implement ensure_full_index()
derrickstolee Jan 8, 2021
0b8ab7d
t1092: compare sparse-checkout to sparse-index
derrickstolee Jan 15, 2021
047824a
test-read-cache: print cache entries with --table
derrickstolee Dec 18, 2020
b7e8d14
test-tool: read-cache --table --no-stat
derrickstolee Jan 6, 2021
0d41da3
test-tool: don't force full index
derrickstolee Jan 7, 2021
d6eca6e
unpack-trees: ensure full index
derrickstolee Jan 19, 2021
c4d3fb9
sparse-checkout: hold pattern list in index
derrickstolee Jan 12, 2021
fb9b605
sparse-index: convert from full to sparse
derrickstolee Jan 8, 2021
fa4efeb
submodule: sparse-index should not collapse links
derrickstolee Jan 11, 2021
dd45cc4
unpack-trees: allow sparse directories
derrickstolee Jan 5, 2021
0673161
sparse-index: check index conversion happens
derrickstolee Jan 8, 2021
a8c6c04
sparse-index: create extension for compatibility
derrickstolee Jan 13, 2021
6a68037
sparse-checkout: toggle sparse index from builtin
derrickstolee Jan 13, 2021
bd2ea69
SERIES-BREAK:sparse-index/format
derrickstolee Jan 13, 2021
2cfd9d5
sparse-checkout: ensure full index
derrickstolee Jan 13, 2021
d336cc8
blame: ensure full index
derrickstolee Dec 30, 2020
307782d
diff-lib: ensure full index in run_diff_files()
derrickstolee Dec 30, 2020
d4cd8f3
dir.c: ensure full index when necessary
derrickstolee Dec 30, 2020
cf971ce
entry.c: ensure full index
derrickstolee Dec 30, 2020
665b776
fsmonitor: ensure full index
derrickstolee Dec 30, 2020
ab4e918
merge-recursive: ensure full index
derrickstolee Dec 30, 2020
f95cccf
name-hash.c: ensure full index
derrickstolee Dec 30, 2020
0bfcbd9
pathspec.c: ensure full index
derrickstolee Dec 30, 2020
e0ec076
read-cache.c: ensure full index
derrickstolee Dec 30, 2020
7b6bdb8
rerere: ensure full index
derrickstolee Dec 31, 2020
aed420c
resolve-undo: ensure full index
derrickstolee Dec 31, 2020
a32deec
sha1-name.c: ensure full index
derrickstolee Dec 31, 2020
675c67a
split-index: ensure full index
derrickstolee Dec 31, 2020
cd3a923
submodule.c: ensure full index
derrickstolee Dec 31, 2020
e454123
tree.c: ensure full index
derrickstolee Dec 31, 2020
110ef04
wt-status.c: ensure full index
derrickstolee Dec 31, 2020
69c4207
grep: ensure full index
derrickstolee Dec 31, 2020
52d8816
ls-files: ensure full index
derrickstolee Dec 31, 2020
7dda065
apply.c: ensure full index
derrickstolee Dec 31, 2020
457b990
diff.c: ensure full index
derrickstolee Dec 31, 2020
44afa1d
checkout-index: ensure full index
derrickstolee Dec 31, 2020
9b2a51e
merge-index: ensure full index
derrickstolee Dec 31, 2020
d82d7f0
mv: ensure full index
derrickstolee Dec 31, 2020
ff252c7
rm: ensure full index
derrickstolee Dec 31, 2020
d239af1
update-index: ensure full index
derrickstolee Dec 31, 2020
365d900
SERIES-BREAK:sparse-index/ensure-full-index
derrickstolee Jan 13, 2021
6bb0c96
unpack-trees: make sparse aware
derrickstolee Jan 11, 2021
87793be
dir.c: accept a directory as part of cone-mode patterns
derrickstolee Jan 11, 2021
d226dcc
status: use sparse-index throughout
derrickstolee Jan 8, 2021
a2be8a0
status: skip sparse-checkout percentage with sparse-index
derrickstolee Jan 15, 2021
672a9e1
sparse-index: expand_to_path() trivial implementation
derrickstolee Jan 11, 2021
f2757ae
sparse-index: expand_to_path no-op if path exists
derrickstolee Jan 11, 2021
169f79a
add: allow operating on a sparse-only index
derrickstolee Jan 12, 2021
6e96ea0
submodule: die_path_inside_submodule is sparse aware
derrickstolee Jan 13, 2021
5bae98d
dir: use expand_to_path
derrickstolee Jan 12, 2021
5a1b4a1
fsmonitor: disable if index is sparse
derrickstolee Jan 15, 2021
c723d14
pathspec: stop calling ensure_full_index
derrickstolee Jan 12, 2021
7325c28
t1092: use GIT_TEST_SPARSE_INDEX=0 when needed
derrickstolee Jan 12, 2021
03b5fab
SERIES-BREAK:sparse-index/status-add
derrickstolee Jan 13, 2021
7e58338
cache-tree: integrate with sparse directory entries
derrickstolee Jan 13, 2021
04450b1
SERIES-BREAK:sparse-index/cache-tree
derrickstolee Jan 13, 2021
084aa10
Merge branch 'sparse-index/prototype' into sparse-index/vfs
derrickstolee Jan 25, 2021
796d6bc
sparse-index: cross-platform and vfs-related fixups
derrickstolee Jan 20, 2021
c3b46c4
sparse-index: static analysis fixups
derrickstolee Jan 20, 2021
2d0b615
fix the_index references
derrickstolee Jan 25, 2021
bd3fb1a
fixup! test-read-cache: print cache entries with --table
derrickstolee Jan 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Documentation/config/extensions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ extensions.objectFormat::
Note that this setting should only be set by linkgit:git-init[1] or
linkgit:git-clone[1]. Trying to change it after initialization will not
work and will produce hard-to-diagnose issues.

extensions.sparseIndex::
When combined with `core.sparseCheckout=true` and
`core.sparseCheckoutCone=true`, the index may contain entries
corresponding to directories outside of the sparse-checkout
definition. Versions of Git that do not understand this extension
do not expect directory entries in the index.
14 changes: 14 additions & 0 deletions Documentation/git-sparse-checkout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ To avoid interfering with other worktrees, it first enables the
When `--cone` is provided, the `core.sparseCheckoutCone` setting is
also set, allowing for better performance with a limited set of
patterns (see 'CONE PATTERN SET' below).
+
Use the `--[no-]sparse-index` option to toggle the use of the sparse
index format. This reduces the size of the index to be more closely
aligned with your sparse-checkout definition. This can have significant
performance advantages for commands such as `git status` or `git add`.
This feature is still experimental. Some commands might be slower with
a sparse index until they are properly integrated with the feature.
+
**WARNING:** Using a sparse index requires modifying the index in a way
that is not completely understood by other tools. Enabling sparse index
enables the `extensions.spareseIndex` config value, which might cause
other tools to stop working with your repository. If you have trouble with
this compatibility, then run `git sparse-checkout sparse-index disable` to
remove this config and rewrite your index to not be sparse.

'set'::
Write a set of patterns to the sparse-checkout file, as given as
Expand Down
42 changes: 32 additions & 10 deletions Documentation/technical/index-format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Git index format
Extensions are identified by signature. Optional extensions can
be ignored if Git does not understand them.

Git currently supports cached tree and resolve undo extensions.
Git currently supports cache tree and resolve undo extensions.

4-byte extension signature. If the first byte is 'A'..'Z' the
extension is optional and can be ignored.
Expand Down Expand Up @@ -136,14 +136,35 @@ Git index format

== Extensions

=== Cached tree

Cached tree extension contains pre-computed hashes for trees that can
be derived from the index. It helps speed up tree object generation
from index for a new commit.

When a path is updated in index, the path must be invalidated and
removed from tree cache.
=== Cache tree

Since the index does not record entries for directories, the cache
entries cannot describe tree objects that already exist in the object
database for regions of the index that are unchanged from an existing
commit. The cache tree extension stores a recursive tree structure that
describes the trees that already exist and completely match sections of
the cache entries. This speeds up tree object generation from the index
for a new commit by only computing the trees that are "new" to that
commit. It also assists when comparing the index to another tree, such
as `HEAD^{tree}`, since sections of the index can be skipped when a tree
comparison demonstrates equality.

The recursive tree structure uses nodes that store a number of cache
entries, a list of subnodes, and an object ID (OID). The OID references
the existing tree for that node, if it is known to exist. The subnodes
correspond to subdirectories that themselves have cache tree nodes. The
number of cache entries corresponds to the number of cache entries in
the index that describe paths within that tree's directory.

The extension tracks the full directory structure in the cache tree
extension, but this is generally smaller than the full cache entry list.

When a path is updated in index, Git invalidates all nodes of the
recursive cache tree corresponding to the parent directories of that
path. We store these tree nodes as being "invalid" by using "-1" as the
number of cache entries. Invalid nodes still store a span of index
entries, allowing Git to focus its efforts when reconstructing a full
cache tree.

The signature for this extension is { 'T', 'R', 'E', 'E' }.

Expand Down Expand Up @@ -174,7 +195,8 @@ Git index format
first entry represents the root level of the repository, followed by the
first subtree--let's call this A--of the root level (with its name
relative to the root level), followed by the first subtree of A (with
its name relative to A), ...
its name relative to A), and so on. The specified number of subtrees
indicates when the current level of the recursive stack is complete.

=== Resolve undo

Expand Down
6 changes: 3 additions & 3 deletions Documentation/technical/racy-git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ information obtained from the filesystem via `lstat(2)` system
call when they were last updated. When checking if they differ,
Git first runs `lstat(2)` on the files and compares the result
with this information (this is what was originally done by the
`ce_match_stat()` function, but the current code does it in
`ie_match_stat()` function, but the current code does it in
`ce_match_stat_basic()` function). If some of these "cached
stat information" fields do not match, Git can tell that the
files are modified without even looking at their contents.
Expand Down Expand Up @@ -102,7 +102,7 @@ timestamp as the index file itself.

The callers that want to check if an index entry matches the
corresponding file in the working tree continue to call
`ce_match_stat()`, but with this change, `ce_match_stat()` uses
`ie_match_stat()`, but with this change, `ie_match_stat()` uses
`ce_modified_check_fs()` to see if racily clean ones are
actually clean after comparing the cached stat information using
`ce_match_stat_basic()`.
Expand All @@ -128,7 +128,7 @@ Runtime penalty
---------------

The runtime penalty of falling back to `ce_modified_check_fs()`
from `ce_match_stat()` can be very expensive when there are many
from `ie_match_stat()` can be very expensive when there are many
racily clean entries. An obvious way to artificially create
this situation is to give the same timestamp to all the files in
the working tree in a large project, run `git update-index` on
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,6 @@ unexport CDPATH
SCRIPT_SH += git-bisect.sh
SCRIPT_SH += git-difftool--helper.sh
SCRIPT_SH += git-filter-branch.sh
SCRIPT_SH += git-merge-octopus.sh
SCRIPT_SH += git-merge-one-file.sh
SCRIPT_SH += git-merge-resolve.sh
SCRIPT_SH += git-mergetool.sh
SCRIPT_SH += git-quiltimport.sh
SCRIPT_SH += git-request-pull.sh
Expand Down Expand Up @@ -930,6 +927,7 @@ LIB_OBJS += merge-blobs.o
LIB_OBJS += merge-ort.o
LIB_OBJS += merge-ort-wrappers.o
LIB_OBJS += merge-recursive.o
LIB_OBJS += merge-strategies.o
LIB_OBJS += merge.o
LIB_OBJS += mergesort.o
LIB_OBJS += midx.o
Expand Down Expand Up @@ -1003,6 +1001,7 @@ LIB_OBJS += sha1-name.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
Expand Down Expand Up @@ -1120,8 +1119,11 @@ BUILTIN_OBJS += builtin/mailsplit.o
BUILTIN_OBJS += builtin/merge-base.o
BUILTIN_OBJS += builtin/merge-file.o
BUILTIN_OBJS += builtin/merge-index.o
BUILTIN_OBJS += builtin/merge-octopus.o
BUILTIN_OBJS += builtin/merge-one-file.o
BUILTIN_OBJS += builtin/merge-ours.o
BUILTIN_OBJS += builtin/merge-recursive.o
BUILTIN_OBJS += builtin/merge-resolve.o
BUILTIN_OBJS += builtin/merge-tree.o
BUILTIN_OBJS += builtin/merge.o
BUILTIN_OBJS += builtin/mktag.o
Expand Down
10 changes: 9 additions & 1 deletion apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -3541,6 +3541,8 @@ static int load_current(struct apply_state *state,
if (!patch->is_new)
BUG("patch to %s is not a creation", patch->old_name);

ensure_full_index(state->repo->index);

pos = index_name_pos(state->repo->index, name, strlen(name));
if (pos < 0)
return error(_("%s: does not exist in index"), name);
Expand Down Expand Up @@ -3710,7 +3712,11 @@ static int check_preimage(struct apply_state *state,
}

if (state->check_index && !previous) {
int pos = index_name_pos(state->repo->index, old_name,
int pos;

ensure_full_index(state->repo->index);

pos = index_name_pos(state->repo->index, old_name,
strlen(old_name));
if (pos < 0) {
if (patch->is_new < 0)
Expand Down Expand Up @@ -3769,6 +3775,8 @@ static int check_to_create(struct apply_state *state,
if (state->check_index && (!ok_if_exists || !state->cached)) {
int pos;

ensure_full_index(state->repo->index);

pos = index_name_pos(state->repo->index, new_name, strlen(new_name));
if (pos >= 0) {
struct cache_entry *ce = state->repo->index->cache[pos];
Expand Down
1 change: 1 addition & 0 deletions archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ int write_archive_entries(struct archiver_args *args,
opts.head_idx = -1;
opts.src_index = args->repo->index;
opts.dst_index = args->repo->index;
ensure_full_index(opts.src_index);
opts.fn = oneway_merge;
init_tree_desc(&t, args->tree->buffer, args->tree->size);
if (unpack_trees(1, &t, &opts))
Expand Down
7 changes: 6 additions & 1 deletion blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ static void verify_working_tree_path(struct repository *r,
return;
}

ensure_full_index(r->index);
pos = index_name_pos(r->index, path, strlen(path));
if (pos >= 0)
; /* path is in the index */
Expand Down Expand Up @@ -277,7 +278,11 @@ static struct commit *fake_working_tree_commit(struct repository *r,

len = strlen(path);
if (!mode) {
int pos = index_name_pos(r->index, path, len);
int pos;

ensure_full_index(r->index);

pos = index_name_pos(r->index, path, len);
if (0 <= pos)
mode = r->index->cache[pos]->ce_mode;
else
Expand Down
3 changes: 3 additions & 0 deletions builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,12 @@ int cmd_maintenance(int argc, const char **argv, const char *prefix);
int cmd_merge(int argc, const char **argv, const char *prefix);
int cmd_merge_base(int argc, const char **argv, const char *prefix);
int cmd_merge_index(int argc, const char **argv, const char *prefix);
int cmd_merge_octopus(int argc, const char **argv, const char *prefix);
int cmd_merge_ours(int argc, const char **argv, const char *prefix);
int cmd_merge_file(int argc, const char **argv, const char *prefix);
int cmd_merge_one_file(int argc, const char **argv, const char *prefix);
int cmd_merge_recursive(int argc, const char **argv, const char *prefix);
int cmd_merge_resolve(int argc, const char **argv, const char *prefix);
int cmd_merge_tree(int argc, const char **argv, const char *prefix);
int cmd_mktag(int argc, const char **argv, const char *prefix);
int cmd_mktree(int argc, const char **argv, const char *prefix);
Expand Down
3 changes: 3 additions & 0 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize;
require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));

prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;

hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);

/*
Expand Down
2 changes: 2 additions & 0 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,7 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
init_tree_desc(&t[0], head->buffer, head->size);
init_tree_desc(&t[1], remote->buffer, remote->size);

ensure_full_index(opts.src_index);
if (unpack_trees(2, t, &opts)) {
rollback_lock_file(&lock_file);
return -1;
Expand Down Expand Up @@ -1908,6 +1909,7 @@ static int merge_tree(struct tree *tree)
opts.fn = oneway_merge;
init_tree_desc(&t[0], tree->buffer, tree->size);

ensure_full_index(opts.src_index);
if (unpack_trees(1, t, &opts)) {
rollback_lock_file(&lock_file);
return -1;
Expand Down
5 changes: 4 additions & 1 deletion builtin/checkout-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ static void write_tempfile_record(const char *name, const char *prefix)
static int checkout_file(const char *name, const char *prefix)
{
int namelen = strlen(name);
int pos = cache_name_pos(name, namelen);
int pos;
int has_same_name = 0;
int did_checkout = 0;
int errs = 0;

ensure_full_index(the_repository->index);
pos = index_name_pos(the_repository->index, name, namelen);

if (pos < 0)
pos = -pos - 1;

Expand Down
4 changes: 1 addition & 3 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
NULL);
parse_tree(tree);
init_tree_desc(&tree_desc, tree->buffer, tree->size);
ensure_full_index(opts.src_index);
switch (unpack_trees(1, &tree_desc, &opts)) {
case -2:
*writeout_error = 1;
Expand Down Expand Up @@ -824,9 +825,6 @@ static int merge_working_tree(const struct checkout_opts *opts,
}
}

if (!active_cache_tree)
active_cache_tree = cache_tree();

if (!cache_tree_fully_valid(active_cache_tree))
cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);

Expand Down
1 change: 1 addition & 0 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ static int checkout(int submodule_progress)
tree = parse_tree_indirect(&oid);
parse_tree(tree);
init_tree_desc(&t, tree->buffer, tree->size);
ensure_full_index(opts.src_index);
if (unpack_trees(1, &t, &opts) < 0)
die(_("unable to checkout working tree"));

Expand Down
4 changes: 4 additions & 0 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ static void create_base_index(const struct commit *current_head)
die(_("failed to unpack HEAD tree object"));
parse_tree(tree);
init_tree_desc(&t, tree->buffer, tree->size);
ensure_full_index(opts.src_index);
if (unpack_trees(1, &t, &opts))
exit(128); /* We've already reported the error, finish dying */
}
Expand Down Expand Up @@ -1559,6 +1560,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(builtin_status_usage, builtin_status_options);

prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;

status_init_config(&s, git_status_config);
argc = parse_options(argc, argv, prefix,
builtin_status_options,
Expand Down
2 changes: 2 additions & 0 deletions builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ static int grep_cache(struct grep_opt *opt,
if (repo_read_index(repo) < 0)
die(_("index file corrupt"));

ensure_full_index(repo->index);

for (nr = 0; nr < repo->index->cache_nr; nr++) {
const struct cache_entry *ce = repo->index->cache[nr];
strbuf_setlen(&name, name_base_len);
Expand Down
9 changes: 8 additions & 1 deletion builtin/ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static void show_other_files(const struct index_state *istate,
}
}

static void show_killed_files(const struct index_state *istate,
static void show_killed_files(struct index_state *istate,
const struct dir_struct *dir)
{
int i;
Expand All @@ -159,6 +159,8 @@ static void show_killed_files(const struct index_state *istate,
char *cp, *sp;
int pos, len, killed = 0;

ensure_full_index(istate);

for (cp = ent->name; cp - ent->name < ent->len; cp = sp + 1) {
sp = strchr(cp, '/');
if (!sp) {
Expand Down Expand Up @@ -313,6 +315,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
show_killed_files(repo->index, dir);
}
if (show_cached || show_stage) {
ensure_full_index(repo->index);
for (i = 0; i < repo->index->cache_nr; i++) {
const struct cache_entry *ce = repo->index->cache[i];

Expand All @@ -332,6 +335,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
}
}
if (show_deleted || show_modified) {
ensure_full_index(repo->index);
for (i = 0; i < repo->index->cache_nr; i++) {
const struct cache_entry *ce = repo->index->cache[i];
struct stat st;
Expand Down Expand Up @@ -368,6 +372,7 @@ static void prune_index(struct index_state *istate,

if (!prefix || !istate->cache_nr)
return;
ensure_full_index(istate);
pos = index_name_pos(istate, prefix, prefixlen);
if (pos < 0)
pos = -pos-1;
Expand Down Expand Up @@ -428,6 +433,8 @@ void overlay_tree_on_index(struct index_state *istate,
if (!tree)
die("bad tree-ish %s", tree_name);

ensure_full_index(istate);

/* Hoist the unmerged entries up to stage #3 to make room */
for (i = 0; i < istate->cache_nr; i++) {
struct cache_entry *ce = istate->cache[i];
Expand Down
Loading