summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-15 12:26:13 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-15 12:26:13 -0400
commitbed5ae143681fdd2de3b502615320636e2db2199 (patch)
tree2279e9bfe15886c113ba69b78cba45c8e7dc9326
parent33a119739233a7d4f234cc7f38f3ec5f21058e4f (diff)
downloadb4-bed5ae143681fdd2de3b502615320636e2db2199.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.py4
-rw-r--r--b4/mbox.py28
2 files changed, 30 insertions, 2 deletions
diff --git a/b4/command.py b/b4/command.py
index 6d516a3..7709649 100644
--- a/b4/command.py
+++ b/b4/command.py
@@ -98,7 +98,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
diff --git a/b4/mbox.py b/b4/mbox.py
index 91085e3..5b08d1a 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -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)