From 80bf3c2b53d7514b888cec7ca6fdb2f4e579269d Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 2 Nov 2019 12:06:40 -0700 Subject: mailscripts.el: add notmuch-extract-message-patches{,-projectile} Signed-off-by: Sean Whitton --- debian/changelog | 1 + mailscripts.el | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/debian/changelog b/debian/changelog index 52c4282..06e92e6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,7 @@ mailscripts (0.12-1) UNRELEASED; urgency=medium Thanks to Daniel Kahn Gillmor for the patch series. * mailscripts.el: add mailscripts-extract-patches-branch-prefix defcustom. * mailscripts.el: add notmuch-extract-thread-patches-projectile command. + * mailscripts.el: add notmuch-extract-message-patches{,-projectile} commands. -- Sean Whitton Fri, 01 Nov 2019 20:38:07 -0700 diff --git a/mailscripts.el b/mailscripts.el index bcdc0ad..09d213d 100644 --- a/mailscripts.el +++ b/mailscripts.el @@ -77,6 +77,35 @@ threads to the notmuch-extract-patch(1) command." (interactive) (mailscripts--projectile-repo-and-branch 'notmuch-extract-thread-patches)) +;;;###autoload +(defun notmuch-extract-message-patches (repo branch) + "Extract patches attached to current message to branch BRANCH in repo REPO. + +The target branch may or may not already exist. + +Patches are applied using git-am(1), so we only consider +attachments with filenames which look like they were generated by +git-format-patch(1)." + (interactive "Dgit repo: \nsnew branch name: ") + (with-current-notmuch-show-message + (let ((default-directory (expand-file-name repo)) + (mm-handle (mm-dissect-buffer))) + (mailscripts--check-out-branch branch) + (notmuch-foreach-mime-part + (lambda (p) + (let* ((disposition (mm-handle-disposition p)) + (filename (cdr (assq 'filename disposition)))) + (and filename + (string-match "^[0-9]+-.+\.\\(patch\\|diff\\|txt\\)$" filename) + (mm-pipe-part p "git am")))) + mm-handle)))) + +;;;###autoload +(defun notmuch-extract-message-patches-projectile () + "Like `notmuch-extract-message-patches', but use projectile to choose the repo." + (interactive) + (mailscripts--projectile-repo-and-branch 'notmuch-extract-message-patches)) + (defun mailscripts--check-out-branch (branch) (call-process-shell-command (format "git checkout -b %s" -- cgit v1.2.3