Skip to content

Commit d856bd5

Browse files
derrickstoleemjcheetham
authored andcommitted
sparse-index: add ensure_full_index_with_reason()
It is sometimes difficult to support users who are hitting issues with sparse index expansion because it is unclear why the index needs to expand from logs alone. It is too invasive to set up a debugging scenario on the user's machine, so let's improve the logging. Create a new ensure_full_index_with_reason() method that takes a formatting string and parameters. If the index is not fully expanded, then apply the formatting logic to create the logged string and log it before calling ensure_full_index(). This should assist with discovering why an index is expanded from trace2 logs alone. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent f665caa commit d856bd5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

sparse-index.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,24 @@ void ensure_full_index(struct index_state *istate)
459459
expand_index(istate, NULL);
460460
}
461461

462+
void ensure_full_index_with_reason(struct index_state *istate,
463+
const char *fmt, ...)
464+
{
465+
va_list ap;
466+
struct strbuf why = STRBUF_INIT;
467+
if (!istate)
468+
BUG("ensure_full_index_with_reason() must get an index!");
469+
if (istate->sparse_index == INDEX_EXPANDED)
470+
return;
471+
472+
va_start(ap, fmt);
473+
strbuf_vaddf(&why, fmt, ap);
474+
trace2_data_string("sparse-index", istate->repo, "expansion-reason", why.buf);
475+
va_end(ap);
476+
strbuf_release(&why);
477+
ensure_full_index(istate);
478+
}
479+
462480
void ensure_correct_sparsity(struct index_state *istate)
463481
{
464482
/*

sparse-index.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ void expand_index(struct index_state *istate, struct pattern_list *pl);
4646

4747
void ensure_full_index(struct index_state *istate);
4848

49+
/**
50+
* If there is a clear reason why the sparse index is being expanded, then
51+
* trace the information for why the expansion is occurring.
52+
*/
53+
void ensure_full_index_with_reason(struct index_state *istate,
54+
const char *fmt,
55+
...);
56+
4957
#endif

0 commit comments

Comments
 (0)