|
24 | 24 | #include "list-objects-filter-options.h"
|
25 | 25 | #include "commit-reach.h"
|
26 | 26 |
|
| 27 | +#define FORCED_UPDATES_DELAY_WARNING_IN_MS (10 * 1000) |
| 28 | + |
27 | 29 | static const char * const builtin_fetch_usage[] = {
|
28 | 30 | N_("git fetch [<options>] [<repository> [<refspec>...]]"),
|
29 | 31 | N_("git fetch [<options>] <group>"),
|
|
40 | 42 |
|
41 | 43 | static int fetch_prune_config = -1; /* unspecified */
|
42 | 44 | static int fetch_show_forced_updates = 1;
|
| 45 | +static uint64_t forced_updates_ms = 0; |
43 | 46 | static int prune = -1; /* unspecified */
|
44 | 47 | #define PRUNE_BY_DEFAULT 0 /* do we prune by default? */
|
45 | 48 |
|
@@ -707,6 +710,7 @@ static int update_local_ref(struct ref *ref,
|
707 | 710 | enum object_type type;
|
708 | 711 | struct branch *current_branch = branch_get(NULL);
|
709 | 712 | const char *pretty_ref = prettify_refname(ref->name);
|
| 713 | + int fast_forward = 0; |
710 | 714 |
|
711 | 715 | type = oid_object_info(the_repository, &ref->new_oid, NULL);
|
712 | 716 | if (type < 0)
|
@@ -781,7 +785,15 @@ static int update_local_ref(struct ref *ref,
|
781 | 785 | return r;
|
782 | 786 | }
|
783 | 787 |
|
784 |
| - if (!fetch_show_forced_updates || in_merge_bases(current, updated)) { |
| 788 | + if (fetch_show_forced_updates) { |
| 789 | + uint64_t t_before = getnanotime(); |
| 790 | + fast_forward = in_merge_bases(current, updated); |
| 791 | + forced_updates_ms += (getnanotime() - t_before) / 1000000; |
| 792 | + } else { |
| 793 | + fast_forward = 1; |
| 794 | + } |
| 795 | + |
| 796 | + if (fast_forward) { |
785 | 797 | struct strbuf quickref = STRBUF_INIT;
|
786 | 798 | int r;
|
787 | 799 |
|
@@ -980,6 +992,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
|
980 | 992 | " 'git remote prune %s' to remove any old, conflicting "
|
981 | 993 | "branches"), remote_name);
|
982 | 994 |
|
| 995 | + if (advice_fetch_show_forced_updates) { |
| 996 | + if (!fetch_show_forced_updates) { |
| 997 | + warning(_("Fetch normally indicates which branches had a forced update, but that check has been disabled.")); |
| 998 | + warning(_("To re-enable, use '--show-forced-updates' flag or run 'git config fetch.showForcedUpdates true'.")); |
| 999 | + } else if (forced_updates_ms > FORCED_UPDATES_DELAY_WARNING_IN_MS) { |
| 1000 | + warning(_("It took %.2f seconds to check forced updates. You can use '--no-show-forced-updates'\n"), |
| 1001 | + forced_updates_ms / 1000.0); |
| 1002 | + warning(_("or run 'git config fetch.showForcedUpdates false' to avoid this check.\n")); |
| 1003 | + } |
| 1004 | + } |
| 1005 | + |
983 | 1006 | abort:
|
984 | 1007 | strbuf_release(¬e);
|
985 | 1008 | free(url);
|
|
0 commit comments