X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/a0688443cc452106c01d7fb4474949a27c178322..746c9f1493536e60be1965ef669620908a553227:/lisp/vc-cvs.el diff --git a/lisp/vc-cvs.el b/lisp/vc-cvs.el index 798ee5c680..94fd3d0acd 100644 --- a/lisp/vc-cvs.el +++ b/lisp/vc-cvs.el @@ -1,11 +1,12 @@ ;;; vc-cvs.el --- non-resident support for CVS version-control -;; Copyright (C) 1995,98,99,2000,2001,2002 Free Software Foundation, Inc. +;; Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, +;; 2004, 2005, 2006 Free Software Foundation, Inc. ;; Author: FSF (see vc.el for full credits) ;; Maintainer: Andre Spiegel -;; $Id: vc-cvs.el,v 1.59 2003/05/08 20:44:50 monnier Exp $ +;; $Id$ ;; This file is part of GNU Emacs. @@ -21,8 +22,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: @@ -42,7 +43,7 @@ (repeat :tag "Argument List" :value ("") string)) - :version "21.4" + :version "22.1" :group 'vc) (defcustom vc-cvs-register-switches nil @@ -89,12 +90,12 @@ and past information to determine the current status of a file. The value can also be a regular expression or list of regular expressions to match against the host name of a repository; then VC only stays local for hosts that match it. Alternatively, the value -can be a list of regular expressions where the first element is the -symbol `except'; then VC always stays local except for hosts matched +can be a list of regular expressions where the first element is the +symbol `except'; then VC always stays local except for hosts matched by these regular expressions." :type '(choice (const :tag "Always stay local" t) (const :tag "Don't stay local" nil) - (list :format "\nExamine hostname and %v" :tag "Examine hostname ..." + (list :format "\nExamine hostname and %v" :tag "Examine hostname ..." (set :format "%v" :inline t (const :format "%t" :tag "don't" except)) (regexp :format " stay local,\n%t: %v" :tag "if it matches") (repeat :format "%v%i\n" :inline t (regexp :tag "or")))) @@ -106,7 +107,7 @@ by these regular expressions." Format is according to `format-time-string'. Only used if `vc-cvs-sticky-tag-display' is t." :type '(string) - :version "21.4" + :version "22.1" :group 'vc) (defcustom vc-cvs-sticky-tag-display t @@ -145,19 +146,13 @@ displayed. Date and time is displayed for sticky dates. See also variable `vc-cvs-sticky-date-format-string'." :type '(choice boolean function) - :version "21.4" + :version "22.1" :group 'vc) ;;; ;;; Internal variables ;;; -(defvar vc-cvs-local-month-numbers - '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) - ("May" . 5) ("Jun" . 6) ("Jul" . 7) ("Aug" . 8) - ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12)) - "Local association list of month numbers.") - ;;; ;;; State-querying functions @@ -191,11 +186,11 @@ See also variable `vc-cvs-sticky-date-format-string'." (defun vc-cvs-state (file) "CVS-specific version of `vc-state'." - (if (vc-cvs-stay-local-p file) + (if (vc-stay-local-p file) (let ((state (vc-file-getprop file 'vc-state))) ;; If we should stay local, use the heuristic but only if ;; we don't have a more precise state already available. - (if (memq state '(up-to-date edited)) + (if (memq state '(up-to-date edited nil)) (vc-cvs-state-heuristic file) state)) (with-temp-buffer @@ -217,7 +212,7 @@ See also variable `vc-cvs-sticky-date-format-string'." "Find the CVS state of all files in DIR." ;; if DIR is not under CVS control, don't do anything. (when (file-readable-p (expand-file-name "CVS/Entries" dir)) - (if (vc-cvs-stay-local-p dir) + (if (vc-stay-local-p dir) (vc-cvs-dir-state-heuristic dir) (let ((default-directory dir)) ;; Don't specify DIR in this command, the default-directory is @@ -241,16 +236,19 @@ See also variable `vc-cvs-sticky-date-format-string'." (defun vc-cvs-checkout-model (file) "CVS-specific version of `vc-checkout-model'." - (if (or (getenv "CVSREAD") - ;; If the file is not writable (despite CVSREAD being - ;; undefined), this is probably because the file is being - ;; "watched" by other developers. - ;; (If vc-mistrust-permissions was t, we actually shouldn't - ;; trust this, but there is no other way to learn this from CVS - ;; at the moment (version 1.9).) - (string-match "r-..-..-." (nth 8 (file-attributes file)))) + (if (getenv "CVSREAD") 'announce - 'implicit)) + (let ((attrib (file-attributes file))) + (if (and attrib ;; don't check further if FILE doesn't exist + ;; If the file is not writable (despite CVSREAD being + ;; undefined), this is probably because the file is being + ;; "watched" by other developers. + ;; (If vc-mistrust-permissions was t, we actually shouldn't + ;; trust this, but there is no other way to learn this from CVS + ;; at the moment (version 1.9).) + (string-match "r-..-..-." (nth 8 attrib))) + 'announce + 'implicit)))) (defun vc-cvs-mode-line-string (file) "Return string for placement into the modeline for FILE. @@ -286,6 +284,10 @@ COMMENT can be used to provide an initial description of FILE. `vc-register-switches' and `vc-cvs-register-switches' are passed to the CVS command (in that order)." + (when (and (not (vc-cvs-responsible-p file)) + (vc-cvs-could-register file)) + ;; Register the directory if needed. + (vc-cvs-register (directory-file-name (file-name-directory file)))) (apply 'vc-cvs-command nil 0 file "add" (and comment (string-match "[^\t\n ]" comment) @@ -299,9 +301,18 @@ the CVS command (in that order)." file (file-name-directory file))))) -(defalias 'vc-cvs-could-register 'vc-cvs-responsible-p +(defun vc-cvs-could-register (file) "Return non-nil if FILE could be registered in CVS. -This is only possible if CVS is responsible for FILE's directory.") +This is only possible if CVS is managing FILE's directory or one of +its parents." + (let ((dir file)) + (while (and (stringp dir) + (not (equal dir (setq dir (file-name-directory dir)))) + dir) + (setq dir (if (file-directory-p + (expand-file-name "CVS/Entries" dir)) + t (directory-file-name dir)))) + (eq dir t))) (defun vc-cvs-checkin (file rev comment) "CVS-specific version of `vc-backend-checkin'." @@ -428,26 +439,21 @@ REV is the revision to check out into WORKFILE." 'implicit))) "-w") "update" - ;; default for verbose checkout: clear the sticky tag so - ;; that the actual update will get the head of the trunk - (if (or (not rev) (eq rev t) (string= rev "")) - "-A" - (concat "-r" rev)) + (when rev + (unless (eq rev t) + ;; default for verbose checkout: clear the + ;; sticky tag so that the actual update will + ;; get the head of the trunk + (if (string= rev "") + "-A" + (concat "-r" rev)))) switches)))) (vc-mode-line file) (message "Checking out %s...done" filename))))) (defun vc-cvs-delete-file (file) - (vc-cvs-command nil 0 file "remove" "-f")) - -(defun vc-cvs-rename-file (old new) - ;; CVS doesn't know how to move files, so we just remove&add. - (condition-case nil - (add-name-to-file old new) - (error (rename-file old new))) - (vc-cvs-delete-file old) - (with-current-buffer (find-file-noselect new) - (vc-register))) + (vc-cvs-command nil 0 file "remove" "-f") + (vc-cvs-command nil 0 file "commit" "-mRemoved.")) (defun vc-cvs-revert (file &optional contents-done) "Revert FILE to the version it was based on." @@ -526,14 +532,14 @@ The changes are between FIRST-VERSION and SECOND-VERSION." ;;; History functions ;;; -(defun vc-cvs-print-log (file) +(defun vc-cvs-print-log (file &optional buffer) "Get change log associated with FILE." (vc-cvs-command - nil - (if (and (vc-cvs-stay-local-p file) (fboundp 'start-process)) 'async 0) + buffer + (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0) file "log")) -(defun vc-cvs-diff (file &optional oldvers newvers) +(defun vc-cvs-diff (file &optional oldvers newvers buffer) "Get a difference report using CVS between two versions of FILE." (if (string= (vc-workfile-version file) "0") ;; This file is added but not yet committed; there is no master file. @@ -542,13 +548,15 @@ The changes are between FIRST-VERSION and SECOND-VERSION." ;; We regard this as "changed". ;; Diff it against /dev/null. ;; Note: this is NOT a "cvs diff". - (apply 'vc-do-command "*vc-diff*" + (apply 'vc-do-command (or buffer "*vc-diff*") 1 "diff" file (append (vc-switches nil 'diff) '("/dev/null"))) ;; Even if it's empty, it's locally modified. 1) - (let* ((async (and (vc-cvs-stay-local-p file) (fboundp 'start-process))) - (status (apply 'vc-cvs-command "*vc-diff*" + (let* ((async (and (not vc-disable-async-diff) + (vc-stay-local-p file) + (fboundp 'start-process))) + (status (apply 'vc-cvs-command (or buffer "*vc-diff*") (if async 'async 1) file "diff" (and oldvers (concat "-r" oldvers)) @@ -560,7 +568,7 @@ The changes are between FIRST-VERSION and SECOND-VERSION." "Diff all files at and below DIR." (with-current-buffer "*vc-diff*" (setq default-directory dir) - (if (vc-cvs-stay-local-p dir) + (if (vc-stay-local-p dir) ;; local diff: do it filewise, and only for files that are modified (vc-file-tree-walk dir @@ -583,7 +591,11 @@ The changes are between FIRST-VERSION and SECOND-VERSION." (defun vc-cvs-annotate-command (file buffer &optional version) "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER. Optional arg VERSION is a version to annotate from." - (vc-cvs-command buffer 0 file "annotate" (if version (concat "-r" version)))) + (vc-cvs-command buffer 0 file "annotate" (if version (concat "-r" version))) + (with-current-buffer buffer + (goto-char (point-min)) + (re-search-forward "^[0-9]") + (delete-region (point-min) (1- (point))))) (defun vc-cvs-annotate-current-time () "Return the current time, based at midnight of the current day, and @@ -594,29 +606,44 @@ encoded as fractional days." (defun vc-cvs-annotate-time () "Return the time of the next annotation (as fraction of days) systime, or nil if there is none." - (let ((time-stamp - "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")) - (if (looking-at time-stamp) - (progn - (let* ((day (string-to-number (match-string 1))) - (month (cdr (assoc (match-string 2) - vc-cvs-local-month-numbers))) - (year-tmp (string-to-number (match-string 3))) - ;; Years 0..68 are 2000..2068. - ;; Years 69..99 are 1969..1999. - (year (+ (cond ((> 69 year-tmp) 2000) - ((> 100 year-tmp) 1900) - (t 0)) - year-tmp))) - (goto-char (match-end 0)) ; Position at end makes for nicer overlay result - (vc-annotate-convert-time (encode-time 0 0 0 day month year)))) - ;; If we did not look directly at an annotation, there might be - ;; some further down. This is the case if we are positioned at - ;; the very top of the buffer, for instance. - (if (re-search-forward time-stamp nil t) - (progn - (beginning-of-line nil) - (vc-cvs-annotate-time)))))) + (let* ((bol (point)) + (cache (get-text-property bol 'vc-cvs-annotate-time)) + buffer-read-only) + (cond + (cache) + ((looking-at + "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ") + (let ((day (string-to-number (match-string 1))) + (month (cdr (assq (intern (match-string 2)) + '((Jan . 1) (Feb . 2) (Mar . 3) + (Apr . 4) (May . 5) (Jun . 6) + (Jul . 7) (Aug . 8) (Sep . 9) + (Oct . 10) (Nov . 11) (Dec . 12))))) + (year (let ((tmp (string-to-number (match-string 3)))) + ;; Years 0..68 are 2000..2068. + ;; Years 69..99 are 1969..1999. + (+ (cond ((> 69 tmp) 2000) + ((> 100 tmp) 1900) + (t 0)) + tmp)))) + (put-text-property + bol (1+ bol) 'vc-cvs-annotate-time + (setq cache (cons + ;; Position at end makes for nicer overlay result. + (match-end 0) + (vc-annotate-convert-time + (encode-time 0 0 0 day month year)))))))) + (when cache + (goto-char (car cache)) ; fontify from here to eol + (cdr cache)))) ; days (float) + +(defun vc-cvs-annotate-extract-revision-at-line () + (save-excursion + (beginning-of-line) + (if (re-search-forward "^\\([0-9]+\\.[0-9]+\\(\\.[0-9]+\\)*\\) +(" + (line-end-position) t) + (match-string-no-properties 1) + nil))) ;;; ;;; Snapshot system @@ -670,7 +697,7 @@ If UPDATE is non-nil, then update (resynch) any affected buffers." ;;; Miscellaneous ;;; -(defalias 'vc-cvs-make-version-backups-p 'vc-cvs-stay-local-p +(defalias 'vc-cvs-make-version-backups-p 'vc-stay-local-p "Return non-nil if version backups should be made for FILE.") (defun vc-cvs-check-headers () @@ -695,56 +722,21 @@ and that it passes `vc-cvs-global-switches' to it before FLAGS." (append vc-cvs-global-switches flags)))) -(defun vc-cvs-stay-local-p (file) - "Return non-nil if VC should stay local when handling FILE. -See `vc-cvs-stay-local'." - (when vc-cvs-stay-local - (let* ((dirname (if (file-directory-p file) - (directory-file-name file) - (file-name-directory file))) - (prop - (or (vc-file-getprop dirname 'vc-cvs-stay-local-p) - (vc-file-setprop - dirname 'vc-cvs-stay-local-p - (let ((rootname (expand-file-name "CVS/Root" dirname))) - (when (file-readable-p rootname) - (with-temp-buffer - (let ((coding-system-for-read - (or file-name-coding-system - default-file-name-coding-system))) - (vc-insert-file rootname)) - (goto-char (point-min)) - (let* ((cvs-root-members - (vc-cvs-parse-root - (buffer-substring (point) - (line-end-position)))) - (hostname (nth 2 cvs-root-members))) - (if (not hostname) - 'no - (let* ((stay-local t) - (rx - (cond - ;; vc-cvs-stay-local: rx - ((stringp vc-cvs-stay-local) - vc-cvs-stay-local) - ;; vc-cvs-stay-local: '( [except] rx ... ) - ((consp vc-cvs-stay-local) - (mapconcat - 'identity - (if (not (eq (car vc-cvs-stay-local) - 'except)) - vc-cvs-stay-local - (setq stay-local nil) - (cdr vc-cvs-stay-local)) - "\\|"))))) - (if (not rx) - 'yes - (if (not (string-match rx hostname)) - (setq stay-local (not stay-local))) - (if stay-local - 'yes - 'no)))))))))))) - (if (eq prop 'yes) t nil)))) +(defalias 'vc-cvs-stay-local-p 'vc-stay-local-p) ;Back-compatibility. + +(defun vc-cvs-repository-hostname (dirname) + "Hostname of the CVS server associated to workarea DIRNAME." + (let ((rootname (expand-file-name "CVS/Root" dirname))) + (when (file-readable-p rootname) + (with-temp-buffer + (let ((coding-system-for-read + (or file-name-coding-system + default-file-name-coding-system))) + (vc-insert-file rootname)) + (goto-char (point-min)) + (nth 2 (vc-cvs-parse-root + (buffer-substring (point) + (line-end-position)))))))) (defun vc-cvs-parse-root (root) "Split CVS ROOT specification string into a list of fields. @@ -758,7 +750,7 @@ is `local'. The default METHOD for a CVS root of the form [USER@]HOSTNAME:/path/to/repository is `ext'. -For an empty string, nil is returned (illegal CVS root)." +For an empty string, nil is returned (invalid CVS root)." ;; Split CVS root into colon separated fields (0-4). ;; The `x:' makes sure, that leading colons are not lost; ;; `HOST:/PATH' is then different from `:METHOD:/PATH'. @@ -859,7 +851,7 @@ CVS/Entries should only be accessed through this function." (let ((coding-system-for-read (or file-name-coding-system default-file-name-coding-system))) (vc-insert-file (expand-file-name "CVS/Entries" dir)))) - + (defun vc-cvs-valid-symbolic-tag-name-p (tag) "Return non-nil if TAG is a valid symbolic tag name." ;; According to the CVS manual, a valid symbolic tag must start with @@ -949,22 +941,26 @@ is non-nil." "\\(.*\\)")) ;Sticky tag (vc-file-setprop file 'vc-workfile-version (match-string 1)) (vc-file-setprop file 'vc-cvs-sticky-tag - (vc-cvs-parse-sticky-tag (match-string 4) (match-string 5))) - ;; compare checkout time and modification time - (let* ((mtime (nth 5 (file-attributes file))) - (system-time-locale "C") - (mtstr (format-time-string "%c" mtime 'utc))) - ;; Solaris sometimes uses "Wed Sep 05" instead of "Wed Sep 5". - ;; See "grep '[^a-z_]ctime' cvs/src/*.c" for reference. - (if (= (aref mtstr 8) ?0) - (setq mtstr (concat (substring mtstr 0 8) " " (substring mtstr 9)))) - (cond ((equal mtstr (match-string 2)) - (vc-file-setprop file 'vc-checkout-time mtime) - (if set-state (vc-file-setprop file 'vc-state 'up-to-date))) - (t - (vc-file-setprop file 'vc-checkout-time 0) - (if set-state (vc-file-setprop file 'vc-state 'edited)))))))) + (vc-cvs-parse-sticky-tag (match-string 4) + (match-string 5))) + ;; Compare checkout time and modification time. + ;; This is intentionally different from the algorithm that CVS uses + ;; (which is based on textual comparison), because there can be problems + ;; generating a time string that looks exactly like the one from CVS. + (let ((mtime (nth 5 (file-attributes file)))) + (require 'parse-time) + (let ((parsed-time + (parse-time-string (concat (match-string 2) " +0000")))) + (cond ((and (not (string-match "\\+" (match-string 2))) + (car parsed-time) + (equal mtime (apply 'encode-time parsed-time))) + (vc-file-setprop file 'vc-checkout-time mtime) + (if set-state (vc-file-setprop file 'vc-state 'up-to-date))) + (t + (vc-file-setprop file 'vc-checkout-time 0) + (if set-state (vc-file-setprop file 'vc-state 'edited))))))))) (provide 'vc-cvs) +;;; arch-tag: 60e1402a-aa53-4607-927a-cf74f144b432 ;;; vc-cvs.el ends here