status: advise to consider use of -u when read_directory takes too long
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Wed, 13 Mar 2013 12:59:16 +0000 (19:59 +0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 Mar 2013 04:44:58 +0000 (21:44 -0700)
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 <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
advice.c
advice.h
t/t7060-wtstatus.sh
t/t7508-status.sh
t/t7512-status-help.sh
wt-status.c
wt-status.h
index d1de85778c8ac8ed6a562ceb9b4cd481f1df0f53..a16eda5d472a837ed3ded6c4802f34c5a32f4305 100644 (file)
@@ -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.
index edfbd4a6fb01a6905671d6d842d22c4869fad729..015011fe0dff7b01c42e13d3e53ceb1178cecfc9 100644 (file)
--- 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 },
index f3cdbbf29e570e151b2b6b329ee9a9940ae59a98..e3e665dc1806561d300120b9994260d80f8f84c2 100644 (file)
--- 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;
index f4f38a5e7387694e16ff6f4a54020843630c2ac7..52ef06b0005aabf2a201d20dbb5f232e3a26766a 100755 (executable)
@@ -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 &&
index e313ef196ed91a6ad12c70b147e2309af8fb4bfd..15e063a0fab64e9d3cbb0991c7d11288f5baecc0 100755 (executable)
@@ -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" &&
        (
index b3f6eb9c684c406dd896a144caa6afc160b03226..2d53e03f492fedc6e5223b9bafda6e5a4253a85a 100755 (executable)
@@ -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 &&
index 2a9658bad4c5035893e9363b51985f285dd3b34c..53c2222a4f7e20ea54ce17abab88e2b0eefb97d9 100644 (file)
@@ -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
index 236b41fd345ca3dd95ce450ac3fb3fca2b725e47..09420d038016c1affd663ecd4b6501635de753a2 100644 (file)
@@ -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 {