unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Luc Teirlinck <teirllm@dms.auburn.edu>
Cc: emacs-devel@gnu.org
Subject: Re: autorevert and vc
Date: Mon, 29 Mar 2004 20:27:51 -0600 (CST)	[thread overview]
Message-ID: <200403300227.i2U2Rp111731@raven.dms.auburn.edu> (raw)
In-Reply-To: <m1d66wgutj.fsf-monnier+emacs@empanada.iro.umontreal.ca> (message from Stefan Monnier on 28 Mar 2004 23:24:03 -0500)

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.
============================================================

  parent reply	other threads:[~2004-03-30  2:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-29  3:52 autorevert and vc Luc Teirlinck
2004-03-29  4:24 ` Stefan Monnier
2004-03-29  4:43   ` Luc Teirlinck
2004-03-30  2:27   ` Luc Teirlinck [this message]
2004-03-30 19:56     ` Stefan Monnier
2004-04-01 10:27     ` Jari Aalto
2004-04-01 16:46       ` Luc Teirlinck
2004-03-30 15:17   ` Luc Teirlinck
2004-03-30 20:51     ` Andre Spiegel
2004-03-31  0:24       ` Stefan Monnier
2004-03-31  2:02         ` Luc Teirlinck
2004-03-31  2:15           ` Luc Teirlinck
2004-03-31  7:19           ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200403300227.i2U2Rp111731@raven.dms.auburn.edu \
    --to=teirllm@dms.auburn.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).