Skip to content

Commit

Permalink
Merge 'forced-updates-after-branch-list'
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
derrickstolee authored and dscho committed Feb 26, 2018
2 parents bf79cca + e263fd4 commit 869d868
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
13 changes: 13 additions & 0 deletions Documentation/fetch-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ endif::git-pull[]
is specified. This flag forces progress status even if the
standard error stream is not directed to a terminal.

--show-forced-updates::
By default, git checks if a branch is force-updated during
fetch. This can be disabled through fetch.showForcedUpdates, but
the --show-forced-updates option guarantees this check occurs.
See linkgit:git-config[1].

--no-show-forced-updates::
By default, git checks if a branch is force-updated during
fetch. Pass --no-show-forced-updates or set fetch.showForcedUpdates
to false to skip this check for performance reasons. If used during
'git-pull' the --ff-only option will still check for forced updates
before attempting a fast-forward update. See linkgit:git-config[1].

-4::
--ipv4::
Use IPv4 addresses only, ignoring IPv6 addresses.
Expand Down
34 changes: 25 additions & 9 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "utf8.h"
#include "packfile.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>"),
Expand All @@ -37,6 +39,7 @@ enum {
static int fetch_prune_config = -1; /* unspecified */
static int fetch_show_forced_updates = 1;
static int fetch_show_forced_updates_warning = 0;
static uint64_t forced_updates_ms = 0;
static int prune = -1; /* unspecified */
#define PRUNE_BY_DEFAULT 0 /* do we prune by default? */

Expand Down Expand Up @@ -631,6 +634,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 = sha1_object_info(ref->new_oid.hash, NULL);
if (type < 0)
Expand Down Expand Up @@ -700,18 +704,19 @@ 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 {
fetch_show_forced_updates_warning = 1;
fast_forward = 1;
}

if (fast_forward) {
struct strbuf quickref = STRBUF_INIT;
int r;

if (!fetch_show_forced_updates && !fetch_show_forced_updates_warning) {
fetch_show_forced_updates_warning = 1;
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'."));
warning(_("OR if you just want to check if a branch with name <branch> was force-updated after fetching, run:"));
warning(_(" git rev-list --left-right --count <branch>...<branch>@{1}"));
}

strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV);
strbuf_addstr(&quickref, "..");
strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV);
Expand Down Expand Up @@ -908,6 +913,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 (!fetch_show_forced_updates && fetch_show_forced_updates_warning) {
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'."));
}
if (fetch_show_forced_updates &&
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);
Expand Down
7 changes: 7 additions & 0 deletions builtin/pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ static char *opt_update_shallow;
static char *opt_refmap;
static char *opt_ipv4;
static char *opt_ipv6;
static int opt_show_forced_updates = 1;

static struct option pull_options[] = {
/* Shared options */
Expand Down Expand Up @@ -226,6 +227,8 @@ static struct option pull_options[] = {
OPT_PASSTHRU('6', "ipv6", &opt_ipv6, NULL,
N_("use IPv6 addresses only"),
PARSE_OPT_NOARG),
OPT_BOOL(0, "show-forced-updates", &opt_show_forced_updates,
N_("check for forced-updates on all updated branches")),

OPT_END()
};
Expand Down Expand Up @@ -534,6 +537,10 @@ static int run_fetch(const char *repo, const char **refspecs)
argv_array_push(&args, opt_ipv4);
if (opt_ipv6)
argv_array_push(&args, opt_ipv6);
if (opt_show_forced_updates)
argv_array_push(&args, "--show-forced-updates");
else
argv_array_push(&args, "--no-show-forced-updates");

if (repo) {
argv_array_push(&args, repo);
Expand Down

0 comments on commit 869d868

Please sign in to comment.