]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: warn about forced updates in branch listing
authorDerrick Stolee <dstolee@microsoft.com>
Tue, 18 Jun 2019 20:25:27 +0000 (13:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Jun 2019 16:38:29 +0000 (09:38 -0700)
The --[no-]show-forced-updates option in 'git fetch' can be confusing
for some users, especially if it is enabled via config setting and not
by argument. Add advice to warn the user that the (forced update)
messages were not listed.

Additionally, warn users when the forced update check takes longer
than ten seconds, and recommend that they disable the check. These
messages can be disabled by the advice.fetchShowForcedUpdates config
setting.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/advice.txt
advice.c
advice.h
builtin/fetch.c

index ec4f6ae6585bac4b107134e52f544d53c24cdf86..1f1e847fb4288ad5f9847b3b8f5aa09c3bfaae24 100644 (file)
@@ -4,6 +4,10 @@ advice.*::
        can tell Git that you do not need help by setting these to 'false':
 +
 --
+       fetchShowForcedUpdates::
+               Advice shown when linkgit:git-fetch[1] takes a long time
+               to calculate forced updates after ref updates, or to warn
+               that the check is disabled.
        pushUpdateRejected::
                Set this variable to 'false' if you want to disable
                'pushNonFFCurrent',
index ce5f374ecd4917346145c8a380ac8c0e45e849a4..4b283be51a8972584680ce7f2c5bc1ffc818ff83 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -3,6 +3,7 @@
 #include "color.h"
 #include "help.h"
 
+int advice_fetch_show_forced_updates = 1;
 int advice_push_update_rejected = 1;
 int advice_push_non_ff_current = 1;
 int advice_push_non_ff_matching = 1;
@@ -59,6 +60,7 @@ static struct {
        const char *name;
        int *preference;
 } advice_config[] = {
+       { "fetchShowForcedUpdates", &advice_fetch_show_forced_updates },
        { "pushUpdateRejected", &advice_push_update_rejected },
        { "pushNonFFCurrent", &advice_push_non_ff_current },
        { "pushNonFFMatching", &advice_push_non_ff_matching },
index e50f02cdfeff788910699f2d34fff1c93081c24b..495e53255cb09facc5b503af32044c47bb66d739 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -3,6 +3,7 @@
 
 #include "git-compat-util.h"
 
+extern int advice_fetch_show_forced_updates;
 extern int advice_push_update_rejected;
 extern int advice_push_non_ff_current;
 extern int advice_push_non_ff_matching;
index 571c2552181d485f73731538712508fc119dbbd0..cf7eb0dd8d48456e5ebfb61b9ebe7c5ff43fd470 100644 (file)
@@ -24,6 +24,8 @@
 #include "list-objects-filter-options.h"
 #include "commit-reach.h"
 
+#define FORCED_UPDATES_DELAY_WARNING_IN_MS (10 * 1000)
+
 static const char * const builtin_fetch_usage[] = {
        N_("git fetch [<options>] [<repository> [<refspec>...]]"),
        N_("git fetch [<options>] <group>"),
@@ -40,6 +42,7 @@ enum {
 
 static int fetch_prune_config = -1; /* unspecified */
 static int fetch_show_forced_updates = 1;
+static uint64_t forced_updates_ms = 0;
 static int prune = -1; /* unspecified */
 #define PRUNE_BY_DEFAULT 0 /* do we prune by default? */
 
@@ -707,6 +710,7 @@ static int update_local_ref(struct ref *ref,
        enum object_type type;
        struct branch *current_branch = branch_get(NULL);
        const char *pretty_ref = prettify_refname(ref->name);
+       int fast_forward = 0;
 
        type = oid_object_info(the_repository, &ref->new_oid, NULL);
        if (type < 0)
@@ -781,7 +785,15 @@ static int update_local_ref(struct ref *ref,
                return r;
        }
 
-       if (!fetch_show_forced_updates || in_merge_bases(current, updated)) {
+       if (fetch_show_forced_updates) {
+               uint64_t t_before = getnanotime();
+               fast_forward = in_merge_bases(current, updated);
+               forced_updates_ms += (getnanotime() - t_before) / 1000000;
+       } else {
+               fast_forward = 1;
+       }
+
+       if (fast_forward) {
                struct strbuf quickref = STRBUF_INIT;
                int r;
 
@@ -980,6 +992,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
                      " 'git remote prune %s' to remove any old, conflicting "
                      "branches"), remote_name);
 
+       if (advice_fetch_show_forced_updates) {
+               if (!fetch_show_forced_updates) {
+                       warning(_("Fetch normally indicates which branches had a forced update, but that check has been disabled."));
+                       warning(_("To re-enable, use '--show-forced-updates' flag or run 'git config fetch.showForcedUpdates true'."));
+               } else if (forced_updates_ms > FORCED_UPDATES_DELAY_WARNING_IN_MS) {
+                       warning(_("It took %.2f seconds to check forced updates. You can use '--no-show-forced-updates'\n"),
+                               forced_updates_ms / 1000.0);
+                       warning(_("or run 'git config fetch.showForcedUpdates false' to avoid this check.\n"));
+               }
+       }
+
  abort:
        strbuf_release(&note);
        free(url);