All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Blain <levraiphilippeblain@gmail.com>
To: "Kernel.org Tools" <tools@linux.kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
	 Philippe Blain <levraiphilippeblain@gmail.com>
Subject: [PATCH b4 2/2] am, shazam: allow cherry-picking an out-of-series patch
Date: Sat, 15 Apr 2023 15:31:00 -0400	[thread overview]
Message-ID: <20230415-am-cherry-pick-suggestion-v1-2-8951a2274256@gmail.com> (raw)
In-Reply-To: <20230415-am-cherry-pick-suggestion-v1-0-8951a2274256@gmail.com>

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>
---
 b4/mbox.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/b4/mbox.py b/b4/mbox.py
index 05c40e9..70b866f 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -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:]:

-- 
2.39.1


  parent reply	other threads:[~2023-04-15 19:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-15 19:30 [PATCH b4 0/2] am, shazam: allow cherry-picking an out-of-series patch Philippe Blain
2023-04-15 19:30 ` [PATCH b4 1/2] mbox.py::make_am: simplify check for early return Philippe Blain
2023-04-15 19:31 ` Philippe Blain [this message]
2023-05-06 20:23 ` [PATCH b4 0/2] am, shazam: allow cherry-picking an out-of-series patch Philippe Blain
2023-05-26 18:28 ` Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230415-am-cherry-pick-suggestion-v1-2-8951a2274256@gmail.com \
    --to=levraiphilippeblain@gmail.com \
    --cc=konstantin@linuxfoundation.org \
    --cc=tools@linux.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.