Refactor continuation logic

pull/10505/head
Oren Cohen 2019-04-28 20:03:08 +03:00
parent d26bca7be8
commit e15068d728
1 changed files with 21 additions and 20 deletions

View File

@ -153,8 +153,7 @@ def get_last_cherry_pick_sha(branch):
lines = output.split('\n') lines = output.split('\n')
for line in lines: for line in lines:
if 'cherry picked from' in line: if 'cherry picked from' in line:
sha = line.split(' ')[-1] sha = line.split(' ')[-1][:-1]
return sha[:-1]
return sha return sha
@ -272,21 +271,23 @@ if __name__ == "__main__":
branch_checkout(branch) branch_checkout(branch)
commit_sha = json_data["commit_sha"] commit_sha = json_data["commit_sha"]
last_sha = get_last_cherry_pick_sha(branch) last_sha = get_last_cherry_pick_sha(branch)
if not last_sha:
## Apply commits specific to mbed-os changes # Few commits are already applied, check the next in sequence
for sha in commit_sha: # and skip to next commit
cherry_pick_sha = ['git', 'cherry-pick', '-x', sha] if last_sha:
run_cmd_with_output(cherry_pick_sha, exit_on_failure=True) assert last_sha in commit_sha, "%s not found in config file" % last_sha
rel_log.info("Cherry-picked commit = %s", sha) # Calculate the index of the next sha to be applied
## Few commits are already applied, check the next in sequence next_sha_idx = commit_sha.index(last_sha) + 1
## and skip to last applied if next_sha_idx >= len(commit_sha):
else: rel_log.info("No more commits to apply")
found = False sys.exit(0)
for sha in commit_sha: # Skipping applied commits
if sha == last_sha: commit_sha = commit_sha[next_sha_idx:]
found = True
continue # Apply commits specific to mbed-os changes
if found is True: for sha in commit_sha:
cherry_pick_sha = ['git', 'cherry-pick', '-x', sha] cherry_pick_sha = ['git', 'cherry-pick', '-x', sha]
run_cmd_with_output(cherry_pick_sha, exit_on_failure=True) rel_log.info("Cherry-picking commit = %s", sha)
rel_log.info("Cherry-picked commit = %s", sha) run_cmd_with_output(cherry_pick_sha, exit_on_failure=True)
rel_log.info("Finished import successfully :)")