all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Wolfgang Scherer <Wolfgang.Scherer@gmx.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 37215@debbugs.gnu.org, larsi@gnus.org, dgutov@yandex.ru
Subject: bug#37215: [PATCH] vc-cvs-ignore writes absolute filenames and duplicate strings
Date: Fri, 21 Feb 2020 21:32:03 +0100	[thread overview]
Message-ID: <686a6419-308c-6536-3996-7f534ca19346@gmx.de> (raw)
In-Reply-To: <83eeuojnhk.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1716 bytes --]


Am 21.02.20 um 10:31 schrieb Eli Zaretskii:
>> Cc: larsi@gnus.org, 37215@debbugs.gnu.org, dgutov@yandex.ru
>> From: Wolfgang Scherer <Wolfgang.Scherer@gmx.de>
>> Date: Thu, 20 Feb 2020 00:06:11 +0100
>> (lisp/vc/pcvs.el) Call ‘vc-cvs-append-to-ignore’ with SORT argument.
> 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.\x15\x04
>> +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 ...

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Do-not-write-absolute-filenames-and-duplicate-string.patch --]
[-- Type: text/x-patch; name="0001-Do-not-write-absolute-filenames-and-duplicate-string.patch", Size: 4541 bytes --]

From edea70777b81f745b86f812c7ca2e0021a9ecb83 Mon Sep 17 00:00:00 2001
From: Wolfgang Scherer <wolfgang.scherer@gmx.de>
Date: Fri, 21 Feb 2020 21:28:11 +0100
Subject: [PATCH] Do not write absolute filenames and duplicate strings into
 CVS ignore files

* lisp/vc/vc-cvs.el: (vc-cvs-ignore) Expand filename correctly
and pass on basename as pattern only.
(vc-cvs-append-to-ignore) Do not write duplicate strings to
.cvsignore.  Addtional optional parameter SORT.
(lisp/vc/pcvs.el) Call 'vc-cvs-append-to-ignore' with SORT argument.
---
 lisp/vc/pcvs.el   |  4 ++--
 lisp/vc/vc-cvs.el | 45 ++++++++++++++++++++++++++++++++-------------
 2 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/lisp/vc/pcvs.el b/lisp/vc/pcvs.el
index dcba504..cb0494e 100644
--- a/lisp/vc/pcvs.el
+++ b/lisp/vc/pcvs.el
@@ -106,7 +106,6 @@
 ;; 	right now, it's killed without further ado.
 ;; - make `cvs-mode-ignore' allow manually entering a pattern.
 ;; 	to which dir should it apply ?
-;; - cvs-mode-ignore should try to remove duplicate entries.
 ;; - maybe poll/check CVS/Entries files to react to external `cvs' commands ?
 ;; - some kind of `cvs annotate' support ?
 ;; 	but vc-annotate can be used instead.
@@ -1972,7 +1971,8 @@ This command ignores files that are not flagged as `Unknown'."
   (interactive)
   (dolist (fi (cvs-mode-marked 'ignore))
     (vc-cvs-append-to-ignore (cvs-fileinfo->dir fi) (cvs-fileinfo->file fi)
-			  (eq (cvs-fileinfo->subtype fi) 'NEW-DIR))
+			  (eq (cvs-fileinfo->subtype fi) 'NEW-DIR)
+                          cvs-sort-ignore-file)
     (setf (cvs-fileinfo->type fi) 'DEAD))
   (cvs-cleanup-collection cvs-cookies nil nil nil))

diff --git a/lisp/vc/vc-cvs.el b/lisp/vc/vc-cvs.el
index 16566a8..b6afda6 100644
--- a/lisp/vc/vc-cvs.el
+++ b/lisp/vc/vc-cvs.el
@@ -1220,14 +1220,33 @@ 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-append-to-ignore (dir str &optional old-dir)
+(defun vc-cvs-ignore (file &optional directory _remove)
+  "Ignore FILE under CVS.
+FILE is either absolute or relative to DIRECTORY.  The basename
+of FILE is written unmodified into the ignore file and is
+therefore evaluated by CVS as an ignore pattern which follows
+glob(7) syntax.  If the pattern should match any of the special
+characters ‘?*[\\\’ literally, they must be escaped with a
+backslash.
+
+CVS processes one ignore file for each subdirectory.  Patterns
+are separated by whitespace and only match files in the same
+directory.  Since FILE can be a relative filename with leading
+diretories, FILE is expanded against DIRECTORY to determine the
+correct absolute filename.  The directory name of this path is
+then used to determine the location of the ignore file.  The base
+name of this path is used as pattern for the ignore file.
+
+Since patterns are whitespace sparated, it is usually better to
+replace spaces in filenames with question marks ‘?’."
+  (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 sort)
   "In DIR, add STR to the .cvsignore file.
 If OLD-DIR is non-nil, then this is a directory that we don't want
-to hear about anymore."
+to hear about anymore.  If SORT is non-nil, sort the lines of the
+ignore file."
   (with-current-buffer
       (find-file-noselect (expand-file-name ".cvsignore" dir))
     (when (ignore-errors
@@ -1236,13 +1255,13 @@ 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 'move)
+        (unless (bolp) (insert "\n"))
+        (insert str (if old-dir "/\n" "\n"))
+        (if sort (sort-lines nil (point-min) (point-max)))
+        (save-buffer)))))

 (provide 'vc-cvs)

--
2.7.4


  parent reply	other threads:[~2020-02-21 20:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-28 22:32 bug#37215: [PATCH] vc-cvs-ignore writes absolute filenames and duplicate strings Wolfgang Scherer
2019-09-15 13:12 ` Lars Ingebrigtsen
2020-01-05  3:59   ` Wolfgang Scherer
2020-01-22 12:43     ` Lars Ingebrigtsen
2020-01-30 19:44       ` Wolfgang Scherer
2020-02-13 19:36         ` Eli Zaretskii
2020-02-14  1:24           ` Wolfgang Scherer
2020-02-14  8:33             ` Eli Zaretskii
2020-02-15  1:42               ` Wolfgang Scherer
2020-02-15  7:44                 ` Eli Zaretskii
2020-02-15 12:55                   ` Dmitry Gutov
2020-02-19 23:02                     ` Wolfgang Scherer
2020-02-16  0:20                   ` Wolfgang Scherer
2020-02-19 23:06                   ` Wolfgang Scherer
2020-02-21  9:31                     ` Eli Zaretskii
2020-02-21 10:16                       ` Dmitry Gutov
2020-02-21 20:44                         ` Wolfgang Scherer
2020-02-21 21:30                           ` Dmitry Gutov
2020-02-21 22:23                             ` Wolfgang Scherer
2020-02-21 20:32                       ` Wolfgang Scherer [this message]
2020-02-22  8:59                         ` Eli Zaretskii
2020-02-14  2:50           ` Wolfgang Scherer
2020-02-14  8:39             ` Eli Zaretskii
2020-02-14  9:24               ` Eli Zaretskii
2020-02-28 16:07 ` Mattias Engdegård
2020-02-28 16:24   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=686a6419-308c-6536-3996-7f534ca19346@gmx.de \
    --to=wolfgang.scherer@gmx.de \
    --cc=37215@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.