diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-04 10:37:07 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-04 10:46:32 +0300 |
commit | c466baa1c30afd14838f8cba97c6bca958ecc3f1 (patch) | |
tree | eedf49b673fe4030b836b9b81c6ba8c5914012d3 | |
parent | 8b14bc6b52f0ca20bf25a9c22abea76917a31cea (diff) |
localrepo: Speed up fetches by disabling computation of forced updatespks-git-fetch-disable-show-forced-updates
By default, git-fetch(1) will compute for every reference it's about to
fetch whether the update is a forced update or a normal one. This info
is used in two different ways:
1. To compute whether the branch update should be allowed in the
first place. This is pointless though in the case where we ask
git-fetch(1) to force all updates anyway.
2. To provide information via stdout whether the reference has been
force-updated or not. This is pointless in the case where we ask
git-fetch(1) to be quiet.
And while this check can indeed be quite expensive and take dozens of
seconds, git-fetch(1) will still perform it even when asked to be quiet
and to force-update any references.
Skip this computation when fetching into localrepos when forcing the
update and asking Git to be quiet.
Changelog: fixed
-rw-r--r-- | internal/git/localrepo/remote.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/git/localrepo/remote.go b/internal/git/localrepo/remote.go index 53b1ce67e..236ef3363 100644 --- a/internal/git/localrepo/remote.go +++ b/internal/git/localrepo/remote.go @@ -81,6 +81,11 @@ func (repo *Repo) FetchRemote(ctx context.Context, remoteName string, opts Fetch commandOptions := []git.CmdOpt{ git.WithEnv(opts.Env...), git.WithStderr(opts.Stderr), + git.WithConfig(git.ConfigPair{ + // Git is so kind to point out that we asked it to not show forced updates + // by default, so we need to ask it not to do that. + Key: "advice.fetchShowForcedUpdates", Value: "false", + }), } if opts.DisableTransactions { commandOptions = append(commandOptions, git.WithDisabledHooks()) @@ -135,6 +140,11 @@ func (repo *Repo) FetchInternal( GitProtocol: git.ProtocolV2, }, ), + git.WithConfig(git.ConfigPair{ + // Git is so kind to point out that we asked it to not show forced updates + // by default, so we need to ask it not to do that. + Key: "advice.fetchShowForcedUpdates", Value: "false", + }), } if opts.DisableTransactions { @@ -188,6 +198,13 @@ func (opts FetchOpts) buildFlags() []git.Option { flags = append(flags, git.Flag{Name: "--atomic"}) } + // Even if we ask Git to not print any output and to force-update branches it will still + // compute whether branches have been force-updated only to discard that information again. + // Let's ask it not to given that this check can be quite expensive. + if !opts.Verbose && opts.Force { + flags = append(flags, git.Flag{Name: "--no-show-forced-updates"}) + } + return flags } |