summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-12-22 12:10:13 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-12-22 12:10:13 -0700
commitbffc5311bee634ed10c955bc184ef1c373b94028 (patch)
treeb52bfc9da08d104e838241da096b8ca5dcd22ed1
parent3c4ce0a29fa125093c427a9144f038ba6d1ee686 (diff)
downloadmailscripts-bffc5311bee634ed10c955bc184ef1c373b94028.tar.gz
mailscripts.el: add mailscripts-git-format-patch-append
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--debian/changelog2
-rw-r--r--mailscripts.el48
2 files changed, 49 insertions, 1 deletions
diff --git a/debian/changelog b/debian/changelog
index d0f983b..fc4a04a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,7 +1,7 @@
mailscripts (28-1) UNRELEASED; urgency=medium
* mailscripts.el:
- - new commands: mailscripts-git-format-patch-{attach,drafts}
+ - new commands: mailscripts-git-format-patch-{attach,drafts,append}
- new DWIM wrapper command: mailscripts-prepare-patch
- notmuch-extract-{thread,message}-patches: add Gnus support
diff --git a/mailscripts.el b/mailscripts.el
index 6f49bd8..d152e92 100644
--- a/mailscripts.el
+++ b/mailscripts.el
@@ -384,6 +384,54 @@ See also the interactive wrapper command `mailscripts-prepare-patch'."
(delete-directory temp t)))
(notmuch-search (format "folder:%s" notmuch-draft-folder)))
+(defun mailscripts-git-format-patch-append (args)
+ "Append a patch generated by git-format-patch(1) to an unsent message.
+ARGS is a single string of arguments to git-format-patch(1).
+The patch is formatted such that a recipient can use the --scissors option to
+git-am(1) to apply the patch; see \"DISCUSSION\" in git-format-patch(1)."
+ (interactive (list (read-string "git format-patch " "-1 ")))
+ (let ((dir default-directory))
+ (compose-mail nil nil nil t)
+ (save-excursion
+ (save-restriction
+ (message-narrow-to-headers-or-head)
+ (let ((unsent-buffer (current-buffer))
+ (default-directory dir)
+ (args (split-string-and-unquote args))
+ (unsent-from (message-fetch-field "from")))
+ (widen)
+ (if (re-search-forward message-signature-separator nil t)
+ (progn (goto-char (pos-bol))
+ (push "--no-signature" args))
+ (goto-char (point-max)))
+ (if (fboundp 'ensure-empty-lines)
+ (ensure-empty-lines 1)
+ ;; This is only some of what (ensure-empty-lines 1) does.
+ (if (bolp)
+ (unless (save-excursion (goto-char (pos-bol 0)) (eolp))
+ (newline))
+ (newline 2)))
+ (insert "-- >8 --\n")
+ (with-temp-buffer
+ (apply #'call-process "git" nil t nil "format-patch" "--stdout"
+ args)
+ (when (bobp)
+ (user-error "git-format-patch(1) produced no output"))
+ (goto-char (point-min))
+ (delete-line) ; drop "From $SHA1 $magic_timestamp"
+ (message-narrow-to-headers-or-head)
+ (when-let* ((unsent
+ (and unsent-from
+ (mail-header-parse-address-lax unsent-from)))
+ (patch-from (message-fetch-field "from"))
+ (patch (mail-header-parse-address-lax patch-from)))
+ (when (equal unsent patch)
+ (message-remove-header "^From:\\|^Date:" t)))
+ (widen)
+ (goto-char (point-max))
+ (delete-blank-lines)
+ (append-to-buffer unsent-buffer 1 (point-max))))))))
+
(defun mailscripts--gfp-addressee ()
"Try to find a recipient for the --to argument to git-format-patch(1)."
(or (and (local-variable-p 'vc-default-patch-addressee)