From a2febf32bba504ee670934297ce919b225a878d0 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Fri, 15 May 2020 12:26:13 -0400 Subject: 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 Signed-off-by: Konstantin Ryabitsev --- b4/command.py | 4 +++- 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 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) -- cgit v1.2.3