Move more logic to vc-ignore from vc-default-ignore

* lisp/vc/vc-dir.el (vc-dir-ignore):
Pass relative file names to vc-ignore.

* lisp/vc/vc.el (vc-ignore): Move the responsibility of
constructing the ignore pattern (right now, most often a relative
file name) using a file name received from the user, here.
(vc-default-ignore): ...from here (bug#37189, see discussion).
Also clarify the docstring.
This commit is contained in:
Dmitry Gutov 2020-02-23 01:51:38 +02:00
parent 2aed279be1
commit dd5756436c
2 changed files with 33 additions and 28 deletions

View file

@ -879,7 +879,9 @@ If a prefix argument is given, ignore all marked files."
(vc-ignore (vc-dir-fileinfo->name filearg)) (vc-ignore (vc-dir-fileinfo->name filearg))
t)) t))
vc-ewoc) vc-ewoc)
(vc-ignore (vc-dir-current-file)))) (vc-ignore
(file-relative-name (vc-dir-current-file))
default-directory)))
(defun vc-dir-current-file () (defun vc-dir-current-file ()
(let ((node (ewoc-locate vc-ewoc))) (let ((node (ewoc-locate vc-ewoc)))

View file

@ -480,8 +480,8 @@
;; ;;
;; - ignore (file &optional directory) ;; - ignore (file &optional directory)
;; ;;
;; Ignore FILE under the VCS of DIRECTORY (default is `default-directory'). ;; Ignore FILE under DIRECTORY (default is 'default-directory').
;; FILE is a file wildcard. ;; FILE is a file wildcard relative to DIRECTORY.
;; When called interactively and with a prefix argument, remove FILE ;; When called interactively and with a prefix argument, remove FILE
;; from ignored files. ;; from ignored files.
;; When called from Lisp code, if DIRECTORY is non-nil, the ;; When called from Lisp code, if DIRECTORY is non-nil, the
@ -1406,40 +1406,43 @@ When called interactively, prompt for a FILE to ignore, unless a
prefix argument is given, in which case prompt for a file FILE to prefix argument is given, in which case prompt for a file FILE to
remove from the list of ignored files." remove from the list of ignored files."
(interactive (interactive
(list (let* ((backend (vc-responsible-backend default-directory))
(if (not current-prefix-arg) (rel-dir
(read-file-name "File to ignore: ") (condition-case nil
(completing-read (file-name-directory
"File to remove: " (vc-call-backend backend 'find-ignore-file
(vc-call-backend default-directory))
(or (vc-responsible-backend default-directory) (vc-not-supported
(error "Unknown backend")) default-directory)))
'ignore-completion-table default-directory))) (file (read-file-name "File to ignore: ")))
nil current-prefix-arg)) (when (and (file-name-absolute-p file)
(file-in-directory-p file rel-dir))
(setq file (file-relative-name file rel-dir)))
(list file
rel-dir
current-prefix-arg)))
(let* ((directory (or directory default-directory)) (let* ((directory (or directory default-directory))
(backend (or (vc-responsible-backend default-directory) (backend (or (vc-responsible-backend default-directory)
(error "Unknown backend")))) (error "Unknown backend"))))
(vc-call-backend backend 'ignore file directory remove))) (vc-call-backend backend 'ignore file directory remove)))
(defun vc-default-ignore (backend file &optional directory remove) (defun vc-default-ignore (backend file &optional directory remove)
"Ignore FILE under the VCS of DIRECTORY (default is `default-directory'). "Ignore FILE under DIRECTORY (default is `default-directory').
FILE is a wildcard specification, either relative to FILE is a wildcard specification relative to DIRECTORY.
DIRECTORY or absolute.
When called from Lisp code, if DIRECTORY is non-nil, the When called from Lisp code, if DIRECTORY is non-nil, the
repository to use will be deduced by DIRECTORY; if REMOVE is repository to use will be deduced by DIRECTORY.
non-nil, remove FILE from ignored files.
Argument BACKEND is the backend you are using." If REMOVE is non-nil, remove FILE from ignored files instead.
Argument BACKEND is the backend to use."
(let ((ignore (let ((ignore
(vc-call-backend backend 'find-ignore-file (or directory default-directory))) (vc-call-backend backend
file-path root-dir pattern) 'find-ignore-file
(setq file-path (expand-file-name file directory)) (or directory default-directory))))
(setq root-dir (file-name-directory ignore))
(when (not (string= (substring file-path 0 (length root-dir)) root-dir))
(error "Ignore spec %s is not below project root %s" file-path root-dir))
(setq pattern (substring file-path (length root-dir)))
(if remove (if remove
(vc--remove-regexp (concat "^" (regexp-quote pattern ) "\\(\n\\|$\\)") ignore) (vc--remove-regexp (concat "^" (regexp-quote file) "\\(\n\\|$\\)") ignore)
(vc--add-line pattern ignore)))) (vc--add-line file ignore))))
(defun vc-default-ignore-completion-table (backend file) (defun vc-default-ignore-completion-table (backend file)
"Return the list of ignored files under BACKEND." "Return the list of ignored files under BACKEND."