From 63191d9f2043d2e67657e85a7b3842805dd1dad6 Mon Sep 17 00:00:00 2001 From: Xue Fuqiao Date: Wed, 4 Sep 2013 08:31:13 +0800 Subject: [PATCH] Some fixes for vc-ignore. * lisp/vc/vc.el (vc-ignore): Rewrite. (vc-default-ignore): New function. (vc-default-ignore-completion-table): Use find-ignore-file. * lisp/vc/vc-bzr.el (vc-bzr-ignore, vc-bzr-ignore-completion-table): * lisp/vc/vc-git.el (vc-git-ignore, vc-git-ignore-completion-table): * lisp/vc/vc-hg.el (vc-hg-ignore, vc-hg-ignore-completion-table): Remove. Most code moved to vc.el. * doc/emacs/maintaining.texi (VC Ignore): Mention `vc-ignore' with prefix argument. --- doc/emacs/ChangeLog | 4 +++ doc/emacs/maintaining.texi | 14 ++++---- etc/NEWS | 5 +-- lisp/ChangeLog | 11 ++++++ lisp/vc/vc-bzr.el | 15 -------- lisp/vc/vc-git.el | 16 --------- lisp/vc/vc-hg.el | 16 --------- lisp/vc/vc-svn.el | 3 +- lisp/vc/vc.el | 73 ++++++++++++++++++++++---------------- 9 files changed, 70 insertions(+), 87 deletions(-) diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index ad411e44ba..73de1ce292 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog @@ -1,3 +1,7 @@ +2013-09-04 Xue Fuqiao + + * maintaining.texi (VC Ignore): Mention `vc-ignore' with prefix argument. + 2013-07-31 Eli Zaretskii * emacs.texi (Top): Remove menu item for the removed "Disabling diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index 553375442d..4a61db5509 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi @@ -1043,12 +1043,14 @@ Ignore a file under current version control system. (@code{vc-ignore}). @kindex C-x v G @findex vc-ignore - Many source trees contain some files that do not need to be versioned, -such as editor backups, object or bytecode files, and built programs. -You can simply not add them, but then they’ll always crop up as -unknown files. You can also tell the version control system to ignore -these files by adding them to the ignore file at the top of the tree. -@kbd{C-x v G} (@code{vc-ignore}) can help you do this. + Many source trees contain some files that do not need to be +versioned, such as editor backups, object or bytecode files, and built +programs. You can simply not add them, but then they’ll always crop +up as unknown files. You can also tell the version control system to +ignore these files by adding them to the ignore file at the top of the +tree. @kbd{C-x v G} (@code{vc-ignore}) can help you do this. When +called with a prefix argument, you can remove a file from the ignored +file list. @node VC Directory Mode @subsection VC Directory Mode diff --git a/etc/NEWS b/etc/NEWS index 60a846b459..fd16a43015 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -241,8 +241,9 @@ whole tree revisions. *** In VC directory mode, `L' lists the change log for the current VC controlled tree in a window. -*** `C-x v G' (globally) and `G' (in VC directory mode) ignores a -file under current version control system. +*** `C-x v G' (globally) and `G' (in VC directory mode) ignores a file +under current version control system. When called with a prefix +argument, you can remove a file from the ignored file list. ** cl-lib diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5dfca6b8e2..9292732dc4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2013-09-04 Xue Fuqiao + + * vc/vc.el (vc-ignore): Rewrite. + (vc-default-ignore): New function. + (vc-default-ignore-completion-table): Use find-ignore-file. + + * vc/vc-bzr.el (vc-bzr-ignore, vc-bzr-ignore-completion-table): + * vc/vc-git.el (vc-git-ignore, vc-git-ignore-completion-table): + * vc/vc-hg.el (vc-hg-ignore, vc-hg-ignore-completion-table): + Remove. Most code moved to vc.el. + 2013-08-04 Xue Fuqiao * vc/vc.el (vc-ignore): Rewrite. diff --git a/lisp/vc/vc-bzr.el b/lisp/vc/vc-bzr.el index e59a7dc521..0d95fbed8c 100644 --- a/lisp/vc/vc-bzr.el +++ b/lisp/vc/vc-bzr.el @@ -651,21 +651,6 @@ REV non-nil gets an error." (vc-bzr-command "cat" t 0 file "-r" rev) (vc-bzr-command "cat" t 0 file)))) -(defun vc-bzr-ignore (file &optional directory remove) - "Ignore FILE under Bazaar. -If DIRECTORY is non-nil, the repository to use will be deduced by -DIRECTORY; if REMOVE is non-nil, remove FILE from ignored files." - (if remove - (if directory - (vc--remove-regexp file (vc-bzr-find-ignore-file directory)) - (vc--remove-regexp file - (vc-bzr-find-ignore-file default-directory))) - (vc-bzr-command "ignore" t 0 file))) - -(defun vc-bzr-ignore-completion-table (file) - "Return the list of ignored files." - (vc--read-lines (vc-bzr-find-ignore-file file))) - (defun vc-bzr-find-ignore-file (file) "Return the root directory of the repository of FILE." (expand-file-name ".bzrignore" diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 472c42840a..07b7d15299 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -680,22 +680,6 @@ It is based on `log-edit-mode', and has Git-specific extensions.") nil "cat-file" "blob" (concat (if rev rev "HEAD") ":" fullname)))) -(defun vc-git-ignore (file &optional directory remove) - "Ignore FILE under Git. -If DIRECTORY is non-nil, the repository to use will be deduced by -DIRECTORY; if REMOVE is non-nil, remove FILE from ignored files." - (let (gitignore) - (if directory - (setq gitignore (vc-git-find-ignore-file directory)) - (setq gitignore (vc-git-find-ignore-file default-directory))) - (if remove - (vc--remove-regexp file gitignore) - (vc--add-line file gitignore)))) - -(defun vc-git-ignore-completion-table (file) - "Return the list of ignored files." - (vc--read-lines (vc-git-find-ignore-file file))) - (defun vc-git-find-ignore-file (file) "Return the root directory of the repository of FILE." (expand-file-name ".gitignore" diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el index 68d98a60f9..211a0c131c 100644 --- a/lisp/vc/vc-hg.el +++ b/lisp/vc/vc-hg.el @@ -459,22 +459,6 @@ REV is ignored." (vc-hg-command buffer 0 file "cat" "-r" rev) (vc-hg-command buffer 0 file "cat")))) -(defun vc-hg-ignore (file &optional directory remove) - "Ignore FILE under Mercurial. -If DIRECTORY is non-nil, the repository to use will be deduced by -DIRECTORY; if REMOVE is non-nil, remove FILE from ignored files." - (let (hgignore) - (if directory - (setq hgignore (vc-hg-find-ignore-file directory)) - (setq hgignore (vc-hg-find-ignore-file default-directory))) - (if remove - (vc--remove-regexp file hgignore) - (vc--add-line file hgignore)))) - -(defun vc-hg-ignore-completion-table (file) - "Return the list of ignored files." - (vc--read-lines (vc-hg-find-ignore-file file))) - (defun vc-hg-find-ignore-file (file) "Return the root directory of the repository of FILE." (expand-file-name ".hgignore" diff --git a/lisp/vc/vc-svn.el b/lisp/vc/vc-svn.el index 0e020614fd..38c3bd9970 100644 --- a/lisp/vc/vc-svn.el +++ b/lisp/vc/vc-svn.el @@ -354,8 +354,7 @@ This is only possible if SVN is responsible for FILE's directory.") (defun vc-svn-ignore (file &optional directory remove) "Ignore FILE under Subversion. -If DIRECTORY is non-nil, the repository to use will be deduced by -DIRECTORY; if REMOVE is non-nil, remove FILE from ignored files." +FILE is a file wildcard, relative to the root directory of DIRECTORY." (vc-svn-command t 0 file "propedit" "svn:ignore")) (defun vc-svn-ignore-completion-table (file) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 9757d4a43b..007bbe86f3 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -497,17 +497,19 @@ ;; This function is used in `vc-stay-local-p' which backends can use ;; for their convenience. ;; -;; - ignore (file &optional remove) -;; -;; Ignore FILE under the current VCS. When called interactively and -;; with a prefix argument, remove an ignored file. When called from -;; Lisp code, if REMOVE is non-nil, remove FILE from ignored files." +;; - ignore (file &optional directory) +;; +;; Ignore FILE under the VCS of DIRECTORY (default is `default-directory'). +;; FILE is a file wildcard. +;; When called interactively and with a prefix argument, remove FILE +;; from ignored files. +;; When called from Lisp code, if DIRECTORY is non-nil, the +;; repository to use will be deduced by DIRECTORY. ;; ;; - ignore-completion-table ;; -;; Return the completion table for files ignored by the current -;; version control system, e.g., the entries in `.gitignore' and -;; `.bzrignore'. +;; Return the completion table for files ignored by the version +;; control system in `default-directory'. ;; ;; - previous-revision (file rev) ;; @@ -1342,33 +1344,44 @@ first backend that could register the file is used." (let ((vc-handled-backends (list backend))) (call-interactively 'vc-register))) -(defun vc-ignore (file &optional directory remove) +(defun vc-ignore (file &optional directory) "Ignore FILE under the VCS of DIRECTORY (default is `default-directory'). +FILE is a file wildcard. When called interactively and with a prefix argument, remove FILE from ignored files. When called from Lisp code, if DIRECTORY is non-nil, the -repository to use will be deduced by DIRECTORY; if REMOVE is -non-nil, remove FILE from ignored files." +repository to use will be deduced by DIRECTORY." (interactive - (if (null current-prefix-arg) - (list (read-file-name "The file to ignore: ")) - (list - (completing-read - "The file to remove: " - (vc-call-backend - (vc-backend default-directory) - 'ignore-completion-table default-directory))))) - (let (backend) - (if directory - (progn (setq backend (vc-backend default-directory)) - (vc-call-backend backend 'ignore file directory remove)) - (setq backend (vc-backend directory)) - (vc-call-backend backend 'ignore file default-directory remove)))) - -(defun vc-default-ignore-completion-table (file) - "Return the list of ignored files." - ;; Unused lexical argument `file' - nil) + (list (read-file-name "The file to ignore: ") + (completing-read + "The file to remove: " + (vc-call-backend + (vc-backend default-directory) + 'ignore-completion-table default-directory)))) + (let* ((directory (or directory default-directory)) + (backend (vc-backend default-directory)) + (remove current-prefix-arg)) + (vc-call-backend backend 'ignore file directory remove))) + +(defun vc-default-ignore (backend file &optional directory remove) + "Ignore FILE under the VCS of DIRECTORY (default is `default-directory'). +FILE is a file wildcard, relative to the root directory of DIRECTORY. +When called from Lisp code, if DIRECTORY is non-nil, the +repository to use will be deduced by DIRECTORY; if REMOVE is +non-nil, remove FILE from ignored files. +Argument BACKEND is the backend you are using." + (let ((ignore + (vc-call-backend backend 'find-ignore-file (or directory default-directory))) + (pattern (file-relative-name + (expand-file-name file) (file-name-directory file)))) + (if remove + (vc--remove-regexp pattern ignore) + (vc--add-line pattern ignore)))) + +(defun vc-default-ignore-completion-table (backend file) + "Return the list of ignored files under BACKEND." + (vc--read-lines + (vc-call-backend backend 'find-ignore-file file))) (defun vc--read-lines (file) "Return a list of lines of FILE." -- 2.20.1