Skip to content

Commit fd4b610

Browse files
derrickstoleemjcheetham
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 5872e4d commit fd4b610

File tree

12 files changed

+20
-14
lines changed

12 files changed

+20
-14
lines changed

builtin/commit.c

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

384384
/* TODO: audit for interaction with sparse-index. */
385-
ensure_full_index(the_repository->index);
385+
ensure_full_index_unaudited(the_repository->index);
386386
for (i = 0; i < the_repository->index->cache_nr; i++) {
387387
const struct cache_entry *ce = the_repository->index->cache[i];
388388
struct string_list_item *item;
@@ -1123,7 +1123,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
11231123
int i, ita_nr = 0;
11241124

11251125
/* TODO: audit for interaction with sparse-index. */
1126-
ensure_full_index(the_repository->index);
1126+
ensure_full_index_unaudited(the_repository->index);
11271127
for (i = 0; i < the_repository->index->cache_nr; i++)
11281128
if (ce_intent_to_add(the_repository->index->cache[i]))
11291129
ita_nr++;

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
588588
ret = run_command(&cmd);
589589

590590
/* TODO: audit for interaction with sparse-index. */
591-
ensure_full_index(&wtindex);
591+
ensure_full_index_unaudited(&wtindex);
592592

593593
/*
594594
* 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
@@ -818,7 +818,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
818818
unsigned int i;
819819

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

builtin/merge-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void merge_all(void)
6464
{
6565
int i;
6666
/* TODO: audit for interaction with sparse-index. */
67-
ensure_full_index(the_repository->index);
67+
ensure_full_index_unaudited(the_repository->index);
6868
for (i = 0; i < the_repository->index->cache_nr; i++) {
6969
const struct cache_entry *ce = the_repository->index->cache[i];
7070
if (!ce_stage(ce))
@@ -91,7 +91,7 @@ int cmd_merge_index(int argc,
9191
repo_read_index(the_repository);
9292

9393
/* TODO: audit for interaction with sparse-index. */
94-
ensure_full_index(the_repository->index);
94+
ensure_full_index_unaudited(the_repository->index);
9595

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

builtin/stash.c

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

15541554
/* TODO: audit for interaction with sparse-index. */
1555-
ensure_full_index(the_repository->index);
1555+
ensure_full_index_unaudited(the_repository->index);
15561556
for (i = 0; i < the_repository->index->cache_nr; i++)
15571557
ce_path_match(the_repository->index, the_repository->index->cache[i], ps,
15581558
ps_matched);

builtin/submodule--helper.c

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

33893389
/* TODO: audit for interaction with sparse-index. */
3390-
ensure_full_index(the_repository->index);
3390+
ensure_full_index_unaudited(the_repository->index);
33913391

33923392
/*
33933393
* 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
@@ -453,7 +453,7 @@ static void mark_colliding_entries(const struct checkout *state,
453453
ce->ce_flags |= CE_MATCHED;
454454

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

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static struct string_list *get_unmerged(struct index_state *istate)
539539
string_list_init_dup(unmerged);
540540

541541
/* TODO: audit for interaction with sparse-index. */
542-
ensure_full_index(istate);
542+
ensure_full_index_unaudited(istate);
543543
for (i = 0; i < istate->cache_nr; i++) {
544544
struct string_list_item *item;
545545
struct stage_data *e;

read-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,7 +2589,7 @@ int repo_index_has_changes(struct repository *repo,
25892589
return opt.flags.has_changes != 0;
25902590
} else {
25912591
/* TODO: audit for interaction with sparse-index. */
2592-
ensure_full_index(istate);
2592+
ensure_full_index_unaudited(istate);
25932593
for (i = 0; sb && i < istate->cache_nr; i++) {
25942594
if (i)
25952595
strbuf_addch(sb, ' ');
@@ -3870,7 +3870,7 @@ void overlay_tree_on_index(struct index_state *istate,
38703870

38713871
/* Hoist the unmerged entries up to stage #3 to make room */
38723872
/* TODO: audit for interaction with sparse-index. */
3873-
ensure_full_index(istate);
3873+
ensure_full_index_unaudited(istate);
38743874
for (i = 0; i < istate->cache_nr; i++) {
38753875
struct cache_entry *ce = istate->cache[i];
38763876
if (!ce_stage(ce))

resolve-undo.c

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

162162
/* TODO: audit for interaction with sparse-index. */
163-
ensure_full_index(istate);
163+
ensure_full_index_unaudited(istate);
164164

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

0 commit comments

Comments
 (0)