Skip to content

Commit d89823c

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 <stolee@gmail.com>
1 parent 74f0e1c commit d89823c

12 files changed

+20
-14
lines changed

Diff for: builtin/commit.c

+2-2
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;
@@ -1133,7 +1133,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
11331133
int i, ita_nr = 0;
11341134

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

Diff for: builtin/difftool.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
592592
ret = run_command(&cmd);
593593

594594
/* TODO: audit for interaction with sparse-index. */
595-
ensure_full_index(&wtindex);
595+
ensure_full_index_unaudited(&wtindex);
596596

597597
/*
598598
* If the diff includes working copy files and those

Diff for: builtin/fsck.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
821821
unsigned int i;
822822

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

Diff for: builtin/merge-index.c

+2-2
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))
@@ -93,7 +93,7 @@ int cmd_merge_index(int argc,
9393
repo_read_index(the_repository);
9494

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

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

Diff for: builtin/stash.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
15601560
char *ps_matched = xcalloc(ps->nr, 1);
15611561

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

Diff for: builtin/submodule--helper.c

+1-1
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

Diff for: entry.c

+1-1
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 (size_t i = 0; i < state->istate->cache_nr; i++) {
458458
struct cache_entry *dup = state->istate->cache[i];
459459

Diff for: merge-recursive.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ static struct string_list *get_unmerged(struct index_state *istate)
540540
string_list_init_dup(unmerged);
541541

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

Diff for: read-cache.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2590,7 +2590,7 @@ int repo_index_has_changes(struct repository *repo,
25902590
return opt.flags.has_changes != 0;
25912591
} else {
25922592
/* TODO: audit for interaction with sparse-index. */
2593-
ensure_full_index(istate);
2593+
ensure_full_index_unaudited(istate);
25942594
for (i = 0; sb && i < istate->cache_nr; i++) {
25952595
if (i)
25962596
strbuf_addch(sb, ' ');
@@ -3872,7 +3872,7 @@ void overlay_tree_on_index(struct index_state *istate,
38723872

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

Diff for: resolve-undo.c

+1-1
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;

Diff for: revision.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
18501850
int i;
18511851

18521852
/* TODO: audit for interaction with sparse-index. */
1853-
ensure_full_index(istate);
1853+
ensure_full_index_unaudited(istate);
18541854
for (i = 0; i < istate->cache_nr; i++) {
18551855
struct cache_entry *ce = istate->cache[i];
18561856
struct blob *blob;

Diff for: sparse-index.h

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef SPARSE_INDEX_H__
22
#define SPARSE_INDEX_H__
33

4+
#include "strbuf.h"
5+
46
/*
57
* If performing an operation where the index is supposed to expand to a
68
* full index, then disable the advice message by setting this global to
@@ -54,4 +56,8 @@ void ensure_full_index_with_reason(struct index_state *istate,
5456
const char *fmt,
5557
...);
5658

59+
#define ensure_full_index_unaudited(i) \
60+
ensure_full_index_with_reason((i), \
61+
"unaudited call (%s.%d)", __FILE__, __LINE__);
62+
5763
#endif

0 commit comments

Comments
 (0)