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>
1 file changed