Skip to content

Commit bf48e5a

Browse files
derrickstoleegitster
authored andcommitted
status: skip sparse-checkout percentage with sparse-index
'git status' began reporting a percentage of populated paths when sparse-checkout is enabled in 051df3c (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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9eb00af commit bf48e5a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ test_expect_success 'status with options' '
218218
test_all_match git status --porcelain=v2 -uno
219219
'
220220

221+
test_expect_success 'status reports sparse-checkout' '
222+
init_repos &&
223+
git -C sparse-checkout status >full &&
224+
git -C sparse-index status >sparse &&
225+
test_i18ngrep "You are in a sparse checkout with " full &&
226+
test_i18ngrep "You are in a sparse checkout." sparse
227+
'
228+
221229
test_expect_success 'add, commit, checkout' '
222230
init_repos &&
223231

wt-status.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,9 +1493,12 @@ static void show_sparse_checkout_in_use(struct wt_status *s,
14931493
if (s->state.sparse_checkout_percentage == SPARSE_CHECKOUT_DISABLED)
14941494
return;
14951495

1496-
status_printf_ln(s, color,
1497-
_("You are in a sparse checkout with %d%% of tracked files present."),
1498-
s->state.sparse_checkout_percentage);
1496+
if (s->state.sparse_checkout_percentage == SPARSE_CHECKOUT_SPARSE_INDEX)
1497+
status_printf_ln(s, color, _("You are in a sparse checkout."));
1498+
else
1499+
status_printf_ln(s, color,
1500+
_("You are in a sparse checkout with %d%% of tracked files present."),
1501+
s->state.sparse_checkout_percentage);
14991502
wt_longstatus_print_trailer(s);
15001503
}
15011504

@@ -1653,6 +1656,11 @@ static void wt_status_check_sparse_checkout(struct repository *r,
16531656
return;
16541657
}
16551658

1659+
if (r->index->sparse_index) {
1660+
state->sparse_checkout_percentage = SPARSE_CHECKOUT_SPARSE_INDEX;
1661+
return;
1662+
}
1663+
16561664
for (i = 0; i < r->index->cache_nr; i++) {
16571665
struct cache_entry *ce = r->index->cache[i];
16581666
if (ce_skip_worktree(ce))

wt-status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum wt_status_format {
7878
};
7979

8080
#define SPARSE_CHECKOUT_DISABLED -1
81+
#define SPARSE_CHECKOUT_SPARSE_INDEX -2
8182

8283
struct wt_status_state {
8384
int merge_in_progress;

0 commit comments

Comments
 (0)