diff options
author | Philippe Blain <levraiphilippeblain@gmail.com> | 2023-04-15 15:31:00 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2023-05-26 14:26:37 -0400 |
commit | 5872a3cfbb27a8511ee8a07f2b1a5bc79163dcd6 (patch) | |
tree | ccc66a483f779760f3c69d82dd7744c330a57480 | |
parent | 6c9ad4ec28f9a14cd8d20c933eef7bce0285a60a (diff) | |
download | b4-5872a3cfbb27a8511ee8a07f2b1a5bc79163dcd6.tar.gz |
am, shazam: allow cherry-picking an out-of-series patch
Reviewers sometimes include a patch as a reply when reviewing a
contributor's series, for example, to suggest tweaks or additional
changes. The contributor might want to add that patch to their series
for the next revision.
Currently, using 'b4 shazam -P_ $msgid', where msgid is the message-id
or full URL of the reviewer's message, does not work:
$ b4 am -o- -P_ ZDnCMegeiw0kT5oj@nand.local
Analyzing 2 messages in the thread
No patches found.
mbox.py::make_am returns early because the LoreSeries 'lser' returned by
lmbx.get_series is empty ('None'). It is empty because when using '-P_',
b4::retrieve_messages only retrieves the specific message-id given (and
its replies), so the LoreSeries 'lmbx' created in make_am does not have
any series.
Also check if the user asked to cherry-pick a specific message-id before
returning early in make_am. This allows us to reach the 'if
cmdargs.cherrypick == '_'' condition, but then we iterate on
lser.patches to find the patch to cherry-pick, and so get a runtime
error:
$ b4 am -o- -P_ ZDnCMegeiw0kT5oj@nand.local
Analyzing 2 messages in the thread
Traceback (most recent call last):
File "/Users/Philippe/Code/b4/b4/command.py", line 381, in <module>
cmd()
File "/Users/Philippe/Code/b4/b4/command.py", line 364, in cmd
cmdargs.func(cmdargs)
File "/Users/Philippe/Code/b4/b4/command.py", line 91, in cmd_am
b4.mbox.main(cmdargs)
File "/Users/Philippe/Code/b4/b4/mbox.py", line 719, in main
make_am(msgs, cmdargs, msgid)
File "/Users/Philippe/Code/b4/b4/mbox.py", line 82, in make_am
for lmsg in lser.patches[1:]:
AttributeError: 'NoneType' object has no attribute 'patches'
Fix this by creating a fake LoreSeries and adding to it any followup
messages in 'lmbx' with a diff in the body.
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Link: https://msgid.link/20230415-am-cherry-pick-suggestion-v1-2-8951a2274256@gmail.com
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/mbox.py | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -57,7 +57,7 @@ def make_am(msgs: List[email.message.Message], cmdargs: argparse.Namespace, msgi reroll = False lser = lmbx.get_series(revision=wantver, sloppytrailers=cmdargs.sloppytrailers, reroll=reroll) - if lser is None: + if lser is None and cmdargs.cherrypick != '_': if wantver is None: logger.critical('No patches found.') else: @@ -70,6 +70,13 @@ def make_am(msgs: List[email.message.Message], cmdargs: argparse.Namespace, msgi if cmdargs.cherrypick: cherrypick = list() if cmdargs.cherrypick == '_': + # We might want to pick a patch sent as a followup, so create a fake series + # and add followups with diffs + if lser is None: + lser = b4.LoreSeries(revision=1, expected=1) + for followup in lmbx.followups: + if followup.has_diff: + lser.add_patch(followup) # Only grab the exact msgid provided at = 0 for lmsg in lser.patches[1:]: |