Skip to content

Commit 3552086

Browse files
derrickstoleedscho
authored andcommitted
sparse-index: add macro for unaudited expansions
For safety, areas of code that iterate over the cache entries in the index were guarded with ensure_full_index() and labeled with a comment. Replace these with a macro that calls ensure_full_index_with_reason() using the line number of the caller to help identify the situation that is causing the index expansion. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 9b65c4f commit 3552086

File tree

11 files changed

+19
-13
lines changed

11 files changed

+19
-13
lines changed

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
385385
}
386386

387387
/* TODO: audit for interaction with sparse-index. */
388-
ensure_full_index(the_repository->index);
388+
ensure_full_index_unaudited(the_repository->index);
389389
for (i = 0; i < the_repository->index->cache_nr; i++) {
390390
const struct cache_entry *ce = the_repository->index->cache[i];
391391
struct string_list_item *item;
@@ -1135,7 +1135,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
11351135
int i, ita_nr = 0;
11361136

11371137
/* TODO: audit for interaction with sparse-index. */
1138-
ensure_full_index(the_repository->index);
1138+
ensure_full_index_unaudited(the_repository->index);
11391139
for (i = 0; i < the_repository->index->cache_nr; i++)
11401140
if (ce_intent_to_add(the_repository->index->cache[i]))
11411141
ita_nr++;

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static int run_dir_diff(struct repository *repo,
607607
ret = run_command(&cmd);
608608

609609
/* TODO: audit for interaction with sparse-index. */
610-
ensure_full_index(&wtindex);
610+
ensure_full_index_unaudited(&wtindex);
611611

612612
/*
613613
* If the diff includes working copy files and those

builtin/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
815815
unsigned int i;
816816

817817
/* TODO: audit for interaction with sparse-index. */
818-
ensure_full_index(istate);
818+
ensure_full_index_unaudited(istate);
819819
for (i = 0; i < istate->cache_nr; i++) {
820820
unsigned int mode;
821821
struct blob *blob;

builtin/merge-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void merge_all(void)
6666
{
6767
int i;
6868
/* TODO: audit for interaction with sparse-index. */
69-
ensure_full_index(the_repository->index);
69+
ensure_full_index_unaudited(the_repository->index);
7070
for (i = 0; i < the_repository->index->cache_nr; i++) {
7171
const struct cache_entry *ce = the_repository->index->cache[i];
7272
if (!ce_stage(ce))
@@ -98,7 +98,7 @@ int cmd_merge_index(int argc,
9898
repo_read_index(the_repository);
9999

100100
/* TODO: audit for interaction with sparse-index. */
101-
ensure_full_index(the_repository->index);
101+
ensure_full_index_unaudited(the_repository->index);
102102

103103
i = 1;
104104
if (!strcmp(argv[i], "-o")) {

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
15591559
char *ps_matched = xcalloc(ps->nr, 1);
15601560

15611561
/* TODO: audit for interaction with sparse-index. */
1562-
ensure_full_index(the_repository->index);
1562+
ensure_full_index_unaudited(the_repository->index);
15631563
for (size_t i = 0; i < the_repository->index->cache_nr; i++)
15641564
ce_path_match(the_repository->index, the_repository->index->cache[i], ps,
15651565
ps_matched);

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3400,7 +3400,7 @@ static void die_on_index_match(const char *path, int force)
34003400
char *ps_matched = xcalloc(ps.nr, 1);
34013401

34023402
/* TODO: audit for interaction with sparse-index. */
3403-
ensure_full_index(the_repository->index);
3403+
ensure_full_index_unaudited(the_repository->index);
34043404

34053405
/*
34063406
* Since there is only one pathspec, we just need to

entry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static void mark_colliding_entries(const struct checkout *state,
455455
ce->ce_flags |= CE_MATCHED;
456456

457457
/* TODO: audit for interaction with sparse-index. */
458-
ensure_full_index(state->istate);
458+
ensure_full_index_unaudited(state->istate);
459459
for (size_t i = 0; i < state->istate->cache_nr; i++) {
460460
struct cache_entry *dup = state->istate->cache[i];
461461

read-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,7 +2562,7 @@ int repo_index_has_changes(struct repository *repo,
25622562
return opt.flags.has_changes != 0;
25632563
} else {
25642564
/* TODO: audit for interaction with sparse-index. */
2565-
ensure_full_index(istate);
2565+
ensure_full_index_unaudited(istate);
25662566
for (i = 0; sb && i < istate->cache_nr; i++) {
25672567
if (i)
25682568
strbuf_addch(sb, ' ');
@@ -3854,7 +3854,7 @@ void overlay_tree_on_index(struct index_state *istate,
38543854

38553855
/* Hoist the unmerged entries up to stage #3 to make room */
38563856
/* TODO: audit for interaction with sparse-index. */
3857-
ensure_full_index(istate);
3857+
ensure_full_index_unaudited(istate);
38583858
for (i = 0; i < istate->cache_nr; i++) {
38593859
struct cache_entry *ce = istate->cache[i];
38603860
if (!ce_stage(ce))

resolve-undo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void unmerge_index(struct index_state *istate, const struct pathspec *pathspec,
161161
return;
162162

163163
/* TODO: audit for interaction with sparse-index. */
164-
ensure_full_index(istate);
164+
ensure_full_index_unaudited(istate);
165165

166166
for_each_string_list_item(item, istate->resolve_undo) {
167167
const char *path = item->string;

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,7 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
18421842
int i;
18431843

18441844
/* TODO: audit for interaction with sparse-index. */
1845-
ensure_full_index(istate);
1845+
ensure_full_index_unaudited(istate);
18461846
for (i = 0; i < istate->cache_nr; i++) {
18471847
struct cache_entry *ce = istate->cache[i];
18481848
struct blob *blob;

0 commit comments

Comments
 (0)