From aaca72806ecd60f28384fe839cdfe6a28a2b5d1f Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 16 Dec 2022 22:34:52 -0700 Subject: vc-prepare-patch: Number the attached patches * lisp/gnus/mml.el (mml-attach-buffer): New FILENAME argument. * lisp/vc/vc.el (vc--subject-to-file-name): New function. (vc-prepare-patch): When vc-prepare-patches-separately is nil, generate file names for the attached patches. Call vc--subject-to-file-name, and then prepend numbers indicating the ordering of the patches (bug#60147). --- lisp/vc/vc.el | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'lisp/vc/vc.el') diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 690c907c77e..b40bb31b603 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -3369,7 +3369,7 @@ If nil, no default will be used. This option may be set locally." (declare-function message--name-table "message" (orig-string)) (declare-function mml-attach-buffer "mml" - (buffer &optional type description disposition)) + (buffer &optional type description disposition filename)) (declare-function log-view-get-marked "log-view" ()) (defun vc-default-prepare-patch (_backend rev) @@ -3410,6 +3410,19 @@ of the current file." (and-let* ((file (buffer-file-name))) (vc-working-revision file))))) +(defun vc--subject-to-file-name (subject) + "Generate a file name for a patch with subject line SUBJECT." + (let* ((stripped + (replace-regexp-in-string "\\`\\[.*PATCH.*\\]\\s-*" "" + subject)) + (truncated (if (length> stripped 50) + (substring stripped 0 50) + stripped))) + (concat + (string-trim (replace-regexp-in-string "\\W" "-" truncated) + "-+" "-+") + ".patch"))) + ;;;###autoload (defun vc-prepare-patch (addressee subject revisions) "Compose an Email sending patches for REVISIONS to ADDRESSEE. @@ -3466,11 +3479,17 @@ marked revisions, use those these." (rfc822-goto-eoh) (forward-line) (save-excursion - (dolist (patch patches) - (mml-attach-buffer (buffer-name (plist-get patch :buffer)) - "text/x-patch" - (plist-get patch :subject) - "attachment"))) + (let ((i 0)) + (dolist (patch patches) + (let* ((patch-subject (plist-get patch :subject)) + (filename + (vc--subject-to-file-name patch-subject))) + (mml-attach-buffer + (buffer-name (plist-get patch :buffer)) + "text/x-patch" + patch-subject + "attachment" + (format "%04d-%s" (cl-incf i) filename)))))) (open-line 2))))) (defun vc-default-responsible-p (_backend _file) -- cgit v1.2.1 From 8739cba1ee0336cef444ec07f170879e67f68202 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 19 Dec 2022 15:15:48 -0700 Subject: ; * lisp/vc/vc.el (vc-prepare-patch): Fix typo. --- lisp/vc/vc.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/vc/vc.el') diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index b40bb31b603..130214b840a 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -3433,7 +3433,7 @@ revision, with SUBJECT derived from each revision subject. When invoked with a numerical prefix argument, use the last N revisions. When invoked interactively in a Log View buffer with -marked revisions, use those these." +marked revisions, use those." (interactive (let ((revs (vc-prepare-patch-prompt-revisions)) to) (require 'message) -- cgit v1.2.1