Commit 1dbd65b1 authored by Edward Lesmes's avatar Edward Lesmes Committed by LUCI CQ

bot_update: Fetch required commit/refs directly.

Change-Id: Ie6bee1743859df364025350fc1a607f331346bd7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2825426Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 784f5c89
...@@ -637,7 +637,8 @@ def _has_in_git_cache(revision_sha1, refs, git_cache_dir, url): ...@@ -637,7 +637,8 @@ def _has_in_git_cache(revision_sha1, refs, git_cache_dir, url):
try: try:
mirror_dir = git( mirror_dir = git(
'cache', 'exists', '--quiet', '--cache-dir', git_cache_dir, url).strip() 'cache', 'exists', '--quiet', '--cache-dir', git_cache_dir, url).strip()
git('cat-file', '-e', revision_sha1, cwd=mirror_dir) if revision_sha1:
git('cat-file', '-e', revision_sha1, cwd=mirror_dir)
for ref in refs: for ref in refs:
git('cat-file', '-e', ref, cwd=mirror_dir) git('cat-file', '-e', ref, cwd=mirror_dir)
return True return True
...@@ -728,44 +729,32 @@ def _git_checkout(sln, sln_dir, revisions, refs, no_fetch_tags, git_cache_dir, ...@@ -728,44 +729,32 @@ def _git_checkout(sln, sln_dir, revisions, refs, no_fetch_tags, git_cache_dir,
branch, revision = get_target_branch_and_revision(name, url, revisions) branch, revision = get_target_branch_and_revision(name, url, revisions)
pin = revision if COMMIT_HASH_RE.match(revision) else None pin = revision if COMMIT_HASH_RE.match(revision) else None
if enforce_fetch:
git(*populate_cmd, env=env)
# Step 1: populate/refresh cache, if necessary. # Step 1: populate/refresh cache, if necessary.
if not pin: if (enforce_fetch
# Refresh only once. or not pin
or not _has_in_git_cache(pin, refs, git_cache_dir, url)):
git(*populate_cmd, env=env) git(*populate_cmd, env=env)
elif _has_in_git_cache(pin, refs, git_cache_dir, url):
# No need to fetch at all, because we already have needed revision. # If cache still doesn't have required pin/refs, try again and fetch pin/refs
pass # directly.
else: for attempt in range(3):
# We may need to retry a bit due to eventual consinstency in replication of if _has_in_git_cache(pin, refs, git_cache_dir, url):
# git servers. break
soft_deadline = time.time() + 60 try:
attempt = 0 mirror_dir = git(
while True: 'cache', 'exists', '--quiet', '--cache-dir', git_cache_dir, url).strip()
attempt += 1
# TODO(tandrii): propagate the pin to git server per recommendation of
# maintainers of *.googlesource.com (workaround git server replication
# lag).
with git_config_if_not_set( with git_config_if_not_set(
'http.extraheader', 'X-Return-Encrypted-Headers: all'): 'http.extraheader', 'X-Return-Encrypted-Headers: all'):
git(*populate_cmd, env=env) if pin:
if _has_in_git_cache(pin, refs, git_cache_dir, url): git('fetch', 'origin', pin, env=env, cwd=mirror_dir)
break for ref in refs:
overrun = time.time() - soft_deadline git('fetch', 'origin', '%s:%s' % (ref, ref),
# Only kick in deadline after second attempt to ensure we retry at least env=env, cwd=mirror_dir)
# once after initial fetch from not-yet-replicated server. break
if attempt >= 2 and overrun > 0: except SubprocessFailed as e:
print('Ran %s seconds past deadline. Aborting.' % (overrun,)) print('Failed to fetch required commits and refs: %s' % str(e))
# TODO(tandrii): raise exception immediately here, instead of doing print('Waiting 60s and trying again')
# useless step 2 trying to fetch something that we know doesn't exist time.sleep(60)
# in cache **after production data gives us confidence to do so**.
break
sleep_secs = min(60, 2**attempt)
print('waiting %s seconds and trying to fetch again...' % sleep_secs)
time.sleep(sleep_secs)
# Step 2: populate a checkout from local cache. All operations are local. # Step 2: populate a checkout from local cache. All operations are local.
mirror_dir = git( mirror_dir = git(
...@@ -791,6 +780,8 @@ def _git_checkout(sln, sln_dir, revisions, refs, no_fetch_tags, git_cache_dir, ...@@ -791,6 +780,8 @@ def _git_checkout(sln, sln_dir, revisions, refs, no_fetch_tags, git_cache_dir,
git('fetch', 'origin', cwd=sln_dir) git('fetch', 'origin', cwd=sln_dir)
git('remote', 'set-url', '--push', 'origin', url, cwd=sln_dir) git('remote', 'set-url', '--push', 'origin', url, cwd=sln_dir)
_set_remote_head(sln_dir) _set_remote_head(sln_dir)
if pin:
git('fetch', 'origin', pin, cwd=sln_dir)
for ref in refs: for ref in refs:
refspec = '%s:%s' % (ref, ref_to_remote_ref(ref.lstrip('+'))) refspec = '%s:%s' % (ref, ref_to_remote_ref(ref.lstrip('+')))
git('fetch', 'origin', refspec, cwd=sln_dir) git('fetch', 'origin', refspec, cwd=sln_dir)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment