aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Scherer2020-02-21 21:28:11 +0100
committerEli Zaretskii2020-02-22 10:52:07 +0200
commit0273f261a71089e5fea3cbfc45a654e508e49497 (patch)
tree7763174437c53370e2da85a2ecf4cf8f61737468
parentd7c22338d2d461e0b55a6628fed1917c08715292 (diff)
downloademacs-0273f261a71089e5fea3cbfc45a654e508e49497.tar.gz
emacs-0273f261a71089e5fea3cbfc45a654e508e49497.zip
Don't write absolute filenames and duplicate strings to CVS ignore files
* lisp/vc/vc-cvs.el (vc-cvs-ignore): Expand filename correctly and pass on only the basename as the pattern. (vc-cvs-append-to-ignore) Do not write duplicate strings to .cvsignore. New optional parameter SORT to more explicitly control sorting of the ignore entries. (Bug#37215) * lisp/vc/pcvs.el (cvs-mode-ignore): Call 'vc-cvs-append-to-ignore' with SORT argument.
-rw-r--r--lisp/vc/pcvs.el4
-rw-r--r--lisp/vc/vc-cvs.el45
2 files changed, 34 insertions, 15 deletions
diff --git a/lisp/vc/pcvs.el b/lisp/vc/pcvs.el
index dcba504401c..cb0494ee91c 100644
--- a/lisp/vc/pcvs.el
+++ b/lisp/vc/pcvs.el
@@ -106,7 +106,6 @@
106;; right now, it's killed without further ado. 106;; right now, it's killed without further ado.
107;; - make `cvs-mode-ignore' allow manually entering a pattern. 107;; - make `cvs-mode-ignore' allow manually entering a pattern.
108;; to which dir should it apply ? 108;; to which dir should it apply ?
109;; - cvs-mode-ignore should try to remove duplicate entries.
110;; - maybe poll/check CVS/Entries files to react to external `cvs' commands ? 109;; - maybe poll/check CVS/Entries files to react to external `cvs' commands ?
111;; - some kind of `cvs annotate' support ? 110;; - some kind of `cvs annotate' support ?
112;; but vc-annotate can be used instead. 111;; but vc-annotate can be used instead.
@@ -1972,7 +1971,8 @@ This command ignores files that are not flagged as `Unknown'."
1972 (interactive) 1971 (interactive)
1973 (dolist (fi (cvs-mode-marked 'ignore)) 1972 (dolist (fi (cvs-mode-marked 'ignore))
1974 (vc-cvs-append-to-ignore (cvs-fileinfo->dir fi) (cvs-fileinfo->file fi) 1973 (vc-cvs-append-to-ignore (cvs-fileinfo->dir fi) (cvs-fileinfo->file fi)
1975 (eq (cvs-fileinfo->subtype fi) 'NEW-DIR)) 1974 (eq (cvs-fileinfo->subtype fi) 'NEW-DIR)
1975 cvs-sort-ignore-file)
1976 (setf (cvs-fileinfo->type fi) 'DEAD)) 1976 (setf (cvs-fileinfo->type fi) 'DEAD))
1977 (cvs-cleanup-collection cvs-cookies nil nil nil)) 1977 (cvs-cleanup-collection cvs-cookies nil nil nil))
1978 1978
diff --git a/lisp/vc/vc-cvs.el b/lisp/vc/vc-cvs.el
index 16566a8902c..b6afda69198 100644
--- a/lisp/vc/vc-cvs.el
+++ b/lisp/vc/vc-cvs.el
@@ -1220,14 +1220,33 @@ is non-nil."
1220 "Return the administrative directory of FILE." 1220 "Return the administrative directory of FILE."
1221 (vc-find-root file "CVS")) 1221 (vc-find-root file "CVS"))
1222 1222
1223(defun vc-cvs-ignore (file &optional _directory _remove) 1223(defun vc-cvs-ignore (file &optional directory _remove)
1224 "Ignore FILE under CVS." 1224 "Ignore FILE under CVS.
1225 (vc-cvs-append-to-ignore (file-name-directory file) file)) 1225FILE is either absolute or relative to DIRECTORY. The basename
1226 1226of FILE is written unmodified into the ignore file and is
1227(defun vc-cvs-append-to-ignore (dir str &optional old-dir) 1227therefore evaluated by CVS as an ignore pattern which follows
1228glob(7) syntax. If the pattern should match any of the special
1229characters ‘?*[\\\’ literally, they must be escaped with a
1230backslash.
1231
1232CVS processes one ignore file for each subdirectory. Patterns
1233are separated by whitespace and only match files in the same
1234directory. Since FILE can be a relative filename with leading
1235diretories, FILE is expanded against DIRECTORY to determine the
1236correct absolute filename. The directory name of this path is
1237then used to determine the location of the ignore file. The base
1238name of this path is used as pattern for the ignore file.
1239
1240Since patterns are whitespace sparated, it is usually better to
1241replace spaces in filenames with question marks ‘?’."
1242 (setq file (directory-file-name (expand-file-name file directory)))
1243 (vc-cvs-append-to-ignore (file-name-directory file) (file-name-nondirectory file)))
1244
1245(defun vc-cvs-append-to-ignore (dir str &optional old-dir sort)
1228 "In DIR, add STR to the .cvsignore file. 1246 "In DIR, add STR to the .cvsignore file.
1229If OLD-DIR is non-nil, then this is a directory that we don't want 1247If OLD-DIR is non-nil, then this is a directory that we don't want
1230to hear about anymore." 1248to hear about anymore. If SORT is non-nil, sort the lines of the
1249ignore file."
1231 (with-current-buffer 1250 (with-current-buffer
1232 (find-file-noselect (expand-file-name ".cvsignore" dir)) 1251 (find-file-noselect (expand-file-name ".cvsignore" dir))
1233 (when (ignore-errors 1252 (when (ignore-errors
@@ -1236,13 +1255,13 @@ to hear about anymore."
1236 (not (vc-editable-p buffer-file-name)))) 1255 (not (vc-editable-p buffer-file-name))))
1237 ;; CVSREAD=on special case 1256 ;; CVSREAD=on special case
1238 (vc-checkout buffer-file-name t)) 1257 (vc-checkout buffer-file-name t))
1239 (goto-char (point-max)) 1258 (goto-char (point-min))
1240 (unless (bolp) (insert "\n")) 1259 (save-match-data
1241 (insert str (if old-dir "/\n" "\n")) 1260 (unless (re-search-forward (concat "^" (regexp-quote str) "$") nil 'move)
1242 ;; FIXME this is a pcvs variable. 1261 (unless (bolp) (insert "\n"))
1243 (if (bound-and-true-p cvs-sort-ignore-file) 1262 (insert str (if old-dir "/\n" "\n"))
1244 (sort-lines nil (point-min) (point-max))) 1263 (if sort (sort-lines nil (point-min) (point-max)))
1245 (save-buffer))) 1264 (save-buffer)))))
1246 1265
1247(provide 'vc-cvs) 1266(provide 'vc-cvs)
1248 1267