Commit f78690b6 authored by Andrii Shyshkalov's avatar Andrii Shyshkalov Committed by Commit Bot

bot_update: refactor hiding ugly revision details into lower layers.

Bug:
Change-Id: Ie1caef2d58dce12bafbbec29fa4a5cc65076626c
Reviewed-on: https://chromium-review.googlesource.com/771856
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
Reviewed-by: 's avatarJao-ke Chin-Lee <jchinlee@chromium.org>
parent f062cf21
...@@ -508,22 +508,25 @@ def get_total_disk_space(): ...@@ -508,22 +508,25 @@ def get_total_disk_space():
return (total, free) return (total, free)
def get_target_revision(solution_name, git_url, revisions): def _get_target_branch_and_revision(solution_name, git_url, revisions):
normalized_name = solution_name.strip('/') normalized_name = solution_name.strip('/')
if normalized_name in revisions: if normalized_name in revisions:
return revisions[normalized_name] configured = revisions[normalized_name]
if git_url in revisions: elif git_url in revisions:
return revisions[git_url] configured = revisions[git_url]
return None else:
return 'master', 'HEAD'
def force_revision(cwd, revision): parts = configured.split(':', 1)
split_revision = revision.split(':', 1) if len(parts) == 2:
branch = 'master'
if len(split_revision) == 2:
# Support for "branch:revision" syntax. # Support for "branch:revision" syntax.
branch, revision = split_revision return parts
return 'master', configured
def force_solution_revision(solution_name, git_url, revisions, cwd):
branch, revision = _get_target_branch_and_revision(
solution_name, git_url, revisions)
if revision and revision.upper() != 'HEAD': if revision and revision.upper() != 'HEAD':
git('checkout', '--force', revision, cwd=cwd) git('checkout', '--force', revision, cwd=cwd)
else: else:
...@@ -644,11 +647,7 @@ def _git_checkout(sln, build_dir, revisions, shallow, refs, git_cache_dir, ...@@ -644,11 +647,7 @@ def _git_checkout(sln, build_dir, revisions, shallow, refs, git_cache_dir,
except Exception: except Exception:
tries -= 1 tries -= 1
# TODO(tandrii): refactor to avoid exposing revision which isn't really force_solution_revision(name, url, revisions, sln_dir)
# sha1 and not even 'HEAD' but can also be 'branch:HEAD' and even
# 'branch:sha1'.
revision = get_target_revision(name, url, revisions) or 'HEAD'
force_revision(sln_dir, revision)
done = True done = True
except SubprocessFailed as e: except SubprocessFailed as e:
# Exited abnormally, theres probably something wrong. # Exited abnormally, theres probably something wrong.
......
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