From 5823eb2b28696bf0eb25f6ca35b303447869f85c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 15 Mar 2013 09:53:48 -0700 Subject: git status: document trade-offs in choosing parameters to the -u option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some repostories users experience that "git status" command takes long time. The command spends some time searching the file system for untracked files. Explain the trade-off struck by the default choice of `normal` to help users make an appropriate choice better, before talking about the configuration variable. Inspired by Torsten Bögershausen. Signed-off-by: Junio C Hamano --- Documentation/git-status.txt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt index 67e5f53a9e..00d5951012 100644 --- a/Documentation/git-status.txt +++ b/Documentation/git-status.txt @@ -43,15 +43,21 @@ OPTIONS Show untracked files. + The mode parameter is optional (defaults to 'all'), and is used to -specify the handling of untracked files; when -u is not used, the -default is 'normal', i.e. show untracked files and directories. +specify the handling of untracked files. + The possible options are: + - - 'no' - Show no untracked files - - 'normal' - Shows untracked files and directories + - 'no' - Show no untracked files. + - 'normal' - Shows untracked files and directories. - 'all' - Also shows individual files in untracked directories. + +When `-u` option is not used, untracked files and directories are +shown (i.e. the same as specifying `normal`), to help you avoid +forgetting to add newly created files. Because it takes extra work +to find untracked files in the filesystem, this mode may take some +time in a large working tree. You can use `no` to have `git status` +return more quickly without showing untracked files. ++ The default can be changed using the status.showUntrackedFiles configuration variable documented in linkgit:git-config[1]. -- cgit v1.2.3 From 6a38ef2ced55f0a8a7967581934e40f79e1d8733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 13 Mar 2013 19:59:16 +0700 Subject: status: advise to consider use of -u when read_directory takes too long MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- Documentation/config.txt | 4 ++++ advice.c | 2 ++ advice.h | 1 + t/t7060-wtstatus.sh | 1 + t/t7508-status.sh | 1 + t/t7512-status-help.sh | 1 + wt-status.c | 25 +++++++++++++++++++++++++ wt-status.h | 1 + 8 files changed, 36 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index d1de85778c..a16eda5d47 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -163,6 +163,10 @@ advice.*:: state in the output of linkgit:git-status[1] and in the template shown when writing commit messages in linkgit:git-commit[1]. + statusUoption:: + Advise to consider using the `-u` option to linkgit:git-status[1] + when the command takes more than 2 seconds to enumerate untracked + files. commitBeforeMerge:: Advice shown when linkgit:git-merge[1] refuses to merge to avoid overwriting local changes. diff --git a/advice.c b/advice.c index edfbd4a6fb..015011fe0d 100644 --- a/advice.c +++ b/advice.c @@ -5,6 +5,7 @@ int advice_push_non_ff_current = 1; int advice_push_non_ff_default = 1; int advice_push_non_ff_matching = 1; int advice_status_hints = 1; +int advice_status_u_option = 1; int advice_commit_before_merge = 1; int advice_resolve_conflict = 1; int advice_implicit_identity = 1; @@ -19,6 +20,7 @@ static struct { { "pushnonffdefault", &advice_push_non_ff_default }, { "pushnonffmatching", &advice_push_non_ff_matching }, { "statushints", &advice_status_hints }, + { "statusuoption", &advice_status_u_option }, { "commitbeforemerge", &advice_commit_before_merge }, { "resolveconflict", &advice_resolve_conflict }, { "implicitidentity", &advice_implicit_identity }, diff --git a/advice.h b/advice.h index f3cdbbf29e..e3e665dc18 100644 --- a/advice.h +++ b/advice.h @@ -8,6 +8,7 @@ extern int advice_push_non_ff_current; extern int advice_push_non_ff_default; extern int advice_push_non_ff_matching; extern int advice_status_hints; +extern int advice_status_u_option; extern int advice_commit_before_merge; extern int advice_resolve_conflict; extern int advice_implicit_identity; diff --git a/t/t7060-wtstatus.sh b/t/t7060-wtstatus.sh index f4f38a5e73..52ef06b000 100755 --- a/t/t7060-wtstatus.sh +++ b/t/t7060-wtstatus.sh @@ -5,6 +5,7 @@ test_description='basic work tree status reporting' . ./test-lib.sh test_expect_success setup ' + git config --global advice.statusuoption false && test_commit A && test_commit B oneside added && git checkout A^0 && diff --git a/t/t7508-status.sh b/t/t7508-status.sh index e313ef196e..15e063a0fa 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -8,6 +8,7 @@ test_description='git status' . ./test-lib.sh test_expect_success 'status -h in broken repository' ' + git config --global advice.statusuoption false && mkdir broken && test_when_finished "rm -fr broken" && ( diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh index b3f6eb9c68..2d53e03f49 100755 --- a/t/t7512-status-help.sh +++ b/t/t7512-status-help.sh @@ -14,6 +14,7 @@ test_description='git status advices' set_fake_editor test_expect_success 'prepare for conflicts' ' + git config --global advice.statusuoption false && test_commit init main.txt init && git branch conflicts && test_commit on_master main.txt on_master && diff --git a/wt-status.c b/wt-status.c index 2a9658bad4..53c2222a4f 100644 --- a/wt-status.c +++ b/wt-status.c @@ -496,9 +496,14 @@ static void wt_status_collect_untracked(struct wt_status *s) { int i; struct dir_struct dir; + struct timeval t_begin; if (!s->show_untracked_files) return; + + if (advice_status_u_option) + gettimeofday(&t_begin, NULL); + memset(&dir, 0, sizeof(dir)); if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES) dir.flags |= @@ -528,6 +533,14 @@ static void wt_status_collect_untracked(struct wt_status *s) } free(dir.entries); + + if (advice_status_u_option) { + struct timeval t_end; + gettimeofday(&t_end, NULL); + s->untracked_in_ms = + (uint64_t)t_end.tv_sec * 1000 + t_end.tv_usec / 1000 - + ((uint64_t)t_begin.tv_sec * 1000 + t_begin.tv_usec / 1000); + } } void wt_status_collect(struct wt_status *s) @@ -1011,6 +1024,18 @@ void wt_status_print(struct wt_status *s) wt_status_print_other(s, &s->untracked, _("Untracked files"), "add"); if (s->show_ignored_files) wt_status_print_other(s, &s->ignored, _("Ignored files"), "add -f"); + if (advice_status_u_option && 2000 < s->untracked_in_ms) { + status_printf_ln(s, GIT_COLOR_NORMAL, ""); + status_printf_ln(s, GIT_COLOR_NORMAL, + _("It took %.2f seconds to enumerate untracked files." + " 'status -uno'"), + s->untracked_in_ms / 1000.0); + status_printf_ln(s, GIT_COLOR_NORMAL, + _("may speed it up, but you have to be careful not" + " to forget to add")); + status_printf_ln(s, GIT_COLOR_NORMAL, + _("new files yourself (see 'git help status').")); + } } else if (s->commitable) status_printf_ln(s, GIT_COLOR_NORMAL, _("Untracked files not listed%s"), advice_status_hints diff --git a/wt-status.h b/wt-status.h index 236b41fd34..09420d0380 100644 --- a/wt-status.h +++ b/wt-status.h @@ -69,6 +69,7 @@ struct wt_status { struct string_list change; struct string_list untracked; struct string_list ignored; + uint32_t untracked_in_ms; }; struct wt_status_state { -- cgit v1.2.3