build: export matching patches (#41174)

* build: make patches/config.json an array of objects

This file was previously an object of patch_dir keys to repo values;
Now is an array of objects containing `patch_dir` and `repo` properties.
This makes other per-target properties (e.g. `grep`) possible.

* build: include Note metadata when exporting patches

* build: support keyword filtering in export_patches()

* build: add optional `--grep` arg to git-export-patches script

* build: update export_all_patches to understand new config file

* fixup! build: update export_all_patches to understand new config file

chore: make lint happy

* fixup! build: make patches/config.json an array of objects

chore: fix oops

* refactor: remove support for the old file format

There is more code using config.json than I thought, so the
effort-to-reward of supporting the old format is not worth it.

* build: update apply_all_patches to understand new config file

* build: update lint.js to understand new config file

* build: update patches-mtime-cache.py to understand new config file

* fixup! build: update apply_all_patches to understand new config file

fix: oops

* fixup! build: update apply_all_patches to understand new config file

fix minor syntax wart

* fixup! build: support keyword filtering in export_patches()

refactor: use idiomatic python

* refactor: warn if config.json has an invalid repo
This commit is contained in:
Charles Kerr 2024-02-08 12:47:59 -06:00 committed by GitHub
parent 4d060afc98
commit b253d52faf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 75 additions and 48 deletions

View file

@ -149,6 +149,7 @@ def format_patch(repo, since):
'format-patch',
'--keep-subject',
'--no-stat',
'--notes',
'--stdout',
# Per RFC 3676 the signature is separated from the body by a line with
@ -181,6 +182,16 @@ def split_patches(patch_data):
patches[-1].append(line)
return patches
def filter_patches(patches, key):
"""Return patches that include the specified key"""
if key is None:
return patches
matches = []
for patch in patches:
if any(key in line for line in patch):
matches.append(patch)
continue
return matches
def munge_subject_to_filename(subject):
"""Derive a suitable filename from a commit's subject"""
@ -227,7 +238,7 @@ def remove_patch_filename(patch):
force_keep_next_line = l.startswith('Subject: ')
def export_patches(repo, out_dir, patch_range=None, dry_run=False):
def export_patches(repo, out_dir, patch_range=None, dry_run=False, grep=None):
if not os.path.exists(repo):
sys.stderr.write(
"Skipping patches in {} because it does not exist.\n".format(repo)
@ -239,6 +250,8 @@ def export_patches(repo, out_dir, patch_range=None, dry_run=False):
num_patches, repo, patch_range[0:7]))
patch_data = format_patch(repo, patch_range)
patches = split_patches(patch_data)
if grep:
patches = filter_patches(patches, grep)
try:
os.mkdir(out_dir)