From 3a07935e20c0ae3ff6cce31579b596abfcab21c8 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Thu, 20 May 2021 18:02:29 -0400 Subject: Reimplement single-msgid cherrypicking When processing -P_, filter by that msgid (and its follow-ups) early on, instead of parsing the entire thread and only then looking for matches. Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 15 +++++++++++++-- b4/mbox.py | 17 ++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/b4/__init__.py b/b4/__init__.py index 0053b9c..fc79e7f 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -2108,7 +2108,7 @@ def get_pi_thread_by_url(t_mbx_url, nocache=False): return msgs -def get_pi_thread_by_msgid(msgid, useproject=None, nocache=False): +def get_pi_thread_by_msgid(msgid, useproject=None, nocache=False, onlymsgids: Optional[set] = None): qmsgid = urllib.parse.quote_plus(msgid) config = get_main_config() # Grab the head from lore, to see where we are redirected @@ -2134,7 +2134,18 @@ def get_pi_thread_by_msgid(msgid, useproject=None, nocache=False): if not msgs: return None - strict = get_strict_thread(msgs, msgid) + if onlymsgids: + strict = list() + for msg in msgs: + if LoreMessage.get_clean_msgid(msg) in onlymsgids: + strict.append(msg) + # also grab any messages where this msgid is in the references header + for onlymsgid in onlymsgids: + if msg.get('references', '').find(onlymsgid) >= 0: + strict.append(msg) + else: + strict = get_strict_thread(msgs, msgid) + return strict diff --git a/b4/mbox.py b/b4/mbox.py index fab9569..9b94af8 100644 --- a/b4/mbox.py +++ b/b4/mbox.py @@ -47,16 +47,6 @@ def make_am(msgs, cmdargs, msgid): reroll = True if cmdargs.nopartialreroll: reroll = False - if cmdargs.cherrypick == '_' and not wantver and len(lmbx.series) > 1: - # Make sure we pick the revision containing the msgid - wantver = None - for cnum, clser in lmbx.series.items(): - for lmsg in clser.patches: - if lmsg and lmsg.msgid == msgid: - wantver = cnum - break - if wantver: - break lser = lmbx.get_series(revision=wantver, sloppytrailers=cmdargs.sloppytrailers, reroll=reroll) if lser is None and wantver is None: @@ -540,7 +530,12 @@ def main(cmdargs): logger.error('Error: pipe a message or pass msgid as parameter') sys.exit(1) - msgs = b4.get_pi_thread_by_msgid(msgid, useproject=cmdargs.useproject, nocache=cmdargs.nocache) + pickings = set() + if cmdargs.cherrypick == '_': + # Just that msgid, please + pickings = {msgid} + msgs = b4.get_pi_thread_by_msgid(msgid, useproject=cmdargs.useproject, nocache=cmdargs.nocache, + onlymsgids=pickings) if not msgs: return else: -- cgit v1.2.3