Skip to content

Commit 1991d52

Browse files
derrickstoleedscho
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 8f6e9ca commit 1991d52

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Diff for: sparse-index.c

+18
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,24 @@ void ensure_full_index(struct index_state *istate)
463463
expand_index(istate, NULL);
464464
}
465465

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

Diff for: sparse-index.h

+8
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)