mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-04 20:19:47 +08:00
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 <zhiyuzhang999@gmail.com> Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/r/20250713163418.1459-1-zhiyuzhang999@gmail.com
This commit is contained in:
parent
2b16b71a05
commit
35293ebbb6
@ -24,6 +24,7 @@ commit 42fb9cfd5b18 ("Documentation: dev-tools: Add link to RV docs")
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
from argparse import ArgumentParser, ArgumentTypeError, BooleanOptionalAction
|
from argparse import ArgumentParser, ArgumentTypeError, BooleanOptionalAction
|
||||||
@ -69,6 +70,38 @@ def get_origin_from_trans(origin_path, t_from_head):
|
|||||||
return o_from_t
|
return o_from_t
|
||||||
|
|
||||||
|
|
||||||
|
def get_origin_from_trans_smartly(origin_path, t_from_head):
|
||||||
|
"""Get the latest origin commit from the formatted translation commit:
|
||||||
|
(1) update to commit HASH (TITLE)
|
||||||
|
(2) Update the translation through commit HASH (TITLE)
|
||||||
|
"""
|
||||||
|
# catch flag for 12-bit commit hash
|
||||||
|
HASH = r'([0-9a-f]{12})'
|
||||||
|
# pattern 1: contains "update to commit HASH"
|
||||||
|
pat_update_to = re.compile(rf'update to commit {HASH}')
|
||||||
|
# pattern 2: contains "Update the translation through commit HASH"
|
||||||
|
pat_update_translation = re.compile(rf'Update the translation through commit {HASH}')
|
||||||
|
|
||||||
|
origin_commit_hash = None
|
||||||
|
for line in t_from_head["message"]:
|
||||||
|
# check if the line matches the first pattern
|
||||||
|
match = pat_update_to.search(line)
|
||||||
|
if match:
|
||||||
|
origin_commit_hash = match.group(1)
|
||||||
|
break
|
||||||
|
# check if the line matches the second pattern
|
||||||
|
match = pat_update_translation.search(line)
|
||||||
|
if match:
|
||||||
|
origin_commit_hash = match.group(1)
|
||||||
|
break
|
||||||
|
if origin_commit_hash is None:
|
||||||
|
return None
|
||||||
|
o_from_t = get_latest_commit_from(origin_path, origin_commit_hash)
|
||||||
|
if o_from_t is not None:
|
||||||
|
logging.debug("tracked origin commit id: %s", o_from_t["hash"])
|
||||||
|
return o_from_t
|
||||||
|
|
||||||
|
|
||||||
def get_commits_count_between(opath, commit1, commit2):
|
def get_commits_count_between(opath, commit1, commit2):
|
||||||
"""Get the commits count between two commits for the specified file"""
|
"""Get the commits count between two commits for the specified file"""
|
||||||
command = f"git log --pretty=format:%H {commit1}...{commit2} -- {opath}"
|
command = f"git log --pretty=format:%H {commit1}...{commit2} -- {opath}"
|
||||||
@ -108,6 +141,9 @@ def check_per_file(file_path):
|
|||||||
logging.error("Cannot find the latest commit for %s", file_path)
|
logging.error("Cannot find the latest commit for %s", file_path)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
o_from_t = get_origin_from_trans_smartly(opath, t_from_head)
|
||||||
|
# notice, o_from_t from get_*_smartly() is always more accurate than from get_*()
|
||||||
|
if o_from_t is None:
|
||||||
o_from_t = get_origin_from_trans(opath, t_from_head)
|
o_from_t = get_origin_from_trans(opath, t_from_head)
|
||||||
|
|
||||||
if o_from_t is None:
|
if o_from_t is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user