Subject: bug#37215: closed (Re: bug#37215: [PATCH] vc-cvs-ignore writes absolute filenames and duplicate strings)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 22 Feb 2020 09:01:02 +0000

Your bug report

#37215: [PATCH] vc-cvs-ignore writes absolute filenames and duplicate strings

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
37215: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=37215
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#37215: [PATCH] vc-cvs-ignore writes absolute filenames and duplicate strings
From: Eli Zaretskii <[email-masked]>
To: Wolfgang Scherer <[email-masked]>
Cc: [email-masked], [email-masked], [email-masked]
Date: Sat, 22 Feb 2020 10:59:49 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> Cc: [email-masked], [email-masked], [email-masked]
> From: Wolfgang Scherer <[email-masked]>
> Date: Fri, 21 Feb 2020 21:32:03 +0100
> 
> > Please quote 'like this' in log messages, and try to avoid non-ASCII
> > characters there (they are generally only necessary in people's
> > names).
> OK
> >> +Patterns follow glob(7) syntax.  Special characters \"?*[\\\" are
> >> +escaped with a backslash."
> > I'd say "should be escaped" here, since this is a requirement for the
> > argument passed to this function.
> Here is that amgbuity again ;-). It is only required, if the user
> wants a special character to match literally. It's perfectly fine to
> specify  *.pyc  as a pattern. I have phrased it like that.
> > Also, I'd mention that FILE can be a pattern, otherwise the reference
> > to patterns might come as a surprise to the reader.
> I emphasized more, that the basename of the FILE argument (not the
> entire FILE) is in fact a CVS ignore pattern.
> >> +to hear about anymore.  If SORT is non-nil, sort the ines of the
> >> +ignore file."                                        ^^^^
> > Typo: should be "lines".
> Right.
> >> +    (goto-char (point-min))
> >> +    (save-match-data
> >> +      (unless (re-search-forward (concat "^" (regexp-quote str) "$") nil t)
> >> +        (goto-char (point-max))
> > You could use non-nil, non-t 3rd argument of re-search-forward, in
> > which case the following goto-char would be redundant, right?
> Right, I just left the  goto-char  in there, because it makes it
> obvious what is going on. Switching to the side-effect optimization ...

Thanks, pushed to the release branch.

Please note that I need to make minor copyedits in the log message;
please try following this style in the future.

With this, I'm closing this bug report.

Subject: [PATCH] vc-cvs-ignore writes absolute filenames and duplicate strings
From: Wolfgang Scherer <[email-masked]>
To: Emacs Bugs <[email-masked]>
Date: Thu, 29 Aug 2019 00:32:22 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

When called with an absolute filename (which is the default
case), `vc-cvs-ignore' writes the entire path into the .cvsignore
file.

`vc-cvs-ignore' also writes duplicate strings into .cvsignore.

The attached patch fixes these errors.

From 2b7b90b94a426754a99c965bf708bf5854008b76 Mon Sep 17 00:00:00 2001
From: Wolfgang Scherer <[email-masked]>
Date: Thu, 29 Aug 2019 00:29:31 +0200
Subject: [PATCH] Do not write absolute filenames and duplicate strings into
 .cvsignore

* lisp/vc/vc-cvs.el: (vc-cvs-ignore) Expand filename correctly
and pass on basename only.
(vc-cvs-append-to-ignore) Do not write duplicate strings to
.cvsignore.
---
 lisp/vc/vc-cvs.el | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/lisp/vc/vc-cvs.el b/lisp/vc/vc-cvs.el
index d84700f..1d0387b 100644
--- a/lisp/vc/vc-cvs.el
+++ b/lisp/vc/vc-cvs.el
@@ -1220,9 +1220,11 @@ is non-nil."
   "Return the administrative directory of FILE."
   (vc-find-root file "CVS"))

-(defun vc-cvs-ignore (file &optional _directory _remove)
-  "Ignore FILE under CVS."
-  (vc-cvs-append-to-ignore (file-name-directory file) file))
+(defun vc-cvs-ignore (file &optional directory _remove)
+  "Ignore FILE under CVS.
+FILE is either absolute or relative to DIRECTORY."
+  (setq file (directory-file-name (expand-file-name file directory)))
+  (vc-cvs-append-to-ignore (file-name-directory file) (file-name-nondirectory file)))

 (defun vc-cvs-append-to-ignore (dir str &optional old-dir)
   "In DIR, add STR to the .cvsignore file.
@@ -1236,13 +1238,16 @@ to hear about anymore."
 		 (not (vc-editable-p buffer-file-name))))
       ;; CVSREAD=on special case
       (vc-checkout buffer-file-name t))
-    (goto-char (point-max))
-    (unless (bolp) (insert "\n"))
-    (insert str (if old-dir "/\n" "\n"))
-    ;; FIXME this is a pcvs variable.
-    (if (bound-and-true-p cvs-sort-ignore-file)
-        (sort-lines nil (point-min) (point-max)))
-    (save-buffer)))
+    (goto-char (point-min))
+    (save-match-data
+      (unless (re-search-forward (concat "^" (regexp-quote str) "$") nil t)
+        (goto-char (point-max))
+        (unless (bolp) (insert "\n"))
+        (insert str (if old-dir "/\n" "\n"))
+        ;; FIXME this is a pcvs variable.
+        (if (bound-and-true-p cvs-sort-ignore-file)
+            (sort-lines nil (point-min) (point-max)))
+        (save-buffer)))))

 (provide 'vc-cvs)

--
2.7.4