aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXue Fuqiao2013-08-04 10:55:45 +0800
committerXue Fuqiao2013-08-04 10:55:45 +0800
commitab419665caa6e2ad7465cf59ef902cc4ad1d2117 (patch)
treec1d67421021798a0dd4fc6f3c2cfb39ad374a8e7
parent3cd51eaa039f2b954cc3fd5b325d0c2102643f04 (diff)
downloademacs-ab419665caa6e2ad7465cf59ef902cc4ad1d2117.tar.gz
emacs-ab419665caa6e2ad7465cf59ef902cc4ad1d2117.zip
Cleanup for vc-ignore.
* 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.
-rw-r--r--lisp/ChangeLog24
-rw-r--r--lisp/vc/vc-bzr.el22
-rw-r--r--lisp/vc/vc-dir.el3
-rw-r--r--lisp/vc/vc-git.el30
-rw-r--r--lisp/vc/vc-hg.el30
-rw-r--r--lisp/vc/vc-svn.el10
-rw-r--r--lisp/vc/vc.el72
7 files changed, 158 insertions, 33 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 4f63206212c..d914582c280 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,27 @@
12013-08-04 Xue Fuqiao <xfq.free@gmail.com>
2
3 * vc/vc.el (vc-ignore): Rewrite.
4 (vc-default-ignore-completion-table):
5 (vc--read-lines):
6 (vc--add-line, vc--remove-regexp): New functions.
7
8 * vc/vc-svn.el (vc-svn-ignore): Doc fix.
9 (vc-svn-ignore-completion-table): New function.
10
11 * vc/vc-hg.el (vc-hg-ignore): Rewrite.
12 (vc-hg-ignore-completion-table):
13 (vc-hg-find-ignore-file): New functions.
14
15 * vc/vc-git.el (vc-git-ignore): Rewrite.
16 (vc-git-ignore-completion-table):
17 (vc-git-find-ignore-file): New functions.
18
19 * vc/vc-dir.el (vc-dir-menu-map): Add menu for vc-dir-ignore.
20
21 * vc/vc-bzr.el (vc-bzr-ignore): Rewrite.
22 (vc-bzr-ignore-completion-table):
23 (vc-bzr-find-ignore-file): New functions.
24
12013-07-30 Xue Fuqiao <xfq.free@gmail.com> 252013-07-30 Xue Fuqiao <xfq.free@gmail.com>
2 26
3 * vc/vc-svn.el (vc-svn-ignore): Remove `interactive'. Use `*vc*' 27 * vc/vc-svn.el (vc-svn-ignore): Remove `interactive'. Use `*vc*'
diff --git a/lisp/vc/vc-bzr.el b/lisp/vc/vc-bzr.el
index 9d2adde8554..e59a7dc5214 100644
--- a/lisp/vc/vc-bzr.el
+++ b/lisp/vc/vc-bzr.el
@@ -651,9 +651,25 @@ REV non-nil gets an error."
651 (vc-bzr-command "cat" t 0 file "-r" rev) 651 (vc-bzr-command "cat" t 0 file "-r" rev)
652 (vc-bzr-command "cat" t 0 file)))) 652 (vc-bzr-command "cat" t 0 file))))
653 653
654(defun vc-bzr-ignore (file) 654(defun vc-bzr-ignore (file &optional directory remove)
655 "Ignore FILE under Bazaar." 655 "Ignore FILE under Bazaar.
656 (vc-bzr-command "ignore" t 0 file)) 656If DIRECTORY is non-nil, the repository to use will be deduced by
657DIRECTORY; if REMOVE is non-nil, remove FILE from ignored files."
658 (if remove
659 (if directory
660 (vc--remove-regexp file (vc-bzr-find-ignore-file directory))
661 (vc--remove-regexp file
662 (vc-bzr-find-ignore-file default-directory)))
663 (vc-bzr-command "ignore" t 0 file)))
664
665(defun vc-bzr-ignore-completion-table (file)
666 "Return the list of ignored files."
667 (vc--read-lines (vc-bzr-find-ignore-file file)))
668
669(defun vc-bzr-find-ignore-file (file)
670 "Return the root directory of the repository of FILE."
671 (expand-file-name ".bzrignore"
672 (vc-bzr-root file)))
657 673
658(defun vc-bzr-checkout (_file &optional _editable rev) 674(defun vc-bzr-checkout (_file &optional _editable rev)
659 (if rev (error "Operation not supported") 675 (if rev (error "Operation not supported")
diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 6f03cba1f75..441b3725968 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -215,6 +215,9 @@ See `run-hooks'."
215 (define-key map [register] 215 (define-key map [register]
216 '(menu-item "Register" vc-register 216 '(menu-item "Register" vc-register
217 :help "Register file set into the version control system")) 217 :help "Register file set into the version control system"))
218 (define-key map [ignore]
219 '(menu-item "Ignore Current File" vc-dir-ignore
220 :help "Ignore the current file under current version control system"))
218 map) 221 map)
219 "Menu for VC dir.") 222 "Menu for VC dir.")
220 223
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 4716d13da13..472c42840af 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -680,16 +680,26 @@ It is based on `log-edit-mode', and has Git-specific extensions.")
680 nil 680 nil
681 "cat-file" "blob" (concat (if rev rev "HEAD") ":" fullname)))) 681 "cat-file" "blob" (concat (if rev rev "HEAD") ":" fullname))))
682 682
683(defun vc-git-ignore (file) 683(defun vc-git-ignore (file &optional directory remove)
684 "Ignore FILE under Git." 684 "Ignore FILE under Git.
685 (with-temp-buffer 685If DIRECTORY is non-nil, the repository to use will be deduced by
686 (insert-file-contents 686DIRECTORY; if REMOVE is non-nil, remove FILE from ignored files."
687 (let ((gitignore (concat (file-name-as-directory (vc-git-root 687 (let (gitignore)
688 default-directory)) ".gitignore"))) 688 (if directory
689 (unless (search-forward (concat "\n" file "\n") nil t) 689 (setq gitignore (vc-git-find-ignore-file directory))
690 (goto-char (point-max)) 690 (setq gitignore (vc-git-find-ignore-file default-directory)))
691 (insert (concat "\n" file "\n")) 691 (if remove
692 (write-region (point-min) (point-max) gitignore)))))) 692 (vc--remove-regexp file gitignore)
693 (vc--add-line file gitignore))))
694
695(defun vc-git-ignore-completion-table (file)
696 "Return the list of ignored files."
697 (vc--read-lines (vc-git-find-ignore-file file)))
698
699(defun vc-git-find-ignore-file (file)
700 "Return the root directory of the repository of FILE."
701 (expand-file-name ".gitignore"
702 (vc-git-root file)))
693 703
694(defun vc-git-checkout (file &optional _editable rev) 704(defun vc-git-checkout (file &optional _editable rev)
695 (vc-git-command nil 0 file "checkout" (or rev "HEAD"))) 705 (vc-git-command nil 0 file "checkout" (or rev "HEAD")))
diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index bc125e2cfa6..68d98a60f98 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -459,16 +459,26 @@ REV is ignored."
459 (vc-hg-command buffer 0 file "cat" "-r" rev) 459 (vc-hg-command buffer 0 file "cat" "-r" rev)
460 (vc-hg-command buffer 0 file "cat")))) 460 (vc-hg-command buffer 0 file "cat"))))
461 461
462(defun vc-hg-ignore (file) 462(defun vc-hg-ignore (file &optional directory remove)
463 "Ignore FILE under Mercurial." 463 "Ignore FILE under Mercurial.
464 (with-temp-buffer 464If DIRECTORY is non-nil, the repository to use will be deduced by
465 (insert-file-contents 465DIRECTORY; if REMOVE is non-nil, remove FILE from ignored files."
466 (let ((hgignore (concat (file-name-as-directory (vc-hg-root 466 (let (hgignore)
467 default-directory)) ".hgignore"))) 467 (if directory
468 (unless (search-forward (concat "\n" file "\n") nil t) 468 (setq hgignore (vc-hg-find-ignore-file directory))
469 (goto-char (point-max)) 469 (setq hgignore (vc-hg-find-ignore-file default-directory)))
470 (insert (concat "\n" file "\n")) 470 (if remove
471 (write-region (point-min) (point-max) hgignore)))))) 471 (vc--remove-regexp file hgignore)
472 (vc--add-line file hgignore))))
473
474(defun vc-hg-ignore-completion-table (file)
475 "Return the list of ignored files."
476 (vc--read-lines (vc-hg-find-ignore-file file)))
477
478(defun vc-hg-find-ignore-file (file)
479 "Return the root directory of the repository of FILE."
480 (expand-file-name ".hgignore"
481 (vc-hg-root file)))
472 482
473;; Modeled after the similar function in vc-bzr.el 483;; Modeled after the similar function in vc-bzr.el
474(defun vc-hg-checkout (file &optional _editable rev) 484(defun vc-hg-checkout (file &optional _editable rev)
diff --git a/lisp/vc/vc-svn.el b/lisp/vc/vc-svn.el
index 743a4d5cb67..0e020614fd2 100644
--- a/lisp/vc/vc-svn.el
+++ b/lisp/vc/vc-svn.el
@@ -352,10 +352,16 @@ This is only possible if SVN is responsible for FILE's directory.")
352 (concat "-r" rev)) 352 (concat "-r" rev))
353 (vc-switches 'SVN 'checkout)))) 353 (vc-switches 'SVN 'checkout))))
354 354
355(defun vc-svn-ignore (file) 355(defun vc-svn-ignore (file &optional directory remove)
356 "Ignore FILE under Subversion." 356 "Ignore FILE under Subversion.
357If DIRECTORY is non-nil, the repository to use will be deduced by
358DIRECTORY; if REMOVE is non-nil, remove FILE from ignored files."
357 (vc-svn-command t 0 file "propedit" "svn:ignore")) 359 (vc-svn-command t 0 file "propedit" "svn:ignore"))
358 360
361(defun vc-svn-ignore-completion-table (file)
362 "Return the list of ignored files."
363 )
364
359(defun vc-svn-checkout (file &optional editable rev) 365(defun vc-svn-checkout (file &optional editable rev)
360 (message "Checking out %s..." file) 366 (message "Checking out %s..." file)
361 (with-current-buffer (or (get-file-buffer file) (current-buffer)) 367 (with-current-buffer (or (get-file-buffer file) (current-buffer))
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 210e647ba65..9757d4a43be 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -486,6 +486,7 @@
486;; default implementation always returns nil. 486;; default implementation always returns nil.
487;; 487;;
488;; - root (file) 488;; - root (file)
489;;
489;; Return the root of the VC controlled hierarchy for file. 490;; Return the root of the VC controlled hierarchy for file.
490;; 491;;
491;; - repository-hostname (dirname) 492;; - repository-hostname (dirname)
@@ -496,6 +497,18 @@
496;; This function is used in `vc-stay-local-p' which backends can use 497;; This function is used in `vc-stay-local-p' which backends can use
497;; for their convenience. 498;; for their convenience.
498;; 499;;
500;; - ignore (file &optional remove)
501;;
502;; Ignore FILE under the current VCS. When called interactively and
503;; with a prefix argument, remove an ignored file. When called from
504;; Lisp code, if REMOVE is non-nil, remove FILE from ignored files."
505;;
506;; - ignore-completion-table
507;;
508;; Return the completion table for files ignored by the current
509;; version control system, e.g., the entries in `.gitignore' and
510;; `.bzrignore'.
511;;
499;; - previous-revision (file rev) 512;; - previous-revision (file rev)
500;; 513;;
501;; Return the revision number that precedes REV for FILE, or nil if no such 514;; Return the revision number that precedes REV for FILE, or nil if no such
@@ -576,9 +589,6 @@
576;; 589;;
577;; - deal with push/pull operations. 590;; - deal with push/pull operations.
578;; 591;;
579;; - add a mechanism for editing the underlying VCS's list of files
580;; to be ignored, when that's possible.
581;;
582;;;; Primitives that need changing: 592;;;; Primitives that need changing:
583;; 593;;
584;; - vc-update/vc-merge should deal with VC systems that don't 594;; - 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."
1332 (let ((vc-handled-backends (list backend))) 1342 (let ((vc-handled-backends (list backend)))
1333 (call-interactively 'vc-register))) 1343 (call-interactively 'vc-register)))
1334 1344
1335(defun vc-ignore (file) 1345(defun vc-ignore (file &optional directory remove)
1336 "Ignore FILE under the current VCS." 1346 "Ignore FILE under the VCS of DIRECTORY (default is `default-directory').
1337 (interactive "fIgnore file: ") 1347When called interactively and with a prefix argument, remove FILE
1338 (let ((backend (vc-backend file))) 1348from ignored files.
1339 (vc-call-backend backend 'ignore file))) 1349When called from Lisp code, if DIRECTORY is non-nil, the
1350repository to use will be deduced by DIRECTORY; if REMOVE is
1351non-nil, remove FILE from ignored files."
1352 (interactive
1353 (if (null current-prefix-arg)
1354 (list (read-file-name "The file to ignore: "))
1355 (list
1356 (completing-read
1357 "The file to remove: "
1358 (vc-call-backend
1359 (vc-backend default-directory)
1360 'ignore-completion-table default-directory)))))
1361 (let (backend)
1362 (if directory
1363 (progn (setq backend (vc-backend default-directory))
1364 (vc-call-backend backend 'ignore file directory remove))
1365 (setq backend (vc-backend directory))
1366 (vc-call-backend backend 'ignore file default-directory remove))))
1367
1368(defun vc-default-ignore-completion-table (file)
1369 "Return the list of ignored files."
1370 ;; Unused lexical argument `file'
1371 nil)
1372
1373(defun vc--read-lines (file)
1374 "Return a list of lines of FILE."
1375 (with-temp-buffer
1376 (insert-file-contents file)
1377 (split-string (buffer-string) "\n" t)))
1378
1379;; Subroutine for `vc-git-ignore' and `vc-hg-ignore'.
1380(defun vc--add-line (string file)
1381 "Add STRING as a line to FILE."
1382 (with-temp-buffer
1383 (insert-file-contents file)
1384 (unless (re-search-forward (concat "^" (regexp-quote string) "$") nil t)
1385 (goto-char (point-max))
1386 (insert (concat "\n" string))
1387 (write-region (point-min) (point-max) file))))
1388
1389(defun vc--remove-regexp (regexp file)
1390 "Remove all matching for REGEXP in FILE."
1391 (with-temp-buffer
1392 (insert-file-contents file)
1393 (while (re-search-forward regexp nil t)
1394 (replace-match ""))
1395 (write-region (point-min) (point-max) file)))
1340 1396
1341(defun vc-checkout (file &optional writable rev) 1397(defun vc-checkout (file &optional writable rev)
1342 "Retrieve a copy of the revision REV of FILE. 1398 "Retrieve a copy of the revision REV of FILE.