Skip to content

Commit c7cba4b

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 070d43f commit c7cba4b

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
@@ -387,7 +387,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
387387
}
388388

389389
/* TODO: audit for interaction with sparse-index. */
390-
ensure_full_index(the_repository->index);
390+
ensure_full_index_unaudited(the_repository->index);
391391
for (i = 0; i < the_repository->index->cache_nr; i++) {
392392
const struct cache_entry *ce = the_repository->index->cache[i];
393393
struct string_list_item *item;
@@ -1151,7 +1151,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
11511151
int i, ita_nr = 0;
11521152

11531153
/* TODO: audit for interaction with sparse-index. */
1154-
ensure_full_index(the_repository->index);
1154+
ensure_full_index_unaudited(the_repository->index);
11551155
for (i = 0; i < the_repository->index->cache_nr; i++)
11561156
if (ce_intent_to_add(the_repository->index->cache[i]))
11571157
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
@@ -817,7 +817,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
817817
unsigned int i;
818818

819819
/* TODO: audit for interaction with sparse-index. */
820-
ensure_full_index(istate);
820+
ensure_full_index_unaudited(istate);
821821
for (i = 0; i < istate->cache_nr; i++) {
822822
unsigned int mode;
823823
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
@@ -1626,7 +1626,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
16261626
char *ps_matched = xcalloc(ps->nr, 1);
16271627

16281628
/* TODO: audit for interaction with sparse-index. */
1629-
ensure_full_index(the_repository->index);
1629+
ensure_full_index_unaudited(the_repository->index);
16301630
for (size_t i = 0; i < the_repository->index->cache_nr; i++)
16311631
ce_path_match(the_repository->index, the_repository->index->cache[i], ps,
16321632
ps_matched);

builtin/submodule--helper.c

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

33933393
/* TODO: audit for interaction with sparse-index. */
3394-
ensure_full_index(the_repository->index);
3394+
ensure_full_index_unaudited(the_repository->index);
33953395

33963396
/*
33973397
* 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
@@ -2563,7 +2563,7 @@ int repo_index_has_changes(struct repository *repo,
25632563
return opt.flags.has_changes != 0;
25642564
} else {
25652565
/* TODO: audit for interaction with sparse-index. */
2566-
ensure_full_index(istate);
2566+
ensure_full_index_unaudited(istate);
25672567
for (i = 0; sb && i < istate->cache_nr; i++) {
25682568
if (i)
25692569
strbuf_addch(sb, ' ');
@@ -3855,7 +3855,7 @@ void overlay_tree_on_index(struct index_state *istate,
38553855

38563856
/* Hoist the unmerged entries up to stage #3 to make room */
38573857
/* TODO: audit for interaction with sparse-index. */
3858-
ensure_full_index(istate);
3858+
ensure_full_index_unaudited(istate);
38593859
for (i = 0; i < istate->cache_nr; i++) {
38603860
struct cache_entry *ce = istate->cache[i];
38613861
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
@@ -1811,7 +1811,7 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
18111811
int i;
18121812

18131813
/* TODO: audit for interaction with sparse-index. */
1814-
ensure_full_index(istate);
1814+
ensure_full_index_unaudited(istate);
18151815
for (i = 0; i < istate->cache_nr; i++) {
18161816
struct cache_entry *ce = istate->cache[i];
18171817
struct blob *blob;

0 commit comments

Comments
 (0)