Skip to content

Commit 09af58f

Browse files
committed
Use regex to find cherry-pick message
1 parent 3273edb commit 09af58f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tools/importer/importer.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import subprocess
2323
import logging
2424
import argparse
25+
import re
2526
from os.path import dirname, abspath, join, isfile, normpath
2627

2728
# Be sure that the tools directory is in the search path
@@ -30,6 +31,9 @@
3031

3132
from tools.utils import delete_dir_files, mkdir, copy_file
3233

34+
cherry_pick_re = re.compile(
35+
'\s*\(cherry picked from commit (([0-9]|[a-f]|[A-F])+)\)')
36+
3337

3438
def del_file(name):
3539
""" Delete the file in RTOS/CMSIS/features directory of mbed-os
@@ -150,11 +154,14 @@ def get_last_cherry_pick_sha(branch):
150154
sha = None
151155
get_commit = ['git', 'log', '-n', '1']
152156
_, output = run_cmd_with_output(get_commit, exit_on_failure=True)
153-
lines = output.split('\n')
157+
158+
lines = output.splitlines()
159+
lines.reverse()
154160
for line in lines:
155-
if 'cherry picked from' in line:
156-
sha = line.split(' ')[-1][:-1]
157-
return sha
161+
match = cherry_pick_re.match(line)
162+
if match:
163+
return match.group(1)
164+
return None
158165

159166

160167
def normalize_commit_sha(sha_lst):

0 commit comments

Comments
 (0)