comparison lisp/vc-dir.el @ 96520:00812d11af93

* 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.
author Dan Nicolaescu <dann@ics.uci.edu>
date Sat, 05 Jul 2008 18:09:32 +0000
parents 4c68d664c39b
children d39625535543
comparison
equal deleted inserted replaced
96519:0197baf37347 96520:00812d11af93
768 (push 768 (push
769 (cons (expand-file-name (vc-dir-fileinfo->name crt-data)) 769 (cons (expand-file-name (vc-dir-fileinfo->name crt-data))
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
807 (define-derived-mode vc-dir-mode special-mode "VC dir" 835 (define-derived-mode vc-dir-mode special-mode "VC dir"
808 "Major mode for dispatcher directory buffers. 836 "Major mode for dispatcher directory buffers.