emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: autorevert and vc


From: Luc Teirlinck
Subject: Re: autorevert and vc
Date: Mon, 29 Mar 2004 20:27:51 -0600 (CST)

Stefan Monnier wrote:

   In other words the VC-state-refresh code should be completely separate
   from the file-buffer-refresh code since both can change independently.
   It can still all be in autorevert.el, but a refresh of one shouldn't
   necessarily force a refresh of another (currently a refresh of the buffer
   text forces a refresh of the VC-state, which is OK only because we don't
   kow how to check staleness of the VC-state so we use staleness of the
   buffer-text as a heuristic that the VC-state might also be stale).

It apparently does not seem to take that much CPU to update the
VC-state (without reverting the buffer) every five seconds, whether it
is needed or not.  I needed at least twenty version controlled buffers
to make the CPU usage just barely measurable on a 1.7 GHZ dual Xeon.
On the other hand, the problem only occurs while editing the same
version controlled buffer from two distinct Emacs buffers.  Why waste
_any_ CPU if one knows that that situation is not going to occur?  

The patch below takes out all original vc-code, as you suggested.
Then it takes care of the problem that code was intended to fix by
calling `vc-find-file-hook' unconditionally if the user requests that
through a customizable variable.  The default is nil, do not do this.
If the user has a reasonably fast machine and worries about the
problem, he sets it to t and forgets about it.  If the user knows he
never is going to be in that situation, he keeps it nil.  Otherwise,
he sets it to t whenever the need arises.

Note that my patch works for all version control systems supported by
VC (I checked it for RCS), whereas the original only worked for CVS.

Does this look OK?

===File ~/autorevert-diff1==================================
*** autorevert.el       28 Mar 2004 07:51:54 -0600      1.27
--- autorevert.el       29 Mar 2004 19:39:15 -0600      
***************
*** 70,83 ****
  ;; Dependencies:
  
  (require 'timer)
! (autoload 'dired-get-filename "dired")
! (autoload 'vc-workfile-version "vc-hooks")
! (autoload 'vc-mode-line        "vc-hooks")
! 
! (eval-when-compile
!   (defvar dired-directory)
!   (defvar vc-mode)
!   (require 'cl))
  
  
  ;; Custom Group:
--- 70,77 ----
  ;; Dependencies:
  
  (require 'timer)
! 
! (eval-when-compile (require 'cl))
  
  
  ;; Custom Group:
***************
*** 191,196 ****
--- 185,205 ----
    :group 'auto-revert
    :type 'hook)
  
+ (defcustom auto-revert-check-vc-numbers nil
+   "If non-nil Auto Revert Mode reliably updates version control info.
+ This matters if a version controlled file is edited from several
+ Emacs sessions.  In that case, if changes in one session are saved,
+ any buffers visiting the file in other sessions are updated.
+ However, if the changes are checked in, the version control number
+ in the mode line, as well as other version control related
+ information, may not be properly updated in the other sessions.
+ If you are worried about this, set this variable to a non-nil value.
+ This should not cause excessive CPU usage on a reasonably fast
+ machine, if it does not apply to too many version controlled buffers."
+   :group 'auto-revert
+   :type 'boolean
+   :version "21.4")
+ 
  (defvar global-auto-revert-ignore-buffer nil
    "*When non-nil, Global Auto-Revert Mode will not revert this buffer.
  
***************
*** 279,365 ****
         (not (memq major-mode
                  global-auto-revert-ignore-modes)))))
  
- (defun auto-revert-vc-cvs-file-version (file)
-   "Get version of FILE by reading control file on disk."
-   (let* ((control "CVS/Entries")
-        (name    (file-name-nondirectory file))
-        (path    (format "%s/%s"
-                         (file-name-directory file)
-                         control)))
-     (when (file-exists-p path)
-       (with-temp-buffer
-       (insert-file-contents-literally path)
-       (goto-char (point-min))
-       (when (re-search-forward
-              ;; /file.txt/1.3/Mon Sep 15 18:43:20 2003//
-              (format "%s/\\([.0-9]+\\)" (regexp-quote name))
-              nil t)
-         (match-string 1))))))
- 
- (defun auto-revert-vc-buffer-p ()
-   "Check if buffer is version controlled."
-   (and (boundp 'vc-mode)
-        (string-match "[0-9]" (or vc-mode ""))))
- 
- (defun auto-revert-handler-vc ()
-   "Check if version controlled buffer needs revert."
-   ;; [Emacs 1]
-   ;; 1. File is saved   (*)
-   ;; 2. checkin is done 1.1 -> 1.2
-   ;; 3. VC reverts, so that updated version number is shown in mode line
-   ;;
-   ;; Suppose the same file has been opened in another Emacs and
-   ;; autorevert.el is on.
-   ;;
-   ;; [Emacs 2]
-   ;; 1. Step (1) is detected and buffer is reverted.
-   ;; 2. But check in does not always change the file in dis, but possibly only
-   ;;  control files like CVS/Entries
-   ;; 3. The buffer is not reverted to update VC version line.
-   ;;  Incorrect version number 1.1 is shown in this Emacs
-   ;;
-   (when (featurep 'vc)
-     (let* ((file         (buffer-file-name))
-          (backend        (vc-backend (buffer-file-name)))
-          (version-buffer (vc-workfile-version file)))
-       (when (stringp version-buffer)
-       (cond
-        ((eq backend 'CVS)
-         (let ((version-file
-                (auto-revert-vc-cvs-file-version (buffer-file-name))))
-           (and (stringp version-file)
-                (not (string-match version-file version-buffer)))))
-        ((eq backend 'RCS)
-         ;; TODO:
-         ))))))
- 
  (defun auto-revert-handler ()
    "Revert current buffer, if appropriate.
  This is an internal function used by Auto-Revert Mode."
    (unless (buffer-modified-p)
      (let (revert)
!       (cond
!        ((auto-revert-vc-buffer-p)
!       (when (auto-revert-handler-vc)
!         (setq revert 'vc)))
!        ((or (and (buffer-file-name)
!                (file-readable-p (buffer-file-name))
!                (not (verify-visited-file-modtime (current-buffer))))
!           (and (or auto-revert-mode global-auto-revert-non-file-buffers)
!                revert-buffer-function
!                (boundp 'buffer-stale-function)
!                (functionp buffer-stale-function)
!                (funcall buffer-stale-function t)))
!       (setq revert t)))
        (when revert
        (when auto-revert-verbose
          (message "Reverting buffer `%s'." (buffer-name)))
!       (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)
!       ;; `preserve-modes' avoids changing the (minor) modes.  But we
!       ;; do want to reset the mode for VC, so we do it explicitly.
!       (vc-find-file-hook)
!       (if (eq revert 'vc)
!           (vc-mode-line buffer-file-name))))))
  
  (defun auto-revert-buffers ()
    "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode.
--- 288,315 ----
         (not (memq major-mode
                  global-auto-revert-ignore-modes)))))
  
  (defun auto-revert-handler ()
    "Revert current buffer, if appropriate.
  This is an internal function used by Auto-Revert Mode."
    (unless (buffer-modified-p)
      (let (revert)
!       (when (or (and (buffer-file-name)
!                    (file-readable-p (buffer-file-name))
!                    (not (verify-visited-file-modtime (current-buffer))))
!               (and (or auto-revert-mode global-auto-revert-non-file-buffers)
!                    revert-buffer-function
!                    (boundp 'buffer-stale-function)
!                    (functionp buffer-stale-function)
!                    (funcall buffer-stale-function t)))
!       (setq revert t))
        (when revert
        (when auto-revert-verbose
          (message "Reverting buffer `%s'." (buffer-name)))
!       (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes))
!       ;; `preserve-modes' avoids changing the (minor) modes.  But we
!       ;; do want to reset the mode for VC, so we do it manually.
!       (when (or revert auto-revert-check-vc-numbers)
!       (vc-find-file-hook)))))
  
  (defun auto-revert-buffers ()
    "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode.
============================================================




reply via email to

[Prev in Thread] Current Thread [Next in Thread]