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():
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('/')
if normalized_name in revisions:
return revisions[normalized_name]
if git_url in revisions:
return revisions[git_url]
return None
configured = revisions[normalized_name]
elif git_url in revisions:
configured = revisions[git_url]
else:
return 'master', 'HEAD'
def force_revision(cwd, revision):
split_revision = revision.split(':', 1)
branch = 'master'
if len(split_revision) == 2:
parts = configured.split(':', 1)
if len(parts) == 2:
# 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':
git('checkout', '--force', revision, cwd=cwd)
else:
......@@ -644,11 +647,7 @@ def _git_checkout(sln, build_dir, revisions, shallow, refs, git_cache_dir,
except Exception:
tries -= 1
# TODO(tandrii): refactor to avoid exposing revision which isn't really
# 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)
force_solution_revision(name, url, revisions, sln_dir)
done = True
except SubprocessFailed as e:
# 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