Skip to content

Commit e15068d

Browse files
author
Oren Cohen
committed
Refactor continuation logic
1 parent d26bca7 commit e15068d

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

tools/importer/importer.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ def get_last_cherry_pick_sha(branch):
153153
lines = output.split('\n')
154154
for line in lines:
155155
if 'cherry picked from' in line:
156-
sha = line.split(' ')[-1]
157-
return sha[:-1]
156+
sha = line.split(' ')[-1][:-1]
158157
return sha
159158

160159

@@ -272,21 +271,23 @@ def get_last_cherry_pick_sha(branch):
272271
branch_checkout(branch)
273272
commit_sha = json_data["commit_sha"]
274273
last_sha = get_last_cherry_pick_sha(branch)
275-
if not last_sha:
276-
## Apply commits specific to mbed-os changes
277-
for sha in commit_sha:
278-
cherry_pick_sha = ['git', 'cherry-pick', '-x', sha]
279-
run_cmd_with_output(cherry_pick_sha, exit_on_failure=True)
280-
rel_log.info("Cherry-picked commit = %s", sha)
281-
## Few commits are already applied, check the next in sequence
282-
## and skip to last applied
283-
else:
284-
found = False
285-
for sha in commit_sha:
286-
if sha == last_sha:
287-
found = True
288-
continue
289-
if found is True:
290-
cherry_pick_sha = ['git', 'cherry-pick', '-x', sha]
291-
run_cmd_with_output(cherry_pick_sha, exit_on_failure=True)
292-
rel_log.info("Cherry-picked commit = %s", sha)
274+
275+
# Few commits are already applied, check the next in sequence
276+
# and skip to next commit
277+
if last_sha:
278+
assert last_sha in commit_sha, "%s not found in config file" % last_sha
279+
# Calculate the index of the next sha to be applied
280+
next_sha_idx = commit_sha.index(last_sha) + 1
281+
if next_sha_idx >= len(commit_sha):
282+
rel_log.info("No more commits to apply")
283+
sys.exit(0)
284+
# Skipping applied commits
285+
commit_sha = commit_sha[next_sha_idx:]
286+
287+
# Apply commits specific to mbed-os changes
288+
for sha in commit_sha:
289+
cherry_pick_sha = ['git', 'cherry-pick', '-x', sha]
290+
rel_log.info("Cherry-picking commit = %s", sha)
291+
run_cmd_with_output(cherry_pick_sha, exit_on_failure=True)
292+
293+
rel_log.info("Finished import successfully :)")

0 commit comments

Comments
 (0)