status: skip sparse-checkout percentage with sparse-index
'git status' began reporting a percentage of populated paths when
sparse-checkout is enabled in 051df3cf
(wt-status: show sparse
checkout status as well, 2020-07-18). This percentage is incorrect when
the index has sparse directories. It would also be expensive to
calculate as we would need to parse trees to count the total number of
possible paths.
Avoid the expensive computation by simplifying the output to only report
that a sparse checkout exists, without the percentage.
This change is the reason we use 'git status --porcelain=v2' in
t1092-sparse-checkout-compatibility.sh. We don't want to ensure that
this message is equal across both modes, but instead just the important
information about staged, modified, and untracked files are compared.
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
9eb00af562
commit
bf48e5acdb
@ -218,6 +218,14 @@ test_expect_success 'status with options' '
|
|||||||
test_all_match git status --porcelain=v2 -uno
|
test_all_match git status --porcelain=v2 -uno
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'status reports sparse-checkout' '
|
||||||
|
init_repos &&
|
||||||
|
git -C sparse-checkout status >full &&
|
||||||
|
git -C sparse-index status >sparse &&
|
||||||
|
test_i18ngrep "You are in a sparse checkout with " full &&
|
||||||
|
test_i18ngrep "You are in a sparse checkout." sparse
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'add, commit, checkout' '
|
test_expect_success 'add, commit, checkout' '
|
||||||
init_repos &&
|
init_repos &&
|
||||||
|
|
||||||
|
14
wt-status.c
14
wt-status.c
@ -1493,9 +1493,12 @@ static void show_sparse_checkout_in_use(struct wt_status *s,
|
|||||||
if (s->state.sparse_checkout_percentage == SPARSE_CHECKOUT_DISABLED)
|
if (s->state.sparse_checkout_percentage == SPARSE_CHECKOUT_DISABLED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
status_printf_ln(s, color,
|
if (s->state.sparse_checkout_percentage == SPARSE_CHECKOUT_SPARSE_INDEX)
|
||||||
_("You are in a sparse checkout with %d%% of tracked files present."),
|
status_printf_ln(s, color, _("You are in a sparse checkout."));
|
||||||
s->state.sparse_checkout_percentage);
|
else
|
||||||
|
status_printf_ln(s, color,
|
||||||
|
_("You are in a sparse checkout with %d%% of tracked files present."),
|
||||||
|
s->state.sparse_checkout_percentage);
|
||||||
wt_longstatus_print_trailer(s);
|
wt_longstatus_print_trailer(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1653,6 +1656,11 @@ static void wt_status_check_sparse_checkout(struct repository *r,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (r->index->sparse_index) {
|
||||||
|
state->sparse_checkout_percentage = SPARSE_CHECKOUT_SPARSE_INDEX;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < r->index->cache_nr; i++) {
|
for (i = 0; i < r->index->cache_nr; i++) {
|
||||||
struct cache_entry *ce = r->index->cache[i];
|
struct cache_entry *ce = r->index->cache[i];
|
||||||
if (ce_skip_worktree(ce))
|
if (ce_skip_worktree(ce))
|
||||||
|
@ -78,6 +78,7 @@ enum wt_status_format {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define SPARSE_CHECKOUT_DISABLED -1
|
#define SPARSE_CHECKOUT_DISABLED -1
|
||||||
|
#define SPARSE_CHECKOUT_SPARSE_INDEX -2
|
||||||
|
|
||||||
struct wt_status_state {
|
struct wt_status_state {
|
||||||
int merge_in_progress;
|
int merge_in_progress;
|
||||||
|
Loading…
Reference in New Issue
Block a user