|
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>"), |
|
39 | 41 | }; |
40 | 42 |
|
41 | 43 | static int fetch_prune_config = -1; /* unspecified */ |
| 44 | +static int fetch_show_forced_updates = 1; |
| 45 | +static uint64_t forced_updates_ms = 0; |
42 | 46 | static int prune = -1; /* unspecified */ |
43 | 47 | #define PRUNE_BY_DEFAULT 0 /* do we prune by default? */ |
44 | 48 |
|
@@ -80,6 +84,11 @@ static int git_fetch_config(const char *k, const char *v, void *cb) |
80 | 84 | return 0; |
81 | 85 | } |
82 | 86 |
|
| 87 | + if (!strcmp(k, "fetch.showforcedupdates")) { |
| 88 | + fetch_show_forced_updates = git_config_bool(k, v); |
| 89 | + return 0; |
| 90 | + } |
| 91 | + |
83 | 92 | if (!strcmp(k, "submodule.recurse")) { |
84 | 93 | int r = git_config_bool(k, v) ? |
85 | 94 | RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF; |
@@ -172,6 +181,8 @@ static struct option builtin_fetch_options[] = { |
172 | 181 | OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options), |
173 | 182 | OPT_BOOL(0, "auto-gc", &enable_auto_gc, |
174 | 183 | N_("run 'gc --auto' after fetching")), |
| 184 | + OPT_BOOL(0, "show-forced-updates", &fetch_show_forced_updates, |
| 185 | + N_("check for forced-updates on all updated branches")), |
175 | 186 | OPT_END() |
176 | 187 | }; |
177 | 188 |
|
@@ -710,6 +721,7 @@ static int update_local_ref(struct ref *ref, |
710 | 721 | enum object_type type; |
711 | 722 | struct branch *current_branch = branch_get(NULL); |
712 | 723 | const char *pretty_ref = prettify_refname(ref->name); |
| 724 | + int fast_forward = 0; |
713 | 725 |
|
714 | 726 | type = oid_object_info(the_repository, &ref->new_oid, NULL); |
715 | 727 | if (type < 0) |
@@ -784,9 +796,18 @@ static int update_local_ref(struct ref *ref, |
784 | 796 | return r; |
785 | 797 | } |
786 | 798 |
|
787 | | - if (in_merge_bases(current, updated)) { |
| 799 | + if (fetch_show_forced_updates) { |
| 800 | + uint64_t t_before = getnanotime(); |
| 801 | + fast_forward = in_merge_bases(current, updated); |
| 802 | + forced_updates_ms += (getnanotime() - t_before) / 1000000; |
| 803 | + } else { |
| 804 | + fast_forward = 1; |
| 805 | + } |
| 806 | + |
| 807 | + if (fast_forward) { |
788 | 808 | struct strbuf quickref = STRBUF_INIT; |
789 | 809 | int r; |
| 810 | + |
790 | 811 | strbuf_add_unique_abbrev(&quickref, ¤t->object.oid, DEFAULT_ABBREV); |
791 | 812 | strbuf_addstr(&quickref, ".."); |
792 | 813 | strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV); |
@@ -982,6 +1003,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, |
982 | 1003 | " 'git remote prune %s' to remove any old, conflicting " |
983 | 1004 | "branches"), remote_name); |
984 | 1005 |
|
| 1006 | + if (advice_fetch_show_forced_updates) { |
| 1007 | + if (!fetch_show_forced_updates) { |
| 1008 | + warning(_("Fetch normally indicates which branches had a forced update, but that check has been disabled.")); |
| 1009 | + warning(_("To re-enable, use '--show-forced-updates' flag or run 'git config fetch.showForcedUpdates true'.")); |
| 1010 | + } else if (forced_updates_ms > FORCED_UPDATES_DELAY_WARNING_IN_MS) { |
| 1011 | + warning(_("It took %.2f seconds to check forced updates. You can use '--no-show-forced-updates'\n"), |
| 1012 | + forced_updates_ms / 1000.0); |
| 1013 | + warning(_("or run 'git config fetch.showForcedUpdates false' to avoid this check.\n")); |
| 1014 | + } |
| 1015 | + } |
| 1016 | + |
985 | 1017 | abort: |
986 | 1018 | strbuf_release(¬e); |
987 | 1019 | free(url); |
|
0 commit comments