mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
Keep old git alternatives when changing mirrors
It's possible to change DEPS git repository while keeping the same source. This is useful feature, for example if upstream repository moves from github to gitlab. The repositories can be out of sync, or even diverge. We use git alternatives to save disk space. If a builder flip-flops between mirror repositories (e.g. case with different release branches), it's possible that new mirror doesn't contain all necessary objects that are present in the old repositories. That will result in invalid git pointer entries and fetch operations will fail. Instead of replacing git alternatives, we append new git alternatives to avoid such problem. R=bpastene@google.com, jojwang@google.com Bug: b/241802975 Change-Id: I3ef025603af58a84692a68bf3b780c47b6d3ae46 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3843133 Reviewed-by: Ben Pastene <bpastene@chromium.org> Reviewed-by: Joanna Wang <jojwang@chromium.org> Commit-Queue: Josip Sokcevic <sokcevic@google.com>
This commit is contained in:
@@ -697,10 +697,15 @@ 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'),
|
||||
'w') as fh:
|
||||
fh.write(os.path.join(url, 'objects'))
|
||||
'a') as fh:
|
||||
fh.write("\n" + os.path.join(url, 'objects'))
|
||||
self._EnsureValidHeadObjectOrCheckout(revision, options, url)
|
||||
self._FetchAndReset(revision, file_list, options)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user