Skip to content

Commit 35293eb

Browse files
QGrainJonathan Corbet
authored andcommitted
scripts: add origin commit identification based on specific patterns
This patch adds the functionability to smartly identify origin commit of the translation by matching the following patterns in commit log: 1) update to commit HASH 2) Update the translation through commit HASH If no such pattern is found, script will obey the original workflow. Signed-off-by: Zhiyu Zhang <[email protected]> Reviewed-by: Dongliang Mu <[email protected]> Signed-off-by: Jonathan Corbet <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2b16b71 commit 35293eb

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

scripts/checktransupdate.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"""
2525

2626
import os
27+
import re
2728
import time
2829
import logging
2930
from argparse import ArgumentParser, ArgumentTypeError, BooleanOptionalAction
@@ -69,6 +70,38 @@ def get_origin_from_trans(origin_path, t_from_head):
6970
return o_from_t
7071

7172

73+
def get_origin_from_trans_smartly(origin_path, t_from_head):
74+
"""Get the latest origin commit from the formatted translation commit:
75+
(1) update to commit HASH (TITLE)
76+
(2) Update the translation through commit HASH (TITLE)
77+
"""
78+
# catch flag for 12-bit commit hash
79+
HASH = r'([0-9a-f]{12})'
80+
# pattern 1: contains "update to commit HASH"
81+
pat_update_to = re.compile(rf'update to commit {HASH}')
82+
# pattern 2: contains "Update the translation through commit HASH"
83+
pat_update_translation = re.compile(rf'Update the translation through commit {HASH}')
84+
85+
origin_commit_hash = None
86+
for line in t_from_head["message"]:
87+
# check if the line matches the first pattern
88+
match = pat_update_to.search(line)
89+
if match:
90+
origin_commit_hash = match.group(1)
91+
break
92+
# check if the line matches the second pattern
93+
match = pat_update_translation.search(line)
94+
if match:
95+
origin_commit_hash = match.group(1)
96+
break
97+
if origin_commit_hash is None:
98+
return None
99+
o_from_t = get_latest_commit_from(origin_path, origin_commit_hash)
100+
if o_from_t is not None:
101+
logging.debug("tracked origin commit id: %s", o_from_t["hash"])
102+
return o_from_t
103+
104+
72105
def get_commits_count_between(opath, commit1, commit2):
73106
"""Get the commits count between two commits for the specified file"""
74107
command = f"git log --pretty=format:%H {commit1}...{commit2} -- {opath}"
@@ -108,7 +141,10 @@ def check_per_file(file_path):
108141
logging.error("Cannot find the latest commit for %s", file_path)
109142
return
110143

111-
o_from_t = get_origin_from_trans(opath, t_from_head)
144+
o_from_t = get_origin_from_trans_smartly(opath, t_from_head)
145+
# notice, o_from_t from get_*_smartly() is always more accurate than from get_*()
146+
if o_from_t is None:
147+
o_from_t = get_origin_from_trans(opath, t_from_head)
112148

113149
if o_from_t is None:
114150
logging.error("Error: Cannot find the latest origin commit for %s", file_path)

0 commit comments

Comments
 (0)