]> git.ipfire.org Git - thirdparty/git.git/blobdiff - wt-status.c
object-name.h: move declarations for object-name.c functions from cache.h
[thirdparty/git.git] / wt-status.c
index 76e37a80883306cf02428b006e72e966fe954186..97b9c1c035974c269f5b9d042155e196d8193b10 100644 (file)
@@ -1,9 +1,14 @@
 #include "cache.h"
+#include "advice.h"
 #include "wt-status.h"
 #include "object.h"
 #include "dir.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
+#include "gettext.h"
+#include "hex.h"
+#include "object-name.h"
 #include "revision.h"
 #include "diffcore.h"
 #include "quote.h"
 #include "refs.h"
 #include "submodule.h"
 #include "column.h"
+#include "setup.h"
 #include "strbuf.h"
+#include "trace.h"
+#include "trace2.h"
 #include "utf8.h"
 #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 +1215,13 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
        strbuf_release(&sb);
 }
 
+static int uf_was_slow(struct wt_status *s)
+{
+       if (getenv("GIT_TEST_UF_DELAY_WARNING"))
+               s->untracked_in_ms = 3250;
+       return UF_DELAY_WARNING_IN_MS < s->untracked_in_ms;
+}
+
 static void show_merge_in_progress(struct wt_status *s,
                                   const char *color)
 {
@@ -1328,7 +1345,7 @@ static void abbrev_oid_in_line(struct strbuf *line)
                 * it after abbreviation.
                 */
                strbuf_trim(split[1]);
-               if (!get_oid(split[1]->buf, &oid)) {
+               if (!repo_get_oid(the_repository, split[1]->buf, &oid)) {
                        strbuf_reset(split[1]);
                        strbuf_add_unique_abbrev(split[1], &oid,
                                                 DEFAULT_ABBREV);
@@ -1494,8 +1511,8 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
        else
                status_printf_ln(s, color,
                        _("You are currently cherry-picking commit %s."),
-                       find_unique_abbrev(&s->state.cherry_pick_head_oid,
-                                          DEFAULT_ABBREV));
+                       repo_find_unique_abbrev(the_repository, &s->state.cherry_pick_head_oid,
+                                               DEFAULT_ABBREV));
 
        if (s->hints) {
                if (has_unmerged(s))
@@ -1524,8 +1541,8 @@ static void show_revert_in_progress(struct wt_status *s,
        else
                status_printf_ln(s, color,
                        _("You are currently reverting commit %s."),
-                       find_unique_abbrev(&s->state.revert_head_oid,
-                                          DEFAULT_ABBREV));
+                       repo_find_unique_abbrev(the_repository, &s->state.revert_head_oid,
+                                               DEFAULT_ABBREV));
        if (s->hints) {
                if (has_unmerged(s))
                        status_printf_ln(s, color,
@@ -1655,7 +1672,8 @@ static void wt_status_get_detached_from(struct repository *r,
                return;
        }
 
-       if (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref, 1) == 1 &&
+       if (repo_dwim_ref(r, cb.buf.buf, cb.buf.len, &oid, &ref,
+                         1) == 1 &&
            /* oid is a commit? match without further lookup */
            (oideq(&cb.noid, &oid) ||
             /* perhaps oid is a tag, try to dereference to a commit */
@@ -1667,9 +1685,9 @@ static void wt_status_get_detached_from(struct repository *r,
                state->detached_from = xstrdup(from);
        } else
                state->detached_from =
-                       xstrdup(find_unique_abbrev(&cb.noid, DEFAULT_ABBREV));
+                       xstrdup(repo_find_unique_abbrev(r, &cb.noid, DEFAULT_ABBREV));
        oidcpy(&state->detached_oid, &cb.noid);
-       state->detached_at = !get_oid("HEAD", &oid) &&
+       state->detached_at = !repo_get_oid(r, "HEAD", &oid) &&
                             oideq(&oid, &state->detached_oid);
 
        free(ref);
@@ -1760,13 +1778,13 @@ void wt_status_get_state(struct repository *r,
        } else if (wt_status_check_rebase(NULL, state)) {
                ;               /* all set */
        } else if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
-                  !get_oid("CHERRY_PICK_HEAD", &oid)) {
+                  !repo_get_oid(r, "CHERRY_PICK_HEAD", &oid)) {
                state->cherry_pick_in_progress = 1;
                oidcpy(&state->cherry_pick_head_oid, &oid);
        }
        wt_status_check_bisect(NULL, state);
        if (refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD") &&
-           !get_oid("REVERT_HEAD", &oid)) {
+           !repo_get_oid(r, "REVERT_HEAD", &oid)) {
                state->revert_in_progress = 1;
                oidcpy(&state->revert_head_oid, &oid);
        }
@@ -1814,6 +1832,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 +1889,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)) {
                        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"),