diff options
| author | Dan Nicolaescu | 2008-07-05 18:09:32 +0000 |
|---|---|---|
| committer | Dan Nicolaescu | 2008-07-05 18:09:32 +0000 |
| commit | d923f4ac083aca4d41e6a7997ab96357526d7bf4 (patch) | |
| tree | 5286b60d8bea03d0394fe42ecf0b4095379918dd | |
| parent | 4f10da1c12a1e91bd2b491ff98ca3c5ec91f5c67 (diff) | |
| download | emacs-d923f4ac083aca4d41e6a7997ab96357526d7bf4.tar.gz emacs-d923f4ac083aca4d41e6a7997ab96357526d7bf4.zip | |
* vc-dir.el (vc-dir-find-child-files): New function.
(vc-dir-resync-directory-files): New function.
(vc-dir-recompute-file-state): New function, broken out of ...
(vc-dir-resynch-file): ... here. Also deal with directories.
* vc-dispatcher.el (vc-resynch-buffers-in-directory): New function.
(vc-resynch-buffer): Use it.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/vc-dir.el | 86 | ||||
| -rw-r--r-- | lisp/vc-dispatcher.el | 18 |
3 files changed, 78 insertions, 33 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1548dae4d58..4fddac183ba 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,12 @@ | |||
| 1 | 2008-07-05 Dan Nicolaescu <dann@ics.uci.edu> | 1 | 2008-07-05 Dan Nicolaescu <dann@ics.uci.edu> |
| 2 | 2 | ||
| 3 | * vc-dir.el (vc-dir-find-child-files): New function. | ||
| 4 | (vc-dir-resync-directory-files): New function. | ||
| 5 | (vc-dir-recompute-file-state): New function, broken out of ... | ||
| 6 | (vc-dir-resynch-file): ... here. Also deal with directories. | ||
| 7 | * vc-dispatcher.el (vc-resynch-buffers-in-directory): New function. | ||
| 8 | (vc-resynch-buffer): Use it. | ||
| 9 | |||
| 3 | * vc-hg.el (vc-hg-registered): Do not set vc-state. | 10 | * vc-hg.el (vc-hg-registered): Do not set vc-state. |
| 4 | 11 | ||
| 5 | * vc-annotate.el (vc-annotate-mode-menu): Add separator. | 12 | * vc-annotate.el (vc-annotate-mode-menu): Add separator. |
diff --git a/lisp/vc-dir.el b/lisp/vc-dir.el index 981178a67c8..dcb5f00c155 100644 --- a/lisp/vc-dir.el +++ b/lisp/vc-dir.el | |||
| @@ -770,37 +770,65 @@ If it is a file, return the corresponding cons for the file itself." | |||
| 770 | (vc-dir-fileinfo->state crt-data)) result)) | 770 | (vc-dir-fileinfo->state crt-data)) result)) |
| 771 | result)) | 771 | result)) |
| 772 | 772 | ||
| 773 | (defun vc-dir-recompute-file-state (fname def-dir) | ||
| 774 | (let* ((file-short (file-relative-name fname def-dir)) | ||
| 775 | (state (vc-call-backend vc-dir-backend 'state fname)) | ||
| 776 | (extra (vc-call-backend vc-dir-backend | ||
| 777 | 'status-fileinfo-extra fname))) | ||
| 778 | (list file-short state extra))) | ||
| 779 | |||
| 780 | (defun vc-dir-find-child-files (dirname) | ||
| 781 | ;; Give a DIRNAME string return the list of all child files shown in | ||
| 782 | ;; the current *vc-dir* buffer. | ||
| 783 | (let ((crt (ewoc-nth vc-ewoc 0)) | ||
| 784 | children | ||
| 785 | dname) | ||
| 786 | ;; Find DIR | ||
| 787 | (while (and crt (not (vc-string-prefix-p | ||
| 788 | dirname (vc-dir-node-directory crt)))) | ||
| 789 | (setq crt (ewoc-next vc-ewoc crt))) | ||
| 790 | (while (and crt (vc-string-prefix-p | ||
| 791 | dirname | ||
| 792 | (setq dname (vc-dir-node-directory crt)))) | ||
| 793 | (let ((data (ewoc-data crt))) | ||
| 794 | (unless (vc-dir-fileinfo->directory data) | ||
| 795 | (push (expand-file-name (vc-dir-fileinfo->name data)) children))) | ||
| 796 | (setq crt (ewoc-next vc-ewoc crt))) | ||
| 797 | children)) | ||
| 798 | |||
| 799 | (defun vc-dir-resync-directory-files (dirname) | ||
| 800 | ;; Update the entries for all the child files of DIRNAME shown in | ||
| 801 | ;; the current *vc-dir* buffer. | ||
| 802 | (let ((files (vc-dir-find-child-files dirname)) | ||
| 803 | (ddir (expand-file-name default-directory)) | ||
| 804 | fileentries) | ||
| 805 | (when files | ||
| 806 | (dolist (crt files) | ||
| 807 | (push (vc-dir-recompute-file-state crt ddir) | ||
| 808 | fileentries)) | ||
| 809 | (vc-dir-update fileentries (current-buffer))))) | ||
| 810 | |||
| 773 | (defun vc-dir-resynch-file (&optional fname) | 811 | (defun vc-dir-resynch-file (&optional fname) |
| 774 | "Update the entries for FILE in any directory buffers that list it." | 812 | "Update the entries for FILE in any directory buffers that list it." |
| 775 | (let ((file (or fname (expand-file-name buffer-file-name)))) | 813 | (let ((file (or fname (expand-file-name buffer-file-name))) |
| 776 | (if (file-directory-p file) | 814 | (found-vc-dir-buf nil)) |
| 777 | ;; FIXME: Maybe this should never happen? | 815 | (save-excursion |
| 778 | ;; FIXME: But it is useful to update the state of a directory | 816 | (dolist (status-buf (buffer-list)) |
| 779 | ;; (more precisely the files in the directory) after some VC | 817 | (set-buffer status-buf) |
| 780 | ;; operations. | 818 | ;; look for a vc-dir buffer that might show this file. |
| 781 | nil | 819 | (when (derived-mode-p 'vc-dir-mode) |
| 782 | (let ((found-vc-dir-buf nil)) | 820 | (setq found-vc-dir-buf t) |
| 783 | (save-excursion | 821 | (let ((ddir (expand-file-name default-directory))) |
| 784 | (dolist (status-buf (buffer-list)) | 822 | (when (vc-string-prefix-p ddir file) |
| 785 | (set-buffer status-buf) | 823 | (if (file-directory-p file) |
| 786 | ;; look for a vc-dir buffer that might show this file. | 824 | (vc-dir-resync-directory-files file) |
| 787 | (when (derived-mode-p 'vc-dir-mode) | 825 | (vc-dir-update |
| 788 | (setq found-vc-dir-buf t) | 826 | (list (vc-dir-recompute-file-state file ddir)) |
| 789 | (let ((ddir (expand-file-name default-directory))) | 827 | status-buf))))))) |
| 790 | (when (vc-string-prefix-p ddir file) | 828 | ;; We didn't find any vc-dir buffers, remove the hook, it is |
| 791 | (let* | 829 | ;; not needed. |
| 792 | ;; FIXME: Any reason we don't use file-relative-name? | 830 | (unless found-vc-dir-buf |
| 793 | ((file-short (substring file (length ddir))) | 831 | (remove-hook 'after-save-hook 'vc-dir-resynch-file)))) |
| 794 | (state (vc-call-backend vc-dir-backend 'state file)) | ||
| 795 | (extra (vc-call-backend vc-dir-backend | ||
| 796 | 'status-fileinfo-extra file)) | ||
| 797 | (entry | ||
| 798 | (list file-short state extra))) | ||
| 799 | (vc-dir-update (list entry) status-buf)))))) | ||
| 800 | ;; We didn't find any vc-dir buffers, remove the hook, it is | ||
| 801 | ;; not needed. | ||
| 802 | (unless found-vc-dir-buf | ||
| 803 | (remove-hook 'after-save-hook 'vc-dir-resynch-file))))))) | ||
| 804 | 832 | ||
| 805 | (defvar use-vc-backend) ;; dynamically bound | 833 | (defvar use-vc-backend) ;; dynamically bound |
| 806 | 834 | ||
diff --git a/lisp/vc-dispatcher.el b/lisp/vc-dispatcher.el index 6a91ac343d5..d4ebb398e98 100644 --- a/lisp/vc-dispatcher.el +++ b/lisp/vc-dispatcher.el | |||
| @@ -480,15 +480,25 @@ editing!" | |||
| 480 | (kill-buffer (current-buffer))))) | 480 | (kill-buffer (current-buffer))))) |
| 481 | 481 | ||
| 482 | (declare-function vc-dir-resynch-file "vc-dir" (&optional fname)) | 482 | (declare-function vc-dir-resynch-file "vc-dir" (&optional fname)) |
| 483 | (declare-function vc-string-prefix-p "vc" (prefix string)) | ||
| 484 | |||
| 485 | (defun vc-resynch-buffers-in-directory (directory &optional keep noquery) | ||
| 486 | "Resync all buffers that visit files in DIRECTORY." | ||
| 487 | (dolist (buffer (buffer-list)) | ||
| 488 | (let ((fname (buffer-file-name buffer))) | ||
| 489 | (when (and fname (vc-string-prefix-p directory fname)) | ||
| 490 | (vc-resynch-buffer fname keep noquery))))) | ||
| 483 | 491 | ||
| 484 | (defun vc-resynch-buffer (file &optional keep noquery) | 492 | (defun vc-resynch-buffer (file &optional keep noquery) |
| 485 | "If FILE is currently visited, resynch its buffer." | 493 | "If FILE is currently visited, resynch its buffer." |
| 486 | (if (string= buffer-file-name file) | 494 | (if (string= buffer-file-name file) |
| 487 | (vc-resynch-window file keep noquery) | 495 | (vc-resynch-window file keep noquery) |
| 488 | (let ((buffer (get-file-buffer file))) | 496 | (if (file-directory-p file) |
| 489 | (when buffer | 497 | (vc-resynch-buffers-in-directory file keep noquery) |
| 490 | (with-current-buffer buffer | 498 | (let ((buffer (get-file-buffer file))) |
| 491 | (vc-resynch-window file keep noquery))))) | 499 | (when buffer |
| 500 | (with-current-buffer buffer | ||
| 501 | (vc-resynch-window file keep noquery)))))) | ||
| 492 | ;; Try to avoid unnecessary work, a *vc-dir* buffer is only present | 502 | ;; Try to avoid unnecessary work, a *vc-dir* buffer is only present |
| 493 | ;; if this is true. | 503 | ;; if this is true. |
| 494 | (when (memq 'vc-dir-resynch-file after-save-hook) | 504 | (when (memq 'vc-dir-resynch-file after-save-hook) |