Skip to content

Commit 6a38ef2

Browse files
pcloudsgitster
authored andcommitted
status: advise to consider use of -u when read_directory takes too long
Introduce advice.statusUoption to suggest considering use of -u to strike different trade-off when it took more than 2 seconds to enumerate untracked/ignored files. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5823eb2 commit 6a38ef2

File tree

8 files changed

+36
-0
lines changed

8 files changed

+36
-0
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ advice.*::
163163
state in the output of linkgit:git-status[1] and in
164164
the template shown when writing commit messages in
165165
linkgit:git-commit[1].
166+
statusUoption::
167+
Advise to consider using the `-u` option to linkgit:git-status[1]
168+
when the command takes more than 2 seconds to enumerate untracked
169+
files.
166170
commitBeforeMerge::
167171
Advice shown when linkgit:git-merge[1] refuses to
168172
merge to avoid overwriting local changes.

advice.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ int advice_push_non_ff_current = 1;
55
int advice_push_non_ff_default = 1;
66
int advice_push_non_ff_matching = 1;
77
int advice_status_hints = 1;
8+
int advice_status_u_option = 1;
89
int advice_commit_before_merge = 1;
910
int advice_resolve_conflict = 1;
1011
int advice_implicit_identity = 1;
@@ -19,6 +20,7 @@ static struct {
1920
{ "pushnonffdefault", &advice_push_non_ff_default },
2021
{ "pushnonffmatching", &advice_push_non_ff_matching },
2122
{ "statushints", &advice_status_hints },
23+
{ "statusuoption", &advice_status_u_option },
2224
{ "commitbeforemerge", &advice_commit_before_merge },
2325
{ "resolveconflict", &advice_resolve_conflict },
2426
{ "implicitidentity", &advice_implicit_identity },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern int advice_push_non_ff_current;
88
extern int advice_push_non_ff_default;
99
extern int advice_push_non_ff_matching;
1010
extern int advice_status_hints;
11+
extern int advice_status_u_option;
1112
extern int advice_commit_before_merge;
1213
extern int advice_resolve_conflict;
1314
extern int advice_implicit_identity;

t/t7060-wtstatus.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='basic work tree status reporting'
55
. ./test-lib.sh
66

77
test_expect_success setup '
8+
git config --global advice.statusuoption false &&
89
test_commit A &&
910
test_commit B oneside added &&
1011
git checkout A^0 &&

t/t7508-status.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test_description='git status'
88
. ./test-lib.sh
99

1010
test_expect_success 'status -h in broken repository' '
11+
git config --global advice.statusuoption false &&
1112
mkdir broken &&
1213
test_when_finished "rm -fr broken" &&
1314
(

t/t7512-status-help.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ test_description='git status advices'
1414
set_fake_editor
1515

1616
test_expect_success 'prepare for conflicts' '
17+
git config --global advice.statusuoption false &&
1718
test_commit init main.txt init &&
1819
git branch conflicts &&
1920
test_commit on_master main.txt on_master &&

wt-status.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,14 @@ static void wt_status_collect_untracked(struct wt_status *s)
496496
{
497497
int i;
498498
struct dir_struct dir;
499+
struct timeval t_begin;
499500

500501
if (!s->show_untracked_files)
501502
return;
503+
504+
if (advice_status_u_option)
505+
gettimeofday(&t_begin, NULL);
506+
502507
memset(&dir, 0, sizeof(dir));
503508
if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
504509
dir.flags |=
@@ -528,6 +533,14 @@ static void wt_status_collect_untracked(struct wt_status *s)
528533
}
529534

530535
free(dir.entries);
536+
537+
if (advice_status_u_option) {
538+
struct timeval t_end;
539+
gettimeofday(&t_end, NULL);
540+
s->untracked_in_ms =
541+
(uint64_t)t_end.tv_sec * 1000 + t_end.tv_usec / 1000 -
542+
((uint64_t)t_begin.tv_sec * 1000 + t_begin.tv_usec / 1000);
543+
}
531544
}
532545

533546
void wt_status_collect(struct wt_status *s)
@@ -1011,6 +1024,18 @@ void wt_status_print(struct wt_status *s)
10111024
wt_status_print_other(s, &s->untracked, _("Untracked files"), "add");
10121025
if (s->show_ignored_files)
10131026
wt_status_print_other(s, &s->ignored, _("Ignored files"), "add -f");
1027+
if (advice_status_u_option && 2000 < s->untracked_in_ms) {
1028+
status_printf_ln(s, GIT_COLOR_NORMAL, "");
1029+
status_printf_ln(s, GIT_COLOR_NORMAL,
1030+
_("It took %.2f seconds to enumerate untracked files."
1031+
" 'status -uno'"),
1032+
s->untracked_in_ms / 1000.0);
1033+
status_printf_ln(s, GIT_COLOR_NORMAL,
1034+
_("may speed it up, but you have to be careful not"
1035+
" to forget to add"));
1036+
status_printf_ln(s, GIT_COLOR_NORMAL,
1037+
_("new files yourself (see 'git help status')."));
1038+
}
10141039
} else if (s->commitable)
10151040
status_printf_ln(s, GIT_COLOR_NORMAL, _("Untracked files not listed%s"),
10161041
advice_status_hints

wt-status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct wt_status {
6969
struct string_list change;
7070
struct string_list untracked;
7171
struct string_list ignored;
72+
uint32_t untracked_in_ms;
7273
};
7374

7475
struct wt_status_state {

0 commit comments

Comments
 (0)