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).
This commit is contained in:
Alexander Adolf 2026-05-28 15:04:46 +02:00 committed by Sean Whitton
parent 05f89d711d
commit 2d915236dc

View file

@ -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")))