diff options
author | Dan Nicolaescu <dann@ics.uci.edu> | 2008-07-05 18:09:32 +0000 |
---|---|---|
committer | Dan Nicolaescu <dann@ics.uci.edu> | 2008-07-05 18:09:32 +0000 |
commit | d923f4ac083aca4d41e6a7997ab96357526d7bf4 (patch) | |
tree | 5286b60d8bea03d0394fe42ecf0b4095379918dd /lisp/vc-dir.el | |
parent | 4f10da1c12a1e91bd2b491ff98ca3c5ec91f5c67 (diff) |
* 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.
Diffstat (limited to 'lisp/vc-dir.el')
-rw-r--r-- | lisp/vc-dir.el | 86 |
1 files changed, 57 insertions, 29 deletions
diff --git a/lisp/vc-dir.el b/lisp/vc-dir.el index 981178a67c..dcb5f00c15 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." (vc-dir-fileinfo->state crt-data)) result)) result)) +(defun vc-dir-recompute-file-state (fname def-dir) + (let* ((file-short (file-relative-name fname def-dir)) + (state (vc-call-backend vc-dir-backend 'state fname)) + (extra (vc-call-backend vc-dir-backend + 'status-fileinfo-extra fname))) + (list file-short state extra))) + +(defun vc-dir-find-child-files (dirname) + ;; Give a DIRNAME string return the list of all child files shown in + ;; the current *vc-dir* buffer. + (let ((crt (ewoc-nth vc-ewoc 0)) + children + dname) + ;; Find DIR + (while (and crt (not (vc-string-prefix-p + dirname (vc-dir-node-directory crt)))) + (setq crt (ewoc-next vc-ewoc crt))) + (while (and crt (vc-string-prefix-p + dirname + (setq dname (vc-dir-node-directory crt)))) + (let ((data (ewoc-data crt))) + (unless (vc-dir-fileinfo->directory data) + (push (expand-file-name (vc-dir-fileinfo->name data)) children))) + (setq crt (ewoc-next vc-ewoc crt))) + children)) + +(defun vc-dir-resync-directory-files (dirname) + ;; Update the entries for all the child files of DIRNAME shown in + ;; the current *vc-dir* buffer. + (let ((files (vc-dir-find-child-files dirname)) + (ddir (expand-file-name default-directory)) + fileentries) + (when files + (dolist (crt files) + (push (vc-dir-recompute-file-state crt ddir) + fileentries)) + (vc-dir-update fileentries (current-buffer))))) + (defun vc-dir-resynch-file (&optional fname) "Update the entries for FILE in any directory buffers that list it." - (let ((file (or fname (expand-file-name buffer-file-name)))) - (if (file-directory-p file) - ;; FIXME: Maybe this should never happen? - ;; FIXME: But it is useful to update the state of a directory - ;; (more precisely the files in the directory) after some VC - ;; operations. - nil - (let ((found-vc-dir-buf nil)) - (save-excursion - (dolist (status-buf (buffer-list)) - (set-buffer status-buf) - ;; look for a vc-dir buffer that might show this file. - (when (derived-mode-p 'vc-dir-mode) - (setq found-vc-dir-buf t) - (let ((ddir (expand-file-name default-directory))) - (when (vc-string-prefix-p ddir file) - (let* - ;; FIXME: Any reason we don't use file-relative-name? - ((file-short (substring file (length ddir))) - (state (vc-call-backend vc-dir-backend 'state file)) - (extra (vc-call-backend vc-dir-backend - 'status-fileinfo-extra file)) - (entry - (list file-short state extra))) - (vc-dir-update (list entry) status-buf)))))) - ;; We didn't find any vc-dir buffers, remove the hook, it is - ;; not needed. - (unless found-vc-dir-buf - (remove-hook 'after-save-hook 'vc-dir-resynch-file))))))) + (let ((file (or fname (expand-file-name buffer-file-name))) + (found-vc-dir-buf nil)) + (save-excursion + (dolist (status-buf (buffer-list)) + (set-buffer status-buf) + ;; look for a vc-dir buffer that might show this file. + (when (derived-mode-p 'vc-dir-mode) + (setq found-vc-dir-buf t) + (let ((ddir (expand-file-name default-directory))) + (when (vc-string-prefix-p ddir file) + (if (file-directory-p file) + (vc-dir-resync-directory-files file) + (vc-dir-update + (list (vc-dir-recompute-file-state file ddir)) + status-buf))))))) + ;; We didn't find any vc-dir buffers, remove the hook, it is + ;; not needed. + (unless found-vc-dir-buf + (remove-hook 'after-save-hook 'vc-dir-resynch-file)))) (defvar use-vc-backend) ;; dynamically bound |