diff options
author | Rudy Rigot <rudy.rigot@gmail.com> | 2022-11-15 21:19:47 +0000 |
---|---|---|
committer | Taylor Blau <me@ttaylorr.com> | 2022-11-15 20:14:14 -0500 |
commit | 1396bc283aa0139e6a605e4413a249d1e866a14f (patch) | |
tree | 7cbbd16cee86b9502c720871f0e5a2054b75cab6 /wt-status.c | |
parent | 63bba4fdd86d80ef061c449daa97a981a9be0792 (diff) | |
download | git-1396bc283aa0139e6a605e4413a249d1e866a14f.tar.gz |
status: long status advice adapted to recent capabilities
Improve the advice displayed when `git status` is slow because
of excessive numbers of untracked files. Update the `git status`
man page to explain the various configuration options.
`git status` can be slow when there are a large number of untracked
files and directories, because Git must search the entire worktree
to enumerate them. Previously, Git would print an advice message
with the elapsed search time and a suggestion to disable the search
using the `-uno` option. This suggestion also carried a warning
that might scare off some users.
Git can reduce the size and time of the untracked file search when
the `core.untrackedCache` and `core.fsmonitor` features are enabled
by caching results from previous `git status` invocations.
Update the advice to explain the various combinations of additional
configuration options and refer to (new) documentation in the man
page that explains it in more detail than what can be printed in an
advice message.
Finally, add new tests to verify the new functionality.
Signed-off-by: Rudy Rigot <rudy.rigot@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 'wt-status.c')
-rw-r--r-- | wt-status.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/wt-status.c b/wt-status.c index 5813174896..1f6d64e759 100644 --- a/wt-status.c +++ b/wt-status.c @@ -18,8 +18,10 @@ #include "worktree.h" #include "lockfile.h" #include "sequencer.h" +#include "fsmonitor-settings.h" #define AB_DELAY_WARNING_IN_MS (2 * 1000) +#define UF_DELAY_WARNING_IN_MS (2 * 1000) static const char cut_line[] = "------------------------ >8 ------------------------\n"; @@ -1205,6 +1207,13 @@ static void wt_longstatus_print_tracking(struct wt_status *s) strbuf_release(&sb); } +static int uf_was_slow(uint32_t untracked_in_ms) +{ + if (getenv("GIT_TEST_UF_DELAY_WARNING")) + untracked_in_ms += UF_DELAY_WARNING_IN_MS + 1; + return UF_DELAY_WARNING_IN_MS < untracked_in_ms; +} + static void show_merge_in_progress(struct wt_status *s, const char *color) { @@ -1814,6 +1823,7 @@ static void wt_longstatus_print(struct wt_status *s) { const char *branch_color = color(WT_STATUS_ONBRANCH, s); const char *branch_status_color = color(WT_STATUS_HEADER, s); + enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(s->repo); if (s->branch) { const char *on_what = _("On branch "); @@ -1870,13 +1880,21 @@ static void wt_longstatus_print(struct wt_status *s) wt_longstatus_print_other(s, &s->untracked, _("Untracked files"), "add"); if (s->show_ignored_mode) wt_longstatus_print_other(s, &s->ignored, _("Ignored files"), "add -f"); - if (advice_enabled(ADVICE_STATUS_U_OPTION) && 2000 < s->untracked_in_ms) { + if (advice_enabled(ADVICE_STATUS_U_OPTION) && uf_was_slow(s->untracked_in_ms)) { status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); + if (fsm_mode > FSMONITOR_MODE_DISABLED) { + status_printf_ln(s, GIT_COLOR_NORMAL, + _("It took %.2f seconds to enumerate untracked files,\n" + "but the results were cached, and subsequent runs may be faster."), + s->untracked_in_ms / 1000.0); + } else { + status_printf_ln(s, GIT_COLOR_NORMAL, + _("It took %.2f seconds to enumerate untracked files."), + s->untracked_in_ms / 1000.0); + } status_printf_ln(s, GIT_COLOR_NORMAL, - _("It took %.2f seconds to enumerate untracked files. 'status -uno'\n" - "may speed it up, but you have to be careful not to forget to add\n" - "new files yourself (see 'git help status')."), - s->untracked_in_ms / 1000.0); + _("See 'git help status' for information on how to improve this.")); + status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); } } else if (s->committable) status_printf_ln(s, GIT_COLOR_NORMAL, _("Untracked files not listed%s"), |