]> git.eshelyaron.com Git - emacs.git/commitdiff
Cleanup for vc-ignore.
authorXue Fuqiao <xfq.free@gmail.com>
Sun, 4 Aug 2013 02:55:45 +0000 (10:55 +0800)
committerXue Fuqiao <xfq.free@gmail.com>
Sun, 4 Aug 2013 02:55:45 +0000 (10:55 +0800)
* vc/vc.el (vc-ignore): Rewrite.
(vc-default-ignore-completion-table):
(vc--read-lines):
(vc--add-line, vc--remove-regexp): New functions.

* vc/vc-svn.el (vc-svn-ignore): Doc fix.
(vc-svn-ignore-completion-table): New function.

* vc/vc-hg.el (vc-hg-ignore): Rewrite.
(vc-hg-ignore-completion-table):
(vc-hg-find-ignore-file): New functions.

* vc/vc-git.el (vc-git-ignore): Rewrite.
(vc-git-ignore-completion-table):
(vc-git-find-ignore-file): New functions.

* vc/vc-dir.el (vc-dir-menu-map): Add menu for vc-dir-ignore.

* vc/vc-bzr.el (vc-bzr-ignore): Rewrite.
(vc-bzr-ignore-completion-table):
(vc-bzr-find-ignore-file): New functions.

lisp/ChangeLog
lisp/vc/vc-bzr.el
lisp/vc/vc-dir.el
lisp/vc/vc-git.el
lisp/vc/vc-hg.el
lisp/vc/vc-svn.el
lisp/vc/vc.el

index 4f63206212c0e0f55e88ac155652b25c68fb96a0..d914582c280b36718e9a2836051296671dfe49c4 100644 (file)
@@ -1,3 +1,27 @@
+2013-08-04  Xue Fuqiao  <xfq.free@gmail.com>
+
+       * vc/vc.el (vc-ignore): Rewrite.
+       (vc-default-ignore-completion-table):
+       (vc--read-lines):
+       (vc--add-line, vc--remove-regexp): New functions.
+
+       * vc/vc-svn.el (vc-svn-ignore): Doc fix.
+       (vc-svn-ignore-completion-table): New function.
+
+       * vc/vc-hg.el (vc-hg-ignore): Rewrite.
+       (vc-hg-ignore-completion-table):
+       (vc-hg-find-ignore-file): New functions.
+
+       * vc/vc-git.el (vc-git-ignore): Rewrite.
+       (vc-git-ignore-completion-table):
+       (vc-git-find-ignore-file): New functions.
+
+       * vc/vc-dir.el (vc-dir-menu-map): Add menu for vc-dir-ignore.
+
+       * vc/vc-bzr.el (vc-bzr-ignore): Rewrite.
+       (vc-bzr-ignore-completion-table):
+       (vc-bzr-find-ignore-file): New functions.
+
 2013-07-30  Xue Fuqiao  <xfq.free@gmail.com>
 
        * vc/vc-svn.el (vc-svn-ignore): Remove `interactive'.  Use `*vc*'
index 9d2adde85546f90fcf9b1c66e898d717bc300708..e59a7dc5214f52f53a052d554cc97971133e9a6f 100644 (file)
@@ -651,9 +651,25 @@ 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)
-  "Ignore FILE under Bazaar."
-  (vc-bzr-command "ignore" 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"
+                   (vc-bzr-root file)))
 
 (defun vc-bzr-checkout (_file &optional _editable rev)
   (if rev (error "Operation not supported")
index 6f03cba1f759d7d50e83dedfa577b5b067f8af2e..441b37259683b094a7d6e69f30fdcc276c83fe7e 100644 (file)
@@ -215,6 +215,9 @@ See `run-hooks'."
     (define-key map [register]
       '(menu-item "Register" vc-register
                  :help "Register file set into the version control system"))
+    (define-key map [ignore]
+      '(menu-item "Ignore Current File" vc-dir-ignore
+                 :help "Ignore the current file under current version control system"))
     map)
   "Menu for VC dir.")
 
index 4716d13da13e5280d9232646ddbeb6f7bc3acb59..472c42840af135b7f28c3f1346838a62ed04fef0 100644 (file)
@@ -680,16 +680,26 @@ 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)
-  "Ignore FILE under Git."
-  (with-temp-buffer
-    (insert-file-contents
-     (let ((gitignore (concat (file-name-as-directory (vc-git-root
-                                                     default-directory)) ".gitignore")))
-       (unless (search-forward (concat "\n" file "\n") nil t)
-        (goto-char (point-max))
-        (insert (concat "\n" file "\n"))
-        (write-region (point-min) (point-max) gitignore))))))
+(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"
+                   (vc-git-root file)))
 
 (defun vc-git-checkout (file &optional _editable rev)
   (vc-git-command nil 0 file "checkout" (or rev "HEAD")))
index bc125e2cfa65f81e8d546ab39bb48f88874f5468..68d98a60f98d1a533b8562326ae2fa365a3834bf 100644 (file)
@@ -459,16 +459,26 @@ REV is ignored."
         (vc-hg-command buffer 0 file "cat" "-r" rev)
       (vc-hg-command buffer 0 file "cat"))))
 
-(defun vc-hg-ignore (file)
-  "Ignore FILE under Mercurial."
-  (with-temp-buffer
-    (insert-file-contents 
-     (let ((hgignore (concat (file-name-as-directory (vc-hg-root
-                                                    default-directory)) ".hgignore")))
-       (unless (search-forward (concat "\n" file "\n") nil t)
-        (goto-char (point-max))
-        (insert (concat "\n" file "\n"))
-        (write-region (point-min) (point-max) hgignore))))))
+(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"
+                   (vc-hg-root file)))
 
 ;; Modeled after the similar function in vc-bzr.el
 (defun vc-hg-checkout (file &optional _editable rev)
index 743a4d5cb678f7a600e323f83b4ca2b0bbab8f8a..0e020614fd2a0afa065c5799e050ea018973fa6f 100644 (file)
@@ -352,10 +352,16 @@ This is only possible if SVN is responsible for FILE's directory.")
                (concat "-r" rev))
           (vc-switches 'SVN 'checkout))))
 
-(defun vc-svn-ignore (file)
-  "Ignore FILE under Subversion."
+(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."
   (vc-svn-command t 0 file "propedit" "svn:ignore"))
 
+(defun vc-svn-ignore-completion-table (file)
+  "Return the list of ignored files."
+  )
+
 (defun vc-svn-checkout (file &optional editable rev)
   (message "Checking out %s..." file)
   (with-current-buffer (or (get-file-buffer file) (current-buffer))
index 210e647ba652a2cefdde770bce080a5bfb7d6e68..9757d4a43bedf261a9b36dd8f37ad68477e9ac32 100644 (file)
 ;;   default implementation always returns nil.
 ;;
 ;; - root (file)
+;; 
 ;;   Return the root of the VC controlled hierarchy for file.
 ;;
 ;; - repository-hostname (dirname)
 ;;   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-completion-table
+;; 
+;;   Return the completion table for files ignored by the current
+;;   version control system, e.g., the entries in `.gitignore' and
+;;   `.bzrignore'.
+;; 
 ;; - previous-revision (file rev)
 ;;
 ;;   Return the revision number that precedes REV for FILE, or nil if no such
 ;;
 ;; - deal with push/pull operations.
 ;;
-;; - add a mechanism for editing the underlying VCS's list of files
-;;   to be ignored, when that's possible.
-;;
 ;;;; Primitives that need changing:
 ;;
 ;; - vc-update/vc-merge should deal with VC systems that don't
@@ -1332,11 +1342,57 @@ first backend that could register the file is used."
   (let ((vc-handled-backends (list backend)))
     (call-interactively 'vc-register)))
 
-(defun vc-ignore (file)
-  "Ignore FILE under the current VCS."
-  (interactive "fIgnore file: ")
-  (let ((backend (vc-backend file)))
-    (vc-call-backend backend 'ignore file)))
+(defun vc-ignore (file &optional directory remove)
+  "Ignore FILE under the VCS of DIRECTORY (default is `default-directory').
+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."
+  (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)
+
+(defun vc--read-lines (file)
+  "Return a list of lines of FILE."
+  (with-temp-buffer
+    (insert-file-contents file)
+    (split-string (buffer-string) "\n" t)))
+
+;; Subroutine for `vc-git-ignore' and `vc-hg-ignore'.
+(defun vc--add-line (string file)
+  "Add STRING as a line to FILE."
+  (with-temp-buffer
+    (insert-file-contents file)
+    (unless (re-search-forward (concat "^" (regexp-quote string) "$") nil t)
+      (goto-char (point-max))
+      (insert (concat "\n" string))
+      (write-region (point-min) (point-max) file))))
+
+(defun vc--remove-regexp (regexp file)
+  "Remove all matching for REGEXP in FILE."
+  (with-temp-buffer
+    (insert-file-contents file)
+    (while (re-search-forward regexp nil t)
+      (replace-match ""))
+    (write-region (point-min) (point-max) file)))
 
 (defun vc-checkout (file &optional writable rev)
   "Retrieve a copy of the revision REV of FILE.