Skip to content

Commit fec274b

Browse files
committed
Merge branch 'tb/document-status-u-tradeoff' into maint
* tb/document-status-u-tradeoff: status: advise to consider use of -u when read_directory takes too long git status: document trade-offs in choosing parameters to the -u option
2 parents 41e603a + 6a38ef2 commit fec274b

9 files changed

Lines changed: 46 additions & 4 deletions

File tree

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ advice.*::
178178
the template shown when writing commit messages in
179179
linkgit:git-commit[1], and in the help message shown
180180
by linkgit:git-checkout[1] when switching branch.
181+
statusUoption::
182+
Advise to consider using the `-u` option to linkgit:git-status[1]
183+
when the command takes more than 2 seconds to enumerate untracked
184+
files.
181185
commitBeforeMerge::
182186
Advice shown when linkgit:git-merge[1] refuses to
183187
merge to avoid overwriting local changes.

Documentation/git-status.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,21 @@ OPTIONS
4646
Show untracked files.
4747
+
4848
The mode parameter is optional (defaults to 'all'), and is used to
49-
specify the handling of untracked files; when -u is not used, the
50-
default is 'normal', i.e. show untracked files and directories.
49+
specify the handling of untracked files.
5150
+
5251
The possible options are:
5352
+
54-
- 'no' - Show no untracked files
55-
- 'normal' - Shows untracked files and directories
53+
- 'no' - Show no untracked files.
54+
- 'normal' - Shows untracked files and directories.
5655
- 'all' - Also shows individual files in untracked directories.
5756
+
57+
When `-u` option is not used, untracked files and directories are
58+
shown (i.e. the same as specifying `normal`), to help you avoid
59+
forgetting to add newly created files. Because it takes extra work
60+
to find untracked files in the filesystem, this mode may take some
61+
time in a large working tree. You can use `no` to have `git status`
62+
return more quickly without showing untracked files.
63+
+
5864
The default can be changed using the status.showUntrackedFiles
5965
configuration variable documented in linkgit:git-config[1].
6066

advice.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ int advice_push_already_exists = 1;
88
int advice_push_fetch_first = 1;
99
int advice_push_needs_force = 1;
1010
int advice_status_hints = 1;
11+
int advice_status_u_option = 1;
1112
int advice_commit_before_merge = 1;
1213
int advice_resolve_conflict = 1;
1314
int advice_implicit_identity = 1;
@@ -25,6 +26,7 @@ static struct {
2526
{ "pushfetchfirst", &advice_push_fetch_first },
2627
{ "pushneedsforce", &advice_push_needs_force },
2728
{ "statushints", &advice_status_hints },
29+
{ "statusuoption", &advice_status_u_option },
2830
{ "commitbeforemerge", &advice_commit_before_merge },
2931
{ "resolveconflict", &advice_resolve_conflict },
3032
{ "implicitidentity", &advice_implicit_identity },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern int advice_push_already_exists;
1111
extern int advice_push_fetch_first;
1212
extern int advice_push_needs_force;
1313
extern int advice_status_hints;
14+
extern int advice_status_u_option;
1415
extern int advice_commit_before_merge;
1516
extern int advice_resolve_conflict;
1617
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 advice'
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
@@ -499,9 +499,14 @@ static void wt_status_collect_untracked(struct wt_status *s)
499499
{
500500
int i;
501501
struct dir_struct dir;
502+
struct timeval t_begin;
502503

503504
if (!s->show_untracked_files)
504505
return;
506+
507+
if (advice_status_u_option)
508+
gettimeofday(&t_begin, NULL);
509+
505510
memset(&dir, 0, sizeof(dir));
506511
if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
507512
dir.flags |=
@@ -533,6 +538,14 @@ static void wt_status_collect_untracked(struct wt_status *s)
533538
}
534539

535540
free(dir.entries);
541+
542+
if (advice_status_u_option) {
543+
struct timeval t_end;
544+
gettimeofday(&t_end, NULL);
545+
s->untracked_in_ms =
546+
(uint64_t)t_end.tv_sec * 1000 + t_end.tv_usec / 1000 -
547+
((uint64_t)t_begin.tv_sec * 1000 + t_begin.tv_usec / 1000);
548+
}
536549
}
537550

538551
void wt_status_collect(struct wt_status *s)
@@ -1100,6 +1113,18 @@ void wt_status_print(struct wt_status *s)
11001113
wt_status_print_other(s, &s->untracked, _("Untracked files"), "add");
11011114
if (s->show_ignored_files)
11021115
wt_status_print_other(s, &s->ignored, _("Ignored files"), "add -f");
1116+
if (advice_status_u_option && 2000 < s->untracked_in_ms) {
1117+
status_printf_ln(s, GIT_COLOR_NORMAL, "");
1118+
status_printf_ln(s, GIT_COLOR_NORMAL,
1119+
_("It took %.2f seconds to enumerate untracked files."
1120+
" 'status -uno'"),
1121+
s->untracked_in_ms / 1000.0);
1122+
status_printf_ln(s, GIT_COLOR_NORMAL,
1123+
_("may speed it up, but you have to be careful not"
1124+
" to forget to add"));
1125+
status_printf_ln(s, GIT_COLOR_NORMAL,
1126+
_("new files yourself (see 'git help status')."));
1127+
}
11031128
} else if (s->commitable)
11041129
status_printf_ln(s, GIT_COLOR_NORMAL, _("Untracked files not listed%s"),
11051130
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)