From 73fac91fc54a5203cc977b6e79d6f812d7d7bbb8 Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Fri, 8 Mar 2019 18:44:19 +0000 Subject: [PATCH] Avoid unnecessary invocations of "git fetch" (reland) If we already have the correct commit, it is not necessary to fetch. Any fetches can takes minutes due to gerrit problems, and often fail completely, so it is helpful to avoid them completely whenever we can. Reland now that skia autoroller does its own fetch. Bug: 938627 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1504102 Commit-Queue: Michael Spang Reviewed-by: Edward Lesmes Change-Id: I5a6877125c682ff0d98bd6d2ffe495245f74c513 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1512024 Auto-Submit: Michael Spang Commit-Queue: Edward Lesmes Reviewed-by: Edward Lesmes --- gclient_scm.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gclient_scm.py b/gclient_scm.py index 7bed91540..a95bdab83 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -657,14 +657,18 @@ class GitWrapper(SCMWrapper): raise gclient_utils.Error('Invalid Upstream: %s' % upstream_branch) self._SetFetchConfig(options) - self._Fetch(options, prune=options.force) + # Fetch upstream if we don't already have |revision|. if not scm.GIT.IsValidRevision(self.checkout_path, revision, sha_only=True): - # Update the remotes first so we have all the refs. - remote_output = scm.GIT.Capture(['remote'] + verbose + ['update'], - cwd=self.checkout_path) - if verbose: - self.Print(remote_output) + self._Fetch(options, prune=options.force) + + if not scm.GIT.IsValidRevision(self.checkout_path, revision, + sha_only=True): + # Update the remotes first so we have all the refs. + remote_output = scm.GIT.Capture(['remote'] + verbose + ['update'], + cwd=self.checkout_path) + if verbose: + self.Print(remote_output) revision = self._AutoFetchRef(options, revision)