diff options
author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2023-10-12 23:06:24 -0400 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2023-11-02 09:38:54 -0600 |
commit | a13af89e10391189b87ad32616ba688d6d7c5878 (patch) | |
tree | b67ecf74165f225cd80d5cae5a0da9f2f4c586d4 /tools/patman/patchstream.py | |
parent | 07fe79c93c5caba181f37844ca95fbda4db3f613 (diff) |
patman: Add a 'keep_change_id' setting
A Change-Id can be useful for traceability purposes, and some projects
may wish to have them preserved. This change makes it configurable
via a new 'keep_change_id' setting.
Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/patchstream.py')
-rw-r--r-- | tools/patman/patchstream.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py index f91669a940..e2e2a83e67 100644 --- a/tools/patman/patchstream.py +++ b/tools/patman/patchstream.py @@ -68,6 +68,7 @@ STATE_PATCH_SUBJECT = 1 # In patch subject (first line of log for a commit) STATE_PATCH_HEADER = 2 # In patch header (after the subject) STATE_DIFFS = 3 # In the diff part (past --- line) + class PatchStream: """Class for detecting/injecting tags in a patch or series of patches @@ -76,7 +77,7 @@ class PatchStream: unwanted tags or inject additional ones. These correspond to the two phases of processing. """ - def __init__(self, series, is_log=False): + def __init__(self, series, is_log=False, keep_change_id=False): self.skip_blank = False # True to skip a single blank line self.found_test = False # Found a TEST= line self.lines_after_test = 0 # Number of lines found after TEST= @@ -86,6 +87,7 @@ class PatchStream: self.section = [] # The current section...END section self.series = series # Info about the patch series self.is_log = is_log # True if indent like git log + self.keep_change_id = keep_change_id # True to keep Change-Id tags self.in_change = None # Name of the change list we are in self.change_version = 0 # Non-zero if we are in a change list self.change_lines = [] # Lines of the current change @@ -452,6 +454,8 @@ class PatchStream: # Detect Change-Id tags elif change_id_match: + if self.keep_change_id: + out = [line] value = change_id_match.group(1) if self.is_log: if self.commit.change_id: @@ -763,7 +767,7 @@ def get_metadata_for_test(text): pst.finalise() return series -def fix_patch(backup_dir, fname, series, cmt): +def fix_patch(backup_dir, fname, series, cmt, keep_change_id=False): """Fix up a patch file, by adding/removing as required. We remove our tags from the patch file, insert changes lists, etc. @@ -776,6 +780,7 @@ def fix_patch(backup_dir, fname, series, cmt): fname (str): Filename to patch file to process series (Series): Series information about this patch set cmt (Commit): Commit object for this patch file + keep_change_id (bool): Keep the Change-Id tag. Return: list: A list of errors, each str, or [] if all ok. @@ -783,7 +788,7 @@ def fix_patch(backup_dir, fname, series, cmt): handle, tmpname = tempfile.mkstemp() outfd = os.fdopen(handle, 'w', encoding='utf-8') infd = open(fname, 'r', encoding='utf-8') - pst = PatchStream(series) + pst = PatchStream(series, keep_change_id=keep_change_id) pst.commit = cmt pst.process_stream(infd, outfd) infd.close() @@ -795,7 +800,7 @@ def fix_patch(backup_dir, fname, series, cmt): shutil.move(tmpname, fname) return cmt.warn -def fix_patches(series, fnames): +def fix_patches(series, fnames, keep_change_id=False): """Fix up a list of patches identified by filenames The patch files are processed in place, and overwritten. @@ -803,6 +808,7 @@ def fix_patches(series, fnames): Args: series (Series): The Series object fnames (:type: list of str): List of patch files to process + keep_change_id (bool): Keep the Change-Id tag. """ # Current workflow creates patches, so we shouldn't need a backup backup_dir = None #tempfile.mkdtemp('clean-patch') @@ -811,7 +817,8 @@ def fix_patches(series, fnames): cmt = series.commits[count] cmt.patch = fname cmt.count = count - result = fix_patch(backup_dir, fname, series, cmt) + result = fix_patch(backup_dir, fname, series, cmt, + keep_change_id=keep_change_id) if result: print('%d warning%s for %s:' % (len(result), 's' if len(result) > 1 else '', fname)) |