discussion and development of piem
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: Leo <git@relevant-information.com>
Cc: piem@inbox.kyleam.com
Subject: [PATCH] *-am-ready-mbox: Don't require PATCH prefix
Date: Sun, 04 Feb 2024 14:54:47 -0500	[thread overview]
Message-ID: <87ttmo57js.fsf@kyleam.com> (raw)
In-Reply-To: <87fry9hn9u.fsf@>

Leo writes:

> This is really just for future reference, in case someone else stumbles
> upon this.  I've resolved it for myself and am just documenting what the
> issue was.

Thanks.

> I found that for a specific email with a patch piem would just refuse to
> apply it with the message "Could not find am-ready mbox for current
> buffer", even if just piping the email through `git am` would work.
> Turns out the issue was with piem-patch-subject-re.  The patch was sent
> with a different subject prefix (the --subject-prefix option in
> git-send-email) than the default, which didn't match
> piem-patch-subject-re.

It looks like piem-patch-subject-re is used in piem--shorten-subject and
*-am-ready-mbox functions:

  $ grep -p piem-patch-subject-re
  piem-gnus.el=(defun piem-gnus-am-ready-mbox ()
  piem-gnus.el:                                  piem-patch-subject-re
  piem-notmuch.el=(defun piem-notmuch-am-ready-mbox ()
  piem-notmuch.el:          (when (string-match-p piem-patch-subject-re
  piem-notmuch.el=(defun piem-notmuch-extract-patch-am-ready-mbox ()
  piem-notmuch.el:             (string-match-p piem-patch-subject-re
  piem.el=(defun piem-extract-mbox-info (&optional buffer)
  piem.el:(defvar piem-patch-subject-re
  piem.el=(defun piem--shorten-subject (subject)
  piem.el:                     piem-patch-subject-re ""))

Perhaps it was a mistake to add the piem-patch-subject-re guard to the
*-am-ready-mbox functions.  If we know we're in the right buffer type
and the caller is asking to extract the am-ready-mbox from the current
buffer, is there any value being strict about the subject?  I'm thinking
of dropping the guards like so...

-- >8 --
Subject: [PATCH] *-am-ready-mbox: Don't require PATCH prefix

All of the *-am-ready-mbox functions expect inline patches to have a
'[... PATCH ...]' in the subject.  In cases where a patch is sent
without that prefix, a piem-am caller gets an unhelpful "Could not
find am-ready mbox for current buffer" in response to
piem-am-ready-mbox returning nil.

To support these (hopefully rare) cases, drop the "has patch prefix?"
guard from all the *-am-ready-mbox functions.  A caller is requesting
to extract a patch from the current buffer, and the "is the current
buffer in the right mode?" check should be sufficient for an
am-ready-mbox function to decide whether it should be responsible for
generating the mbox.

This change makes it more likely that a piem-am caller invokes 'git
am' on something that's not a valid patch, but in that case 1) the
output buffer gives a reasonable error and 2) no other function in
piem-am-ready-mbox-functions could be expected to successfully apply
it, so there's no harm in claiming it.
---
 piem-gnus.el    |  8 ++------
 piem-notmuch.el | 12 ++++--------
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/piem-gnus.el b/piem-gnus.el
index 7120512..b6dc672 100644
--- a/piem-gnus.el
+++ b/piem-gnus.el
@@ -130,12 +130,8 @@ (defun piem-gnus-am-ready-mbox ()
       (when-let ((patch (with-current-buffer gnus-article-buffer
                           (save-restriction
                             (widen)
-                            (and (string-match-p
-                                  piem-patch-subject-re
-                                  (mail-decode-encoded-word-string
-                                   (message-field-value "subject")))
-                                 (buffer-substring-no-properties
-                                  (point-min) (point-max)))))))
+                            (buffer-substring-no-properties
+                             (point-min) (point-max))))))
         (cons (lambda () (insert patch))
               "mbox"))))))
 
diff --git a/piem-notmuch.el b/piem-notmuch.el
index 493b724..9077ec8 100644
--- a/piem-notmuch.el
+++ b/piem-notmuch.el
@@ -100,12 +100,10 @@ (defun piem-notmuch-am-ready-mbox ()
            (n-attachments (notmuch-count-attachments handle))
            patches)
       (if (= n-attachments 0)
-          (when (string-match-p piem-patch-subject-re
-                                (notmuch-show-get-subject))
-            (let ((id (notmuch-show-get-message-id)))
-              (lambda ()
-                (call-process notmuch-command nil t nil
-                              "show" "--format=mbox" id))))
+          (let ((id (notmuch-show-get-message-id)))
+            (lambda ()
+              (call-process notmuch-command nil t nil
+                            "show" "--format=mbox" id)))
         (notmuch-foreach-mime-part
          (lambda (p)
            (when-let ((patch (piem-am-extract-attached-patch p)))
@@ -125,8 +123,6 @@ (defun piem-notmuch-extract-patch-am-ready-mbox ()
 notmuch-extract-patch to get the latest patch series from the
 notmuch thread."
   (when (and (derived-mode-p 'notmuch-show-mode)
-             (string-match-p piem-patch-subject-re
-                             (notmuch-show-get-subject))
              (= (notmuch-count-attachments
                  (piem-notmuch--with-current-message
                    (mm-dissect-buffer)))

base-commit: 4256eb8b62f81f1f755184bbe245b3155f723a5a
-- 
2.41.0


  reply	other threads:[~2024-02-04 19:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-03 10:09 Could not find am-ready mbox for current buffer Leo
2024-02-04 19:54 ` Kyle Meyer [this message]
2024-02-04 20:12   ` [PATCH] *-am-ready-mbox: Don't require PATCH prefix Kyle Meyer
     [not found]   ` <87sf272ojs.fsf@>
2024-02-06  4:08     ` Kyle Meyer
2024-02-12  3:44       ` Kyle Meyer

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

  List information: https://git.kyleam.com/

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

  git send-email \
    --in-reply-to=87ttmo57js.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=git@relevant-information.com \
    --cc=piem@inbox.kyleam.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.kyleam.com/piem/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).