diff options
| author | Wolfgang Scherer | 2020-02-21 21:28:11 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2020-02-22 10:52:07 +0200 |
| commit | 0273f261a71089e5fea3cbfc45a654e508e49497 (patch) | |
| tree | 7763174437c53370e2da85a2ecf4cf8f61737468 | |
| parent | d7c22338d2d461e0b55a6628fed1917c08715292 (diff) | |
| download | emacs-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.el | 4 | ||||
| -rw-r--r-- | 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 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)) | 1225 | FILE is either absolute or relative to DIRECTORY. The basename |
| 1226 | 1226 | of FILE is written unmodified into the ignore file and is | |
| 1227 | (defun vc-cvs-append-to-ignore (dir str &optional old-dir) | 1227 | therefore evaluated by CVS as an ignore pattern which follows |
| 1228 | glob(7) syntax. If the pattern should match any of the special | ||
| 1229 | characters ‘?*[\\\’ literally, they must be escaped with a | ||
| 1230 | backslash. | ||
| 1231 | |||
| 1232 | CVS processes one ignore file for each subdirectory. Patterns | ||
| 1233 | are separated by whitespace and only match files in the same | ||
| 1234 | directory. Since FILE can be a relative filename with leading | ||
| 1235 | diretories, FILE is expanded against DIRECTORY to determine the | ||
| 1236 | correct absolute filename. The directory name of this path is | ||
| 1237 | then used to determine the location of the ignore file. The base | ||
| 1238 | name of this path is used as pattern for the ignore file. | ||
| 1239 | |||
| 1240 | Since patterns are whitespace sparated, it is usually better to | ||
| 1241 | replace 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. |
| 1229 | If OLD-DIR is non-nil, then this is a directory that we don't want | 1247 | If OLD-DIR is non-nil, then this is a directory that we don't want |
| 1230 | to hear about anymore." | 1248 | to hear about anymore. If SORT is non-nil, sort the lines of the |
| 1249 | ignore 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 | ||