From 2d915236dcb2147e95d068eba702f4d07efe9caf Mon Sep 17 00:00:00 2001 From: Alexander Adolf Date: Thu, 28 May 2026 15:04:46 +0200 Subject: [PATCH] vc--subject-to-file-name: Fix over-greedy regex (bug#81017) * lisp/vc/vc.el (vc--subject-to-file-name): Make the prefix regex less greedy, ensure the result has no text properties, improve the docstring (bug#81017). --- lisp/vc/vc.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 8f0e9e5bdc4..256a04812f6 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -5393,15 +5393,19 @@ of the current file." (vc-working-revision file))))) (defun vc--subject-to-file-name (subject) - "Generate a file name for a patch with subject line SUBJECT." + "Generate a file name for a patch with subject line SUBJECT. + +The resulting filename is similar to the names generated by \"git +format-patch\", but without the leading patch sequence number \"0001-\". +Any leading \"[PATCH 1/1]\" style strings, and any text properties are +removed from SUBJECT prior to conversion." (let* ((stripped - (replace-regexp-in-string "\\`\\[.*PATCH.*\\]\\s-*" "" + (replace-regexp-in-string "\\`\\[[^][]*PATCH[^][]*]\\s-*" "" subject)) - (truncated (if (length> stripped 50) - (substring stripped 0 50) - stripped))) + (truncated (substring-no-properties stripped + 0 (min (length stripped) 50)))) (concat - (string-trim (replace-regexp-in-string "\\W" "-" truncated) + (string-trim (replace-regexp-in-string "\\W+" "-" truncated) "-+" "-+") ".patch")))