Reset alternates when the git_cache dir is updated

When cache URL is updated, `gclient sync` appends the new cache path as
an additional alternate object db instead of overriding the old alternate object db. This was done to support reusing cache while changing mirror path. However, when the cache is reset by LUCI, gclient
appends the new mirror path instead of overwriting the existing one.
This results in failed builds where `git fetch` looks for non-existent
alternate object dbs.

Bug: 1428312
Change-Id: Ib10e0b966ddef8793415cf8ef0eddbec13ba1a8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4379380
Reviewed-by: Joanna Wang <jojwang@chromium.org>
Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
changes/80/4379380/4
Aravind Vasudevan 2 years ago committed by LUCI CQ
parent 4a7343007c
commit cf46585793

@ -698,15 +698,24 @@ class GitWrapper(SCMWrapper):
# Switch over to the new upstream
self._Run(['remote', 'set-url', self.remote, url], options)
if mirror:
# Because we use Git alternatives, our existing repository is not
# self-contained. It's possible that new git alternative doesn't have
# all necessary objects that the current repository needs. Instead of
# blindly hoping that new alternative contains all necessary objects,
# keep the old alternative and just append a new one on top of it.
with open(os.path.join(
self.checkout_path, '.git', 'objects', 'info', 'alternates'),
'a') as fh:
fh.write("\n" + os.path.join(url, 'objects'))
if git_cache.Mirror.CacheDirToUrl(
current_url.rstrip('/')) == git_cache.Mirror.CacheDirToUrl(
url.rstrip('/')):
# Reset alternates when the cache dir is updated.
with open(
os.path.join(self.checkout_path, '.git', 'objects', 'info',
'alternates'), 'w') as fh:
fh.write(os.path.join(url, 'objects'))
else:
# Because we use Git alternatives, our existing repository is not
# self-contained. It's possible that new git alternative doesn't have
# all necessary objects that the current repository needs. Instead of
# blindly hoping that new alternative contains all necessary objects,
# keep the old alternative and just append a new one on top of it.
with open(
os.path.join(self.checkout_path, '.git', 'objects', 'info',
'alternates'), 'a') as fh:
fh.write("\n" + os.path.join(url, 'objects'))
self._EnsureValidHeadObjectOrCheckout(revision, options, url)
self._FetchAndReset(revision, file_list, options)

Loading…
Cancel
Save