Skip to content

Commit 5386123

Browse files
committed
Merge 'forced-updates-after-branch-list'
Move the warning about `--[no-]show-forced-updates` to the end of the branch update list. Also, show a different message when a lot of time is spent walking the commits. (Note, this time will not include the loose object downloads for the tip commits, but may include some loose object downloads for the reachable commits.)
2 parents abfe908 + 61e9e80 commit 5386123

3 files changed

Lines changed: 45 additions & 9 deletions

File tree

Documentation/fetch-options.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ endif::git-pull[]
220220
When multiple `--server-option=<option>` are given, they are all
221221
sent to the other side in the order listed on the command line.
222222

223+
--show-forced-updates::
224+
By default, git checks if a branch is force-updated during
225+
fetch. This can be disabled through fetch.showForcedUpdates, but
226+
the --show-forced-updates option guarantees this check occurs.
227+
See linkgit:git-config[1].
228+
229+
--no-show-forced-updates::
230+
By default, git checks if a branch is force-updated during
231+
fetch. Pass --no-show-forced-updates or set fetch.showForcedUpdates
232+
to false to skip this check for performance reasons. If used during
233+
'git-pull' the --ff-only option will still check for forced updates
234+
before attempting a fast-forward update. See linkgit:git-config[1].
235+
223236
-4::
224237
--ipv4::
225238
Use IPv4 addresses only, ignoring IPv6 addresses.

builtin/fetch.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "list-objects-filter-options.h"
2525
#include "commit-reach.h"
2626

27+
#define FORCED_UPDATES_DELAY_WARNING_IN_MS (10 * 1000)
28+
2729
static const char * const builtin_fetch_usage[] = {
2830
N_("git fetch [<options>] [<repository> [<refspec>...]]"),
2931
N_("git fetch [<options>] <group>"),
@@ -41,6 +43,7 @@ enum {
4143
static int fetch_prune_config = -1; /* unspecified */
4244
static int fetch_show_forced_updates = 1;
4345
static int fetch_show_forced_updates_warning = 0;
46+
static uint64_t forced_updates_ms = 0;
4447
static int prune = -1; /* unspecified */
4548
#define PRUNE_BY_DEFAULT 0 /* do we prune by default? */
4649

@@ -708,6 +711,7 @@ static int update_local_ref(struct ref *ref,
708711
enum object_type type;
709712
struct branch *current_branch = branch_get(NULL);
710713
const char *pretty_ref = prettify_refname(ref->name);
714+
int fast_forward = 0;
711715

712716
type = oid_object_info(the_repository, &ref->new_oid, NULL);
713717
if (type < 0)
@@ -782,18 +786,19 @@ static int update_local_ref(struct ref *ref,
782786
return r;
783787
}
784788

785-
if (!fetch_show_forced_updates || in_merge_bases(current, updated)) {
789+
if (fetch_show_forced_updates) {
790+
uint64_t t_before = getnanotime();
791+
fast_forward = in_merge_bases(current, updated);
792+
forced_updates_ms += (getnanotime() - t_before) / 1000000;
793+
} else {
794+
fetch_show_forced_updates_warning = 1;
795+
fast_forward = 1;
796+
}
797+
798+
if (fast_forward) {
786799
struct strbuf quickref = STRBUF_INIT;
787800
int r;
788801

789-
if (!fetch_show_forced_updates && !fetch_show_forced_updates_warning) {
790-
fetch_show_forced_updates_warning = 1;
791-
warning(_("Fetch normally indicates which branches had a forced update, but that check has been disabled."));
792-
warning(_("To re-enable, use '--show-forced-updates' flag or run 'git config fetch.showForcedUpdates true'."));
793-
warning(_("OR if you just want to check if a branch with name <branch> was force-updated after fetching, run:"));
794-
warning(_(" git rev-list --left-right --count <branch>...<branch>@{1}"));
795-
}
796-
797802
strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
798803
strbuf_addstr(&quickref, "..");
799804
strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
@@ -989,6 +994,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
989994
" 'git remote prune %s' to remove any old, conflicting "
990995
"branches"), remote_name);
991996

997+
if (!fetch_show_forced_updates && fetch_show_forced_updates_warning) {
998+
warning(_("Fetch normally indicates which branches had a forced update, but that check has been disabled."));
999+
warning(_("To re-enable, use '--show-forced-updates' flag or run 'git config fetch.showForcedUpdates true'."));
1000+
}
1001+
if (fetch_show_forced_updates &&
1002+
forced_updates_ms > FORCED_UPDATES_DELAY_WARNING_IN_MS) {
1003+
warning(_("It took %.2f seconds to check forced updates. You can use '--no-show-forced-updates'\n"),
1004+
forced_updates_ms / 1000.0);
1005+
warning(_("or run 'git config fetch.showForcedUpdates false' to avoid this check.\n"));
1006+
}
1007+
9921008
abort:
9931009
strbuf_release(&note);
9941010
free(url);

builtin/pull.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static char *opt_update_shallow;
122122
static char *opt_refmap;
123123
static char *opt_ipv4;
124124
static char *opt_ipv6;
125+
static int opt_show_forced_updates = -1;
125126

126127
static struct option pull_options[] = {
127128
/* Shared options */
@@ -233,6 +234,8 @@ static struct option pull_options[] = {
233234
OPT_PASSTHRU('6', "ipv6", &opt_ipv6, NULL,
234235
N_("use IPv6 addresses only"),
235236
PARSE_OPT_NOARG),
237+
OPT_BOOL(0, "show-forced-updates", &opt_show_forced_updates,
238+
N_("check for forced-updates on all updated branches")),
236239

237240
OPT_END()
238241
};
@@ -541,6 +544,10 @@ static int run_fetch(const char *repo, const char **refspecs)
541544
argv_array_push(&args, opt_ipv4);
542545
if (opt_ipv6)
543546
argv_array_push(&args, opt_ipv6);
547+
if (opt_show_forced_updates > 0)
548+
argv_array_push(&args, "--show-forced-updates");
549+
else if (opt_show_forced_updates == 0)
550+
argv_array_push(&args, "--no-show-forced-updates");
544551

545552
if (repo) {
546553
argv_array_push(&args, repo);

0 commit comments

Comments
 (0)