Subject: bug#55039: [PATCH] Use VC-relative file names in ChangeLog entries

From: Philip Kaludercic <[email-masked]>
Date: Tue, 06 Sep 2022 20:10:41 +0000

Here is an updated patch:

>From f8e4b14198e8a9ccd5e4cbdbe044eb468697c2b8 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <[email-masked]>
Date: Tue, 6 Sep 2022 22:06:29 +0200
Subject: [PATCH] Add new user option 'diff-add-log-relative-names'

* .dir-locals.el: Set 'diff-add-log-relative-names' to t
* doc/emacs/maintaining.texi (Log Buffer): Mention
'diff-add-log-relative-names'
* etc/NEWS: Mention 'diff-add-log-relative-names'
* lisp/vc/diff-mode.el (diff-add-log-relative-names): Add new option.
(diff-add-log-current-defuns): Use new option.
---
 .dir-locals.el             |  3 ++-
 doc/emacs/maintaining.texi |  5 ++++-
 etc/NEWS                   |  5 +++++
 lisp/vc/diff-mode.el       | 17 +++++++++++++++--
 4 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/.dir-locals.el b/.dir-locals.el
index 7812beb001..3312021920 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -5,7 +5,8 @@
          (sentence-end-double-space . t)
          (fill-column . 70)
 	 (emacs-lisp-docstring-fill-column . 65)
-         (bug-reference-url-format . "https://debbugs.gnu.org/%s")))
+         (bug-reference-url-format . "https://debbugs.gnu.org/%s")
+	 (diff-add-log-relative-names . t)))
  (c-mode . ((c-file-style . "GNU")
             (c-noise-macro-names . ("INLINE" "ATTRIBUTE_NO_SANITIZE_UNDEFINED" "UNINIT" "CALLBACK" "ALIGN_STACK"))
             (electric-quote-comment . nil)
diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index 60169d8d8c..0f1dc18f1a 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -694,7 +694,10 @@ Log Buffer
 (@code{log-edit-generate-changelog-from-diff}), to generate skeleton
 ChangeLog entries, listing all changed file and function names based
 on the diff of the VC fileset.  Consecutive entries left empty will be
-combined by @kbd{C-q} (@code{fill-paragraph}).
+combined by @kbd{C-q} (@code{fill-paragraph}).  By default the
+inserted file names will just be the files without a path.  If
+@code{diff-add-log-relative-names} is non-nil, a partial path relative
+to the VC root directory will be inserted instead.
 
 @kindex C-c C-a @r{(Log Edit mode)}
 @findex log-edit-insert-changelog
diff --git a/etc/NEWS b/etc/NEWS
index 1317cd0128..0547796b6c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1288,6 +1288,11 @@ Sets the value of the buffer-local variable 'whitespace-style' in
 'diff-mode' buffers.  By default, this variable is '(face trailing)',
 which preserves behavior from previous Emacs versions.
 
++++
+*** New user option 'diff-relative-names-in-changelog'.
+If non-nil insert file names in ChangeLog skeletons relative to the
+VC root directory.
+
 ** Ispell
 
 ---
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 6b30de3cb3..7cafb43334 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -2336,10 +2336,18 @@ diff-undo
   (let ((inhibit-read-only t))
     (undo arg)))
 
+(defcustom diff-add-log-relative-names nil
+  "Use relative file names when generating ChangeLog messages."
+  :type 'boolean
+  :safe #'booleanp
+  :version "29.1")
+
 (defun diff-add-log-current-defuns ()
   "Return an alist of defun names for the current diff.
 The elements of the alist are of the form (FILE . (DEFUN...)),
-where DEFUN... is a list of function names found in FILE."
+where DEFUN... is a list of function names found in FILE.  If
+`diff-add-log-relative-names' is non-nil, insert file names
+relative to the VC root directory."
   (save-excursion
     (goto-char (point-min))
     (let* ((defuns nil)
@@ -2373,7 +2381,12 @@ diff-add-log-current-defuns
           ;; hunks (e.g., "diff --git ..." etc).
           (re-search-forward diff-hunk-header-re nil t)
         (setq hunk-end (save-excursion (diff-end-of-hunk)))
-        (pcase-let* ((filename (substring-no-properties (diff-find-file-name)))
+        (pcase-let* ((filename (substring-no-properties
+                                (if diff-add-log-relative-names
+                                    (file-relative-name
+                                     (diff-find-file-name)
+                                     (vc-root-dir))
+                                  (diff-find-file-name))))
                      (=lines 0)
                      (+lines 0)
                      (-lines 0)
-- 
2.30.2