diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-05-15 12:26:13 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-05-15 12:31:49 -0400 |
commit | a2febf32bba504ee670934297ce919b225a878d0 (patch) | |
tree | a156c2b16a56c4f1b118bf5eab944a4134308633 | |
parent | dcae0e5120a6045d5ce866afe628b4bf14930757 (diff) | |
download | b4-a2febf32bba504ee670934297ce919b225a878d0.tar.gz |
Expand use of --cherry-pick ("this", globbing)
In addition to numerical ranges, -P is now also able to do:
- "-P _" to grab just the msgid used with "b4 am"
- "-P *glob*" to filter by commit message subject
Suggested-by: Rob Herring <robh@kernel.org>
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/command.py | 4 | ||||
-rw-r--r-- | b4/mbox.py | 28 |
2 files changed, 30 insertions, 2 deletions
diff --git a/b4/command.py b/b4/command.py index 097de5f..84fb724 100644 --- a/b4/command.py +++ b/b4/command.py @@ -96,7 +96,9 @@ def cmd(): sp_am.add_argument('-Q', '--quilt-ready', dest='quiltready', action='store_true', default=False, help='Save mbox patches in a quilt-ready folder') sp_am.add_argument('-P', '--cherry-pick', dest='cherrypick', default=None, - help='Cherry-pick a subset of patches (e.g. -P 1-2,4,6-)') + help='Cherry-pick a subset of patches (e.g. "-P 1-2,4,6-", ' + '"-P _" to use just the msgid specified, or ' + '"-P *globbing*" to match on commit subject)') sp_am.set_defaults(func=cmd_am) # b4 attest @@ -14,6 +14,7 @@ import email.utils import re import time import json +import fnmatch import urllib.parse import xml.etree.ElementTree @@ -67,7 +68,32 @@ def mbox_to_am(mboxfile, cmdargs): logger.info('---') if cmdargs.cherrypick: - cherrypick = list(b4.parse_int_range(cmdargs.cherrypick, upper=len(lser.patches)-1)) + cherrypick = list() + if cmdargs.cherrypick == '_': + msgid = b4.get_msgid(cmdargs) + # Only grab the exact msgid provided + at = 0 + for lmsg in lser.patches[1:]: + at += 1 + if lmsg.msgid == msgid: + cherrypick = [at] + cmdargs.cherrypick = '5' + break + if not len(cherrypick): + logger.critical('Specified msgid is not present in the series, cannot cherry-pick') + sys.exit(1) + elif cmdargs.cherrypick.find('*') >= 0: + # Globbing on subject + at = 0 + for lmsg in lser.patches[1:]: + at += 1 + if fnmatch.fnmatch(lmsg.subject, cmdargs.cherrypick): + cherrypick.append(at) + if not len(cherrypick): + logger.critical('Could not match "%s" to any subjects in the series', cmdargs.cherrypick) + sys.exit(1) + else: + cherrypick = list(b4.parse_int_range(cmdargs.cherrypick, upper=len(lser.patches)-1)) else: cherrypick = None logger.critical('Writing %s', am_filename) |