]> code.delx.au - gnu-emacs/blobdiff - lisp/vc-arch.el
(byte-compile-dynamic)
[gnu-emacs] / lisp / vc-arch.el
index 042b4bbbdca7e878df1391fba309192659a171dc..a0fc8af83456a0ff2513f0230c2e2665fe132b4d 100644 (file)
@@ -1,6 +1,6 @@
 ;;; vc-arch.el --- VC backend for the Arch version-control system
 
-;; Copyright (C) 1995,98,99,2000,01,02,03,2004  Free Software Foundation, Inc.
+;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
 
 ;; Author:      FSF (see vc.el for full credits)
 ;; Maintainer:  Stefan Monnier <monnier@gnu.org>
@@ -19,8 +19,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -55,7 +55,7 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'vc))
+(eval-when-compile (require 'vc) (require 'cl))
 
 ;;;
 ;;; Customization options
 (put 'Arch 'vc-functions nil)
 
 ;;;###autoload (defun vc-arch-registered (file)
-;;;###autoload   (let ((dir file))
-;;;###autoload     (while (and (stringp dir)
-;;;###autoload                 (not (equal
-;;;###autoload                       dir (setq dir (file-name-directory dir))))
-;;;###autoload                 dir)
-;;;###autoload       (setq dir (if (file-directory-p
-;;;###autoload                      (expand-file-name "{arch}" dir))
-;;;###autoload                     t (directory-file-name dir))))
-;;;###autoload     (if (eq dir t)
-;;;###autoload          (progn
-;;;###autoload           (load "vc-arch")
-;;;###autoload           (vc-arch-registered file)))))
+;;;###autoload   (if (vc-find-root file "{arch}/=tagging-method")
+;;;###autoload       (progn
+;;;###autoload         (load "vc-arch")
+;;;###autoload         (vc-arch-registered file))))
 
 (defun vc-arch-add-tagline ()
   "Add an `arch-tag' to the end of the current file."
@@ -186,22 +178,19 @@ Only the value `maybe' can be trusted :-(."
   "Return the root directory of a Arch project, if any."
   (or (vc-file-getprop file 'arch-root)
       (vc-file-setprop
-       file 'arch-root
-       (let ((root nil))
-        (while (not (or root
-                        (equal file (setq file (file-name-directory file)))
-                        (null file)))
-          (if (file-directory-p (expand-file-name "{arch}" file))
-              (setq root file)
-            (setq file (directory-file-name file))))
-        root))))
+       ;; Check the =tagging-method, in case someone naively manually
+       ;; creates a {arch} directory somewhere.
+       file 'arch-root (vc-find-root file "{arch}/=tagging-method"))))
 
 (defun vc-arch-register (file &optional rev comment)
-  (if rev (error "Explicit initial revision not supported for Arch."))
+  (if rev (error "Explicit initial revision not supported for Arch"))
   (let ((tagmet (vc-arch-tagging-method file)))
     (if (and (memq tagmet '(tagline implicit)) comment-start)
        (with-current-buffer (find-file-noselect file)
-         (vc-arch-add-tagline))
+         (if (buffer-modified-p)
+             (error "Save %s first" (buffer-name)))
+         (vc-arch-add-tagline)
+         (save-buffer))
       (vc-arch-command nil 0 file "add"))))
 
 (defun vc-arch-registered (file)
@@ -248,9 +237,13 @@ Return non-nil if FILE is unchanged."
        (with-current-buffer (find-file-noselect sigfile)
          (goto-char (point-min))
          (while (and (search-forward id nil 'move)
-                     (progn (goto-char (- (match-beginning 0) 2))
-                            ;; Ignore E_ entries used for foo.id files.
-                            (or (not (bolp)) (looking-at "E_")))))
+                     (save-excursion
+                       (goto-char (- (match-beginning 0) 2))
+                       ;; For `names', the lines start with `?./foo/bar'.
+                       ;; For others there's 2 chars before the ./foo/bar.
+                       (or (not (or (bolp) (looking-at "\n?")))
+                           ;; Ignore E_ entries used for foo.id files.
+                           (looking-at "E_")))))
          (if (eobp)
              ;; ID not found.
              (if (equal (file-name-nondirectory sigfile)
@@ -267,16 +260,16 @@ Return non-nil if FILE is unchanged."
                ;; Buh?  Unexpected format.
                'edited
              (let ((ats (file-attributes file)))
-               (if (and (= (nth 7 ats) (string-to-number (match-string 2)))
+               (if (and (eq (nth 7 ats) (string-to-number (match-string 2)))
                         (equal (format-time-string "%s" (nth 5 ats))
                                (match-string 1)))
                    'up-to-date
                  'edited)))))))))
-           
+
 (defun vc-arch-workfile-version (file)
   (let* ((root (expand-file-name "{arch}" (vc-arch-root file)))
         (defbranch (vc-arch-default-version file)))
-    (when (and defbranch (string-match "\\`\\(.+@[^/\n]+\\)/\\(\\(\\(.*\\)--.*\\)--.*\\)\\'" defbranch))
+    (when (and defbranch (string-match "\\`\\(.+@[^/\n]+\\)/\\(\\(\\(.*?\\)\\(?:--.*\\)?\\)--.*\\)\\'" defbranch))
       (let* ((archive (match-string 1 defbranch))
             (category (match-string 4 defbranch))
             (branch (match-string 3 defbranch))
@@ -289,8 +282,8 @@ Return non-nil if FILE is unchanged."
        (setq logdir (expand-file-name version logdir))
        (setq logdir (expand-file-name archive logdir))
        (setq logdir (expand-file-name "patch-log" logdir))
-       ;; Revision names go: base-0, patch-N, version-0, versionfix-N.
-       (dolist (file (directory-files logdir))
+       (dolist (file (if (file-directory-p logdir) (directory-files logdir)))
+         ;; Revision names go: base-0, patch-N, version-0, versionfix-M.
          (when (and (eq (aref file 0) ?v) (not sealed))
            (setq sealed t rev-nb 0))
          (if (and (string-match "-\\([0-9]+\\)\\'" file)
@@ -298,13 +291,16 @@ Return non-nil if FILE is unchanged."
                   (or (not sealed) (eq (aref file 0) ?v))
                   (>= tmp rev-nb))
              (setq rev-nb tmp rev file)))
-       (concat defbranch "--" rev)))))
+       ;; Use "none-000" if the tree hasn't yet been committed on the
+       ;; default branch.  We'll then get "Arch:000[branch]" on the mode-line.
+       (concat defbranch "--" (or rev "none-000"))))))
 
 
 (defcustom vc-arch-mode-line-rewrite
   '(("\\`.*--\\(.*--.*\\)--\\(v?\\).*-\\([0-9]+\\)\\'" . "\\2\\3[\\1]"))
   "Rewrite rules to shorten Arch's revision names on the mode-line."
-  :type '(repeat (cons regexp string)))
+  :type '(repeat (cons regexp string))
+  :group 'vc)
 
 (defun vc-arch-mode-line-string (file)
   "Return string for placement in modeline by `vc-mode-line' for FILE."
@@ -328,14 +324,13 @@ Return non-nil if FILE is unchanged."
           (looking-at "Conflicts occured, diff3 conflict markers left in file\\.")))))
 
 (defun vc-arch-delete-rej-if-obsolete ()
-  "For use in `write-file-functions'."
-  (let ((rej (concat buffer-file-name ".rej")))
-    (when (and buffer-file-name (vc-arch-diff3-rej-p rej))
-      (if (not (re-search-forward "^>>>>>>> " nil t))
-         ;; The .rej file is obsolete.
-         (condition-case nil (delete-file rej) (error nil)))))
-  ;; This did not save the buffer.
-  nil)
+  "For use in `after-save-hook'."
+  (save-excursion
+    (let ((rej (concat buffer-file-name ".rej")))
+      (when (and buffer-file-name (vc-arch-diff3-rej-p rej))
+       (if (not (re-search-forward "^<<<<<<< " nil t))
+           ;; The .rej file is obsolete.
+           (condition-case nil (delete-file rej) (error nil)))))))
 
 (defun vc-arch-find-file-hook ()
   (let ((rej (concat buffer-file-name ".rej")))
@@ -343,11 +338,11 @@ Return non-nil if FILE is unchanged."
       (if (vc-arch-diff3-rej-p rej)
          (save-excursion
            (goto-char (point-min))
-           (if (not (re-search-forward "^>>>>>>> " nil t))
+           (if (not (re-search-forward "^<<<<<<< " nil t))
                ;; The .rej file is obsolete.
                (condition-case nil (delete-file rej) (error nil))
              (smerge-mode 1)
-             (add-hook 'write-file-functions
+             (add-hook 'after-save-hook
                        'vc-arch-delete-rej-if-obsolete nil t)
              (message "There are unresolved conflicts in this file")))
        (message "There are unresolved conflicts in %s"
@@ -361,7 +356,7 @@ Return non-nil if FILE is unchanged."
 (defun vc-arch-checkout-model (file) 'implicit)
 
 (defun vc-arch-checkin (file rev comment)
-  (if rev (error "Committing to a specific revision is unsupported."))
+  (if rev (error "Committing to a specific revision is unsupported"))
   (let ((summary (file-relative-name file (vc-arch-root file))))
     ;; Extract a summary from the comment.
     (when (or (string-match "\\`Summary:[ \t]*\\(.*[^ \t\n]\\)\\([ \t]*\n\\)*" comment)
@@ -371,7 +366,7 @@ Return non-nil if FILE is unchanged."
     (vc-arch-command nil 0 file "commit" "-s" summary "-L" comment "--"
                     (vc-switches 'Arch 'checkin))))
 
-(defun vc-arch-diff (file &optional oldvers newvers)
+(defun vc-arch-diff (file &optional oldvers newvers buffer)
   "Get a difference report using Arch between two versions of FILE."
   (if (and newvers
           (vc-up-to-date-p file)
@@ -380,13 +375,13 @@ Return non-nil if FILE is unchanged."
       ;; so we can diff with the current file.
       (setq newvers nil))
   (if newvers
-      (error "Diffing specific revisions not implemented.")
-    (let* ((async (fboundp 'start-process))
+      (error "Diffing specific revisions not implemented")
+    (let* ((async (and (not vc-disable-async-diff) (fboundp 'start-process)))
           ;; Run the command from the root dir.
           (default-directory (vc-arch-root file))
           (status
            (vc-arch-command
-            "*vc-diff*"
+            (or buffer "*vc-diff*")
             (if async 'async 1)
             nil "file-diffs"
             ;; Arch does not support the typical flags.
@@ -403,11 +398,15 @@ Return non-nil if FILE is unchanged."
 (defun vc-arch-rename-file (old new)
   (vc-arch-command nil 0 new "mv" (file-relative-name old)))
 
+(defalias 'vc-arch-responsible-p 'vc-arch-root)
+
 (defun vc-arch-command (buffer okstatus file &rest flags)
   "A wrapper around `vc-do-command' for use in vc-arch.el."
   (apply 'vc-do-command buffer okstatus vc-arch-command file flags))
 
+(defun vc-arch-init-version () nil)
+
 (provide 'vc-arch)
 
-;;; arch-tag: a35c7c1c-5237-429d-88ef-3d718fd2e704
+;; arch-tag: a35c7c1c-5237-429d-88ef-3d718fd2e704
 ;;; vc-arch.el ends here