bug-gnu-emacs
[Top][All Lists]
Advanced

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

[patch] 21.3 autorevert.el -- Added VC (cvs) buffer support


From: Jari Aalto+mail.emacs
Subject: [patch] 21.3 autorevert.el -- Added VC (cvs) buffer support
Date: Sun, 25 Jan 2004 16:55:09 +0200

    autorevert.el does not notice changes in VC buffer, where the
    changes are made out of current Emacs. Usually the modeline does
    not pick up the current version changed in disk. See long comment
    in the patch. At this point CVS is addressed, I'm not sure how to
    do it correctly with RCS yet.

    This patch supposes, that the two "dired" support patches that I
    sent earlier, have been applied.

    Jari


2004-01-25 Sun  Jari Aalto  <address@hidden>

        * autorevert.el (top level): Byte compiler fixes.
        defvar `dired-directory' added, autoload `dired-get-filename' added.
        (auto-revert-dired-file-list): added missing variable `file' to `let'.
        (top level): Added autoloads for Dired and VC.
        (auto-revert-vc-cvs-file-version): New.
        (auto-revert-vc-buffer-p): New.
        (auto-revert-handler-vc): New.
        (auto-revert-handler): Added support for VC controlled files.
        (auto-revert-buffer-p): Added support for VC controlled files.


Index: autorevert.el
===================================================================
RCS file: 
/cygdrive/h/data/version-control/cvsroot/emacs/gnu-emacs/lisp213/autorevert.el,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -IId: -b -w -u -r1.4 -r1.5
--- autorevert.el       25 Jan 2004 13:08:09 -0000      1.4
+++ autorevert.el       25 Jan 2004 14:40:42 -0000      1.5
@@ -71,9 +71,12 @@
 
 (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))
 
 
@@ -323,10 +326,13 @@
 
 (defun auto-revert-buffer-p ()
   "Check if current buffer should be reverted."
-  ;;  Always include dired buffers to list. It would be too expensive
+  ;;  - Always include dired buffers to list. It would be too expensive
   ;;  to test the "revert" status here each time timer launches.
+  ;;  - Same for VC buffers
   (or (eq major-mode 'dired-mode)
       (and (not (buffer-modified-p))
+           (auto-revert-vc-buffer-p))
+      (and (not (buffer-modified-p))
            (if (buffer-file-name)
                (and (file-readable-p (buffer-file-name))
                     (not (verify-visited-file-modtime (current-buffer))))
@@ -335,23 +341,81 @@
                            global-auto-revert-non-file-buffers)
                       auto-revert-mode))))))
 
+(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."
-  (let (done)
+  (let (revert)
     (cond
      ((eq major-mode 'dired-mode)
       ;;  Dired includes revert-buffer-function
       (when (and revert-buffer-function
                  (auto-revert-dired-changed-p))
-        (setq done t)
-        (revert-buffer t t t)))
+        (setq revert t)))
+     ((auto-revert-vc-buffer-p)
+      (when (auto-revert-handler-vc)
+        (setq revert 'vc)))
      ((or (buffer-file-name)
           revert-buffer-function)
-      (setq done t)
-      (revert-buffer t t t)))
-    (if (and done
-             auto-revert-verbose)
-        (message "Reverting buffer `%s'." (buffer-name)))))
+      (setq revert t)))
+    (when revert
+      (revert-buffer t t t)
+      (if (eq revert 'vc)
+          (vc-mode-line buffer-file-name))
+      (if auto-revert-verbose
+          (message "Reverting buffer `%s'." (buffer-name))))))
 
 (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]