summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 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
diff --git a/b4/mbox.py b/b4/mbox.py
index 1ffb563..99ad2ee 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)