annotate lisp/packages/vc-hooks.el @ 153:25f70ba0133c r20-3b3

Import from CVS: tag r20-3b3
author cvs
date Mon, 13 Aug 2007 09:38:25 +0200
parents 59463afc5666
children 6075d714658b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; vc-hooks.el --- resident support for version-control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
6 ;; Maintainer: Andre Spiegel <spiegel@inf.fu-berlin.de>
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
7 ;; XEmacs conversion: Steve Baur <steve@altair.xemacs.org>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
9 ;; This file is part of GNU Emacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
19 ;; GNU General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
24 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
28 ;; This is the always-loaded portion of VC.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
29 ;; It takes care VC-related activities that are done when you visit a file,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
30 ;; so that vc.el itself is loaded only when you use a VC command.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; See the commentary of vc.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
35 ;; Customization Variables (the rest is in vc.el)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
36
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
37 (defvar vc-default-back-end nil
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
38 "*Back-end actually used by this interface; may be SCCS or RCS.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
39 The value is only computed when needed to avoid an expensive search.")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
40
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
41 (defvar vc-handle-cvs t
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
42 "*If non-nil, use VC for files managed with CVS.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
43 If it is nil, don't use VC for those files.")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
44
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
45 (defvar vc-rcsdiff-knows-brief nil
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
46 "*Indicates whether rcsdiff understands the --brief option.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
47 The value is either `yes', `no', or nil. If it is nil, VC tries
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
48 to use --brief and sets this variable to remember whether it worked.")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
49
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
50 (defvar vc-path
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
51 (if (file-directory-p "/usr/sccs")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
52 '("/usr/sccs")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
53 nil)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
54 "*List of extra directories to search for version control commands.")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
55
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defvar vc-master-templates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 '(("%sRCS/%s,v" . RCS) ("%s%s,v" . RCS) ("%sRCS/%s" . RCS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ("%sSCCS/s.%s" . SCCS) ("%ss.%s". SCCS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 vc-find-cvs-master)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "*Where to look for version-control master files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 The first pair corresponding to a given back end is used as a template
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 when creating new masters.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (defvar vc-make-backup-files nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 "*If non-nil, backups of registered files are made as with other files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 If nil (the default), files covered by version control don't get backups.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
68 (defvar vc-follow-symlinks 'ask
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
69 "*Indicates what to do if you visit a symbolic link to a file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
70 that is under version control. Editing such a file through the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
71 link bypasses the version control system, which is dangerous and
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
72 probably not what you want.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
73 If this variable is t, VC follows the link and visits the real file,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
74 telling you about it in the echo area. If it is `ask', VC asks for
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
75 confirmation whether it should follow the link. If nil, the link is
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
76 visited and a warning displayed.")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
77
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (defvar vc-display-status t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 "*If non-nil, display revision number and lock status in modeline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 Otherwise, not displayed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
82 (defvar vc-consult-headers t
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
83 "*If non-nil, identify work files by searching for version headers.")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
84
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
85 (defvar vc-keep-workfiles t
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
86 "*If non-nil, don't delete working files after registering changes.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
87 If the back-end is CVS, workfiles are always kept, regardless of the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
88 value of this flag.")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
89
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
90 (defvar vc-mistrust-permissions nil
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
91 "*If non-nil, don't assume that permissions and ownership track
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
92 version-control status. If nil, do rely on the permissions.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
93 See also variable `vc-consult-headers'.")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
94
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
95 (defun vc-mistrust-permissions (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
96 ;; Access function to the above.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
97 (or (eq vc-mistrust-permissions 't)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
98 (and vc-mistrust-permissions
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
99 (funcall vc-mistrust-permissions
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
100 (vc-backend-subdirectory-name file)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
101
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; Tell Emacs about this new kind of minor mode
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
103 ;;(if (not (assoc 'vc-mode minor-mode-alist))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
104 ;; (setq minor-mode-alist (cons '(vc-mode vc-mode)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
105 ;; minor-mode-alist)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
106
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
107 ;; XEmacs:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (add-minor-mode 'vc-mode 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
110 (defvar vc-mode nil) ; used for modeline flag
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
111 ;; End XEmacs addition.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
112
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (make-variable-buffer-local 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (put 'vc-mode 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; We need a notion of per-file properties because the version
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
117 ;; control state of a file is expensive to derive --- we compute
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
118 ;; them when the file is initially found, keep them up to date
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
119 ;; during any subsequent VC operations, and forget them when
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
120 ;; the buffer is killed.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (defmacro vc-error-occurred (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
125 (defvar vc-file-prop-obarray [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 "Obarray for per-file properties.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
128 (defvar vc-buffer-backend t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
129 (make-variable-buffer-local 'vc-buffer-backend)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
130
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (defun vc-file-setprop (file property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;; set per-file property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (put (intern file vc-file-prop-obarray) property value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defun vc-file-getprop (file property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; get per-file property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (get (intern file vc-file-prop-obarray) property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
139 (defun vc-file-clearprops (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
140 ;; clear all properties of a given file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
141 (setplist (intern file vc-file-prop-obarray) nil))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
142
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
143 ;;; Functions that determine property values, by examining the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
144 ;;; working file, the master file, or log program output
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
145
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
146 (defun vc-match-substring (bn)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
147 (buffer-substring (match-beginning bn) (match-end bn)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
148
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
149 (defun vc-lock-file (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
150 ;; Generate lock file name corresponding to FILE
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
151 (let ((master (vc-name file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
152 (and
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
153 master
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
154 (string-match "\\(.*/\\)s\\.\\(.*\\)" master)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
155 (concat
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
156 (substring master (match-beginning 1) (match-end 1))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
157 "p."
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
158 (substring master (match-beginning 2) (match-end 2))))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
159
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
160 (defun vc-parse-buffer (patterns &optional file properties)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
161 ;; Use PATTERNS to parse information out of the current buffer.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
162 ;; Each element of PATTERNS is a list of 2 to 3 elements. The first element
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
163 ;; is the pattern to be matched, and the second (an integer) is the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
164 ;; number of the subexpression that should be returned. If there's
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
165 ;; a third element (also the number of a subexpression), that
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
166 ;; subexpression is assumed to be a date field and we want the most
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
167 ;; recent entry matching the template.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
168 ;; If FILE and PROPERTIES are given, the latter must be a list of
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
169 ;; properties of the same length as PATTERNS; each property is assigned
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
170 ;; the corresponding value.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
171 (mapcar (function (lambda (p)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
172 (goto-char (point-min))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
173 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
174 ((eq (length p) 2) ;; search for first entry
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
175 (let ((value nil))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
176 (if (re-search-forward (car p) nil t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
177 (setq value (vc-match-substring (elt p 1))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
178 (if file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
179 (progn (vc-file-setprop file (car properties) value)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
180 (setq properties (cdr properties))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
181 value))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
182 ((eq (length p) 3) ;; search for latest entry
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
183 (let ((latest-date "") (latest-val))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
184 (while (re-search-forward (car p) nil t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
185 (let ((date (vc-match-substring (elt p 2))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
186 (if (string< latest-date date)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
187 (progn
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
188 (setq latest-date date)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
189 (setq latest-val
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
190 (vc-match-substring (elt p 1)))))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
191 (if file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
192 (progn (vc-file-setprop file (car properties) latest-val)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
193 (setq properties (cdr properties))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
194 latest-val)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
195 patterns)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
196 )
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
197
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
198 (defun vc-insert-file (file &optional limit blocksize)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
199 ;; Insert the contents of FILE into the current buffer.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
200 ;; Optional argument LIMIT is a regexp. If present,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
201 ;; the file is inserted in chunks of size BLOCKSIZE
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
202 ;; (default 8 kByte), until the first occurrence of
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
203 ;; LIMIT is found. The function returns nil if FILE
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
204 ;; doesn't exist.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
205 (erase-buffer)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
206 (cond ((file-exists-p file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
207 (cond (limit
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
208 (if (not blocksize) (setq blocksize 8192))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
209 (let (found s)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
210 (while (not found)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
211 (setq s (buffer-size))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
212 (goto-char (1+ s))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
213 (setq found
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
214 (or (zerop (car (cdr
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
215 (insert-file-contents file nil s
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
216 (+ s blocksize)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
217 (progn (beginning-of-line)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
218 (re-search-forward limit nil t)))))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
219 (t (insert-file-contents file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
220 (set-buffer-modified-p nil)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
221 (auto-save-mode nil)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
222 t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
223 (t nil)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
224
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
225 (defun vc-parse-locks (file locks)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
226 ;; Parse RCS or SCCS locks.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
227 ;; The result is a list of the form ((VERSION USER) (VERSION USER) ...),
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
228 ;; which is returned and stored into the property `vc-master-locks'.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
229 (if (not locks)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
230 (vc-file-setprop file 'vc-master-locks 'none)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
231 (let ((found t) (index 0) master-locks version user)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
232 (cond ((eq (vc-backend file) 'SCCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
233 (while (string-match "^\\([0-9.]+\\) [0-9.]+ \\([^ ]+\\) .*\n?"
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
234 locks index)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
235 (setq version (substring locks
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
236 (match-beginning 1) (match-end 1)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
237 (setq user (substring locks
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
238 (match-beginning 2) (match-end 2)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
239 (setq master-locks (append master-locks
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
240 (list (cons version user))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
241 (setq index (match-end 0))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
242 ((eq (vc-backend file) 'RCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
243 (while (string-match "[ \t\n]*\\([^:]+\\):\\([0-9.]+\\)"
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
244 locks index)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
245 (setq version (substring locks
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
246 (match-beginning 2) (match-end 2)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
247 (setq user (substring locks
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
248 (match-beginning 1) (match-end 1)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
249 (setq master-locks (append master-locks
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
250 (list (cons version user))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
251 (setq index (match-end 0)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
252 (if (string-match ";[ \t\n]+strict;" locks index)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
253 (vc-file-setprop file 'vc-checkout-model 'manual)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
254 (vc-file-setprop file 'vc-checkout-model 'implicit))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
255 (vc-file-setprop file 'vc-master-locks (or master-locks 'none)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
256
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
257 (defun vc-simple-command (okstatus command file &rest args)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
258 ;; Simple version of vc-do-command, for use in vc-hooks only.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
259 ;; Don't switch to the *vc-info* buffer before running the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
260 ;; command, because that would change its default directory
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
261 (save-excursion (set-buffer (get-buffer-create "*vc-info*"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
262 (erase-buffer))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
263 (let ((exec-path (append vc-path exec-path)) exec-status
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
264 ;; Add vc-path to PATH for the execution of this command.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
265 (process-environment
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
266 (cons (concat "PATH=" (getenv "PATH")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
267 path-separator
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
268 (mapconcat 'identity vc-path path-separator))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
269 process-environment)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
270 (setq exec-status
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
271 (apply 'call-process command nil "*vc-info*" nil
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
272 (append args (list file))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
273 (cond ((> exec-status okstatus)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
274 (switch-to-buffer (get-file-buffer file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
275 (shrink-window-if-larger-than-buffer
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
276 (display-buffer "*vc-info*"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
277 (error "Couldn't find version control information")))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
278 exec-status))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
279
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
280 (defun vc-fetch-master-properties (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
281 ;; Fetch those properties of FILE that are stored in the master file.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
282 ;; For an RCS file, we don't get vc-latest-version vc-your-latest-version
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
283 ;; here because that is slow.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
284 ;; That gets done if/when the functions vc-latest-version
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
285 ;; and vc-your-latest-version get called.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
286 (save-excursion
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
287 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
288 ((eq (vc-backend file) 'SCCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
289 (set-buffer (get-buffer-create "*vc-info*"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
290 (if (vc-insert-file (vc-lock-file file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
291 (vc-parse-locks file (buffer-string))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
292 (vc-file-setprop file 'vc-master-locks 'none))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
293 (vc-insert-file (vc-name file) "^\001e")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
294 (vc-parse-buffer
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
295 (list '("^\001d D \\([^ ]+\\)" 1)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
296 (list (concat "^\001d D \\([^ ]+\\) .* "
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
297 (regexp-quote (vc-user-login-name)) " ") 1))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
298 file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
299 '(vc-latest-version vc-your-latest-version)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
300
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
301 ((eq (vc-backend file) 'RCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
302 (set-buffer (get-buffer-create "*vc-info*"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
303 (vc-insert-file (vc-name file) "^[0-9]")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
304 (vc-parse-buffer
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
305 (list '("^head[ \t\n]+\\([^;]+\\);" 1)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
306 '("^branch[ \t\n]+\\([^;]+\\);" 1)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
307 '("^locks[ \t\n]*\\([^;]*;\\([ \t\n]*strict;\\)?\\)" 1))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
308 file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
309 '(vc-head-version
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
310 vc-default-branch
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
311 vc-master-locks))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
312 ;; determine vc-master-workfile-version: it is either the head
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
313 ;; of the trunk, the head of the default branch, or the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
314 ;; "default branch" itself, if that is a full revision number.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
315 (let ((default-branch (vc-file-getprop file 'vc-default-branch)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
316 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
317 ;; no default branch
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
318 ((or (not default-branch) (string= "" default-branch))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
319 (vc-file-setprop file 'vc-master-workfile-version
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
320 (vc-file-getprop file 'vc-head-version)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
321 ;; default branch is actually a revision
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
322 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
323 default-branch)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
324 (vc-file-setprop file 'vc-master-workfile-version default-branch))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
325 ;; else, search for the head of the default branch
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
326 (t (vc-insert-file (vc-name file) "^desc")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
327 (vc-parse-buffer (list (list
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
328 (concat "^\\("
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
329 (regexp-quote default-branch)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
330 "\\.[0-9]+\\)\ndate[ \t]+\\([0-9.]+\\);") 1 2))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
331 file '(vc-master-workfile-version)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
332 ;; translate the locks
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
333 (vc-parse-locks file (vc-file-getprop file 'vc-master-locks)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
334
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
335 ((eq (vc-backend file) 'CVS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
336 (save-excursion
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
337 ;; Call "cvs status" in the right directory, passing only the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
338 ;; nondirectory part of the file name -- otherwise CVS might
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
339 ;; silently give a wrong result.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
340 (let ((default-directory (file-name-directory file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
341 (vc-simple-command 0 "cvs" (file-name-nondirectory file) "status"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
342 (set-buffer (get-buffer "*vc-info*"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
343 (vc-parse-buffer
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
344 ;; CVS 1.3 says "RCS Version:", other releases "RCS Revision:",
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
345 ;; and CVS 1.4a1 says "Repository revision:".
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
346 '(("\\(RCS Version\\|RCS Revision\\|Repository revision\\):[\t ]+\\([0-9.]+\\)" 2)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
347 ("^File: [^ \t]+[ \t]+Status: \\(.*\\)" 1))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
348 file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
349 '(vc-latest-version vc-cvs-status))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
350 ;; Translate those status values that we understand into symbols.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
351 ;; Any other value is converted to nil.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
352 (let ((status (vc-file-getprop file 'vc-cvs-status)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
353 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
354 ((string-match "Up-to-date" status)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
355 (vc-file-setprop file 'vc-cvs-status 'up-to-date)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
356 (vc-file-setprop file 'vc-checkout-time
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
357 (nth 5 (file-attributes file))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
358 ((vc-file-setprop file 'vc-cvs-status
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
359 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
360 ((string-match "Locally Modified" status) 'locally-modified)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
361 ((string-match "Needs Merge" status) 'needs-merge)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
362 ((string-match "Needs \\(Checkout\\|Patch\\)" status)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
363 'needs-checkout)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
364 ((string-match "Unresolved Conflict" status) 'unresolved-conflict)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
365 ((string-match "Locally Added" status) 'locally-added)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
366 (t 'unknown)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
367 ))))))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
368 (if (get-buffer "*vc-info*")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
369 (kill-buffer (get-buffer "*vc-info*")))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
370
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
371 ;;; Functions that determine property values, by examining the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
372 ;;; working file, the master file, or log program output
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
373
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
374 (defun vc-consult-rcs-headers (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
375 ;; Search for RCS headers in FILE, and set properties
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
376 ;; accordingly. This function can be disabled by setting
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
377 ;; vc-consult-headers to nil.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
378 ;; Returns: nil if no headers were found
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
379 ;; (or if the feature is disabled,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
380 ;; or if there is currently no buffer
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
381 ;; visiting FILE)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
382 ;; 'rev if a workfile revision was found
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
383 ;; 'rev-and-lock if revision and lock info was found
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
384 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
385 ((or (not vc-consult-headers)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
386 (not (get-file-buffer file))) nil)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
387 ((let (status version locking-user)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
388 (save-excursion
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
389 (set-buffer (get-file-buffer file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
390 (goto-char (point-min))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
391 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
392 ;; search for $Id or $Header
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
393 ;; -------------------------
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
394 ((or (and (search-forward "$Id: " nil t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
395 (looking-at "[^ ]+ \\([0-9.]+\\) "))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
396 (and (progn (goto-char (point-min))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
397 (search-forward "$Header: " nil t))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
398 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
399 (goto-char (match-end 0))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
400 ;; if found, store the revision number ...
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
401 (setq version (buffer-substring-no-properties (match-beginning 1)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
402 (match-end 1)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
403 ;; ... and check for the locking state
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
404 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
405 ((looking-at
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
406 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
407 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
408 "[^ ]+ [^ ]+ ")) ; author & state
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
409 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
410 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
411 ;; unlocked revision
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
412 ((looking-at "\\$")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
413 (setq locking-user 'none)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
414 (setq status 'rev-and-lock))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
415 ;; revision is locked by some user
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
416 ((looking-at "\\([^ ]+\\) \\$")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
417 (setq locking-user
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
418 (buffer-substring-no-properties (match-beginning 1)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
419 (match-end 1)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
420 (setq status 'rev-and-lock))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
421 ;; everything else: false
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
422 (nil)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
423 ;; unexpected information in
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
424 ;; keyword string --> quit
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
425 (nil)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
426 ;; search for $Revision
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
427 ;; --------------------
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
428 ((re-search-forward (concat "\\$"
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
429 "Revision: \\([0-9.]+\\) \\$")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
430 nil t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
431 ;; if found, store the revision number ...
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
432 (setq version (buffer-substring-no-properties (match-beginning 1)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
433 (match-end 1)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
434 ;; and see if there's any lock information
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
435 (goto-char (point-min))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
436 (if (re-search-forward (concat "\\$" "Locker:") nil t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
437 (cond ((looking-at " \\([^ ]+\\) \\$")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
438 (setq locking-user (buffer-substring-no-properties
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
439 (match-beginning 1)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
440 (match-end 1)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
441 (setq status 'rev-and-lock))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
442 ((looking-at " *\\$")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
443 (setq locking-user 'none)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
444 (setq status 'rev-and-lock))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
445 (t
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
446 (setq locking-user 'none)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
447 (setq status 'rev-and-lock)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
448 (setq status 'rev)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
449 ;; else: nothing found
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
450 ;; -------------------
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
451 (t nil)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
452 (if status (vc-file-setprop file 'vc-workfile-version version))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
453 (and (eq status 'rev-and-lock)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
454 (eq (vc-backend file) 'RCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
455 (vc-file-setprop file 'vc-locking-user locking-user)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
456 ;; If the file has headers, we don't want to query the master file,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
457 ;; because that would eliminate all the performance gain the headers
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
458 ;; brought us. We therefore use a heuristic for the checkout model
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
459 ;; now: If we trust the file permissions, and the file is not
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
460 ;; locked, then if the file is read-only the checkout model is
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
461 ;; `manual', otherwise `implicit'.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
462 (not (vc-mistrust-permissions file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
463 (not (vc-locking-user file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
464 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
465 (vc-file-setprop file 'vc-checkout-model 'manual)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
466 (vc-file-setprop file 'vc-checkout-model 'implicit)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
467 status))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
468
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
469 ;;; Access functions to file properties
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
470 ;;; (Properties should be _set_ using vc-file-setprop, but
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
471 ;;; _retrieved_ only through these functions, which decide
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
472 ;;; if the property is already known or not. A property should
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
473 ;;; only be retrieved by vc-file-getprop if there is no
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
474 ;;; access function.)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
475
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
476 ;;; properties indicating the backend
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
477 ;;; being used for FILE
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
478
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
479 (defun vc-backend-subdirectory-name (&optional file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
480 ;; Where the master and lock files for the current directory are kept
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
481 (symbol-name
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
482 (or
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
483 (and file (vc-backend file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
484 vc-default-back-end
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
485 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
486
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
487 (defun vc-name (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
488 "Return the master name of a file, nil if it is not registered.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
489 For CVS, the full name of CVS/Entries is returned."
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
490 (or (vc-file-getprop file 'vc-name)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
491 (let ((name-and-type (vc-registered file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
492 (if name-and-type
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
493 (progn
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
494 (vc-file-setprop file 'vc-backend (cdr name-and-type))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
495 (vc-file-setprop file 'vc-name (car name-and-type)))))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
496
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
497 (defun vc-backend (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
498 "Return the version-control type of a file, nil if it is not registered."
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
499 (and file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
500 (or (vc-file-getprop file 'vc-backend)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
501 (let ((name-and-type (vc-registered file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
502 (if name-and-type
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
503 (progn
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
504 (vc-file-setprop file 'vc-name (car name-and-type))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
505 (vc-file-setprop file 'vc-backend (cdr name-and-type))))))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
506
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
507 (defun vc-checkout-model (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
508 ;; Return `manual' if the user has to type C-x C-q to check out FILE.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
509 ;; Return `implicit' if the file can be modified without locking it first.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
510 (or
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
511 (vc-file-getprop file 'vc-checkout-model)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
512 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
513 ((eq (vc-backend file) 'SCCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
514 (vc-file-setprop file 'vc-checkout-model 'manual))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
515 ((eq (vc-backend file) 'RCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
516 (vc-consult-rcs-headers file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
517 (or (vc-file-getprop file 'vc-checkout-model)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
518 (progn (vc-fetch-master-properties file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
519 (vc-file-getprop file 'vc-checkout-model))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
520 ((eq (vc-backend file) 'CVS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
521 (vc-file-setprop file 'vc-checkout-model
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
522 (if (getenv "CVSREAD") 'manual 'implicit))))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
523
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
524 ;;; properties indicating the locking state
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
525
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
526 (defun vc-cvs-status (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
527 ;; Return the cvs status of FILE
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
528 ;; (Status field in output of "cvs status")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
529 (cond ((vc-file-getprop file 'vc-cvs-status))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
530 (t (vc-fetch-master-properties file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
531 (vc-file-getprop file 'vc-cvs-status))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
532
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
533 (defun vc-master-locks (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
534 ;; Return the lock entries in the master of FILE.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
535 ;; Return 'none if there are no such entries, and a list
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
536 ;; of the form ((VERSION USER) (VERSION USER) ...) otherwise.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
537 (cond ((vc-file-getprop file 'vc-master-locks))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
538 (t (vc-fetch-master-properties file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
539 (vc-file-getprop file 'vc-master-locks))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
540
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
541 (defun vc-master-locking-user (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
542 ;; Return the master file's idea of who is locking
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
543 ;; the current workfile version of FILE.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
544 ;; Return 'none if it is not locked.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
545 (let ((master-locks (vc-master-locks file)) lock)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
546 (if (eq master-locks 'none) 'none
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
547 ;; search for a lock on the current workfile version
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
548 (setq lock (assoc (vc-workfile-version file) master-locks))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
549 (cond (lock (cdr lock))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
550 ('none)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
551
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
552 (defun vc-lock-from-permissions (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
553 ;; If the permissions can be trusted for this file, determine the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
554 ;; locking state from them. Returns (user-login-name), `none', or nil.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
555 ;; This implementation assumes that any file which is under version
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
556 ;; control and has -rw-r--r-- is locked by its owner. This is true
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
557 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
558 ;; We have to be careful not to exclude files with execute bits on;
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
559 ;; scripts can be under version control too. Also, we must ignore the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
560 ;; group-read and other-read bits, since paranoid users turn them off.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
561 ;; This hack wins because calls to the somewhat expensive
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
562 ;; `vc-fetch-master-properties' function only have to be made if
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
563 ;; (a) the file is locked by someone other than the current user,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
564 ;; or (b) some untoward manipulation behind vc's back has changed
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
565 ;; the owner or the `group' or `other' write bits.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
566 (let ((attributes (file-attributes file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
567 (if (not (vc-mistrust-permissions file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
568 (cond ((string-match ".r-..-..-." (nth 8 attributes))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
569 (vc-file-setprop file 'vc-locking-user 'none))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
570 ((and (= (nth 2 attributes) (user-uid))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
571 (string-match ".rw..-..-." (nth 8 attributes)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
572 (vc-file-setprop file 'vc-locking-user (vc-user-login-name)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
573 (nil)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
574
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
575 (defun vc-user-login-name (&optional uid)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
576 ;; Return the name under which the user is logged in, as a string.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
577 ;; (With optional argument UID, return the name of that user.)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
578 ;; This function does the same as `user-login-name', but unlike
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
579 ;; that, it never returns nil. If a UID cannot be resolved, that
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
580 ;; UID is returned as a string.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
581 (or (user-login-name uid)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
582 (and uid (number-to-string uid))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
583 (number-to-string (user-uid))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
584
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
585 (defun vc-file-owner (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
586 ;; Return who owns FILE (user name, as a string).
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
587 (vc-user-login-name (nth 2 (file-attributes file))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
588
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
589 (defun vc-rcs-lock-from-diff (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
590 ;; Diff the file against the master version. If differences are found,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
591 ;; mark the file locked. This is only used for RCS with non-strict
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
592 ;; locking. (If "rcsdiff" doesn't understand --brief, we do a double-take
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
593 ;; and remember the fact for the future.)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
594 (let* ((version (concat "-r" (vc-workfile-version file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
595 (status (if (eq vc-rcsdiff-knows-brief 'no)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
596 (vc-simple-command 1 "rcsdiff" file version)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
597 (vc-simple-command 2 "rcsdiff" file "--brief" version))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
598 (if (eq status 2)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
599 (if (not vc-rcsdiff-knows-brief)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
600 (setq vc-rcsdiff-knows-brief 'no
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
601 status (vc-simple-command 1 "rcsdiff" file version))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
602 (error "rcsdiff failed."))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
603 (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
604 (if (zerop status)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
605 (vc-file-setprop file 'vc-locking-user 'none)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
606 (vc-file-setprop file 'vc-locking-user (vc-file-owner file)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
607
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
608 (defun vc-locking-user (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
609 ;; Return the name of the person currently holding a lock on FILE.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
610 ;; Return nil if there is no such person.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
611 ;; Under CVS, a file is considered locked if it has been modified since
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
612 ;; it was checked out.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
613 ;; The property is cached. It is only looked up if it is currently nil.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
614 ;; Note that, for a file that is not locked, the actual property value
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
615 ;; is `none', to distinguish it from an unknown locking state. That value
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
616 ;; is converted to nil by this function, and returned to the caller.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
617 (let ((locking-user (vc-file-getprop file 'vc-locking-user)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
618 (if locking-user
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
619 ;; if we already know the property, return it
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
620 (if (eq locking-user 'none) nil locking-user)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
621
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
622 ;; otherwise, infer the property...
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
623 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
624 ((eq (vc-backend file) 'CVS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
625 (or (and (eq (vc-checkout-model file) 'manual)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
626 (vc-lock-from-permissions file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
627 (and (equal (vc-file-getprop file 'vc-checkout-time)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
628 (nth 5 (file-attributes file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
629 (vc-file-setprop file 'vc-locking-user 'none))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
630 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
631
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
632 ((eq (vc-backend file) 'RCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
633 (let (p-lock)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
634
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
635 ;; Check for RCS headers first
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
636 (or (eq (vc-consult-rcs-headers file) 'rev-and-lock)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
637
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
638 ;; If there are no headers, try to learn it
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
639 ;; from the permissions.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
640 (and (setq p-lock (vc-lock-from-permissions file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
641 (if (eq p-lock 'none)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
642
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
643 ;; If the permissions say "not locked", we know
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
644 ;; that the checkout model must be `manual'.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
645 (vc-file-setprop file 'vc-checkout-model 'manual)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
646
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
647 ;; If the permissions say "locked", we can only trust
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
648 ;; this *if* the checkout model is `manual'.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
649 (eq (vc-checkout-model file) 'manual)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
650
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
651 ;; Otherwise, use lock information from the master file.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
652 (vc-file-setprop file 'vc-locking-user
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
653 (vc-master-locking-user file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
654
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
655 ;; Finally, if the file is not explicitly locked
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
656 ;; it might still be locked implicitly.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
657 (and (eq (vc-file-getprop file 'vc-locking-user) 'none)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
658 (eq (vc-checkout-model file) 'implicit)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
659 (vc-rcs-lock-from-diff file))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
660
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
661 ((eq (vc-backend file) 'SCCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
662 (or (vc-lock-from-permissions file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
663 (vc-file-setprop file 'vc-locking-user
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
664 (vc-master-locking-user file)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
665
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
666 ;; convert a possible 'none value
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
667 (setq locking-user (vc-file-getprop file 'vc-locking-user))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
668 (if (eq locking-user 'none) nil locking-user))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
669
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
670 ;;; properties to store current and recent version numbers
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
671
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
672 (defun vc-latest-version (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
673 ;; Return version level of the latest version of FILE
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
674 (cond ((vc-file-getprop file 'vc-latest-version))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
675 (t (vc-fetch-properties file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
676 (vc-file-getprop file 'vc-latest-version))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
677
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
678 (defun vc-your-latest-version (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
679 ;; Return version level of the latest version of FILE checked in by you
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
680 (cond ((vc-file-getprop file 'vc-your-latest-version))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
681 (t (vc-fetch-properties file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
682 (vc-file-getprop file 'vc-your-latest-version))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
683
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
684 (defun vc-master-workfile-version (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
685 ;; Return the master file's idea of what is the current workfile version.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
686 ;; This property is defined for RCS only.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
687 (cond ((vc-file-getprop file 'vc-master-workfile-version))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
688 (t (vc-fetch-master-properties file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
689 (vc-file-getprop file 'vc-master-workfile-version))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
690
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
691 (defun vc-fetch-properties (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
692 ;; Fetch vc-latest-version and vc-your-latest-version
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
693 ;; if that wasn't already done.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
694 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
695 ((eq (vc-backend file) 'RCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
696 (save-excursion
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
697 (set-buffer (get-buffer-create "*vc-info*"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
698 (vc-insert-file (vc-name file) "^desc")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
699 (vc-parse-buffer
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
700 (list '("^\\([0-9]+\\.[0-9.]+\\)\ndate[ \t]+\\([0-9.]+\\);" 1 2)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
701 (list (concat "^\\([0-9]+\\.[0-9.]+\\)\n"
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
702 "date[ \t]+\\([0-9.]+\\);[ \t]+"
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
703 "author[ \t]+"
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
704 (regexp-quote (vc-user-login-name)) ";") 1 2))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
705 file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
706 '(vc-latest-version vc-your-latest-version))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
707 (if (get-buffer "*vc-info*")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
708 (kill-buffer (get-buffer "*vc-info*")))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
709 (t (vc-fetch-master-properties file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
710 ))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
711
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
712 (defun vc-workfile-version (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
713 ;; Return version level of the current workfile FILE
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
714 ;; This is attempted by first looking at the RCS keywords.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
715 ;; If there are no keywords in the working file,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
716 ;; vc-master-workfile-version is taken.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
717 ;; Note that this property is cached, that is, it is only
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
718 ;; looked up if it is nil.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
719 ;; For SCCS, this property is equivalent to vc-latest-version.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
720 (cond ((vc-file-getprop file 'vc-workfile-version))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
721 ((eq (vc-backend file) 'SCCS) (vc-latest-version file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
722 ((eq (vc-backend file) 'RCS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
723 (if (vc-consult-rcs-headers file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
724 (vc-file-getprop file 'vc-workfile-version)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
725 (let ((rev (cond ((vc-master-workfile-version file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
726 ((vc-latest-version file)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
727 (vc-file-setprop file 'vc-workfile-version rev)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
728 rev)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
729 ((eq (vc-backend file) 'CVS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
730 (if (vc-consult-rcs-headers file) ;; CVS
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
731 (vc-file-getprop file 'vc-workfile-version)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
732 (catch 'found
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
733 (vc-find-cvs-master (file-name-directory file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
734 (file-name-nondirectory file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
735 (vc-file-getprop file 'vc-workfile-version)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
736
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;;; actual version-control code starts here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (defun vc-registered (file)
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
740 (let (handler handlers)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (if (boundp 'file-name-handler-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (setq handler (find-file-name-handler file 'vc-registered)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (funcall handler 'vc-registered file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ;; Search for a master corresponding to the given file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (let ((dirname (or (file-name-directory file) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (basename (file-name-nondirectory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (catch 'found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (function (lambda (s)
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
751 (if (atom s)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
752 (funcall s dirname basename)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
753 (let ((trial (format (car s) dirname basename)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
754 (if (and (file-exists-p trial)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
755 ;; Make sure the file we found with name
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
756 ;; TRIAL is not the source file itself.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
757 ;; That can happen with RCS-style names
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
758 ;; if the file name is truncated
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
759 ;; (e.g. to 14 chars). See if either
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
760 ;; directory or attributes differ.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
761 (or (not (string= dirname
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
762 (file-name-directory trial)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
763 (not (equal
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
764 (file-attributes file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
765 (file-attributes trial)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
766 (throw 'found (cons trial (cdr s))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 vc-master-templates)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (defun vc-find-cvs-master (dirname basename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 ;; Check if DIRNAME/BASENAME is handled by CVS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 ;; If it is, do a (throw 'found (cons MASTER 'CVS)).
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
773 ;; Note: This function throws the name of CVS/Entries
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
774 ;; NOT that of the RCS master file (because we wouldn't be able
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
775 ;; to access it under remote CVS).
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
776 ;; The function returns nil if DIRNAME/BASENAME is not handled by CVS.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
777 (if (and vc-handle-cvs
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
778 (file-directory-p (concat dirname "CVS/"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (file-readable-p (concat dirname "CVS/Entries")))
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
780 (let (buffer time (fold case-fold-search)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
781 (file (concat dirname basename)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (save-excursion
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
784 (setq buffer (set-buffer (get-buffer-create "*vc-info*")))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
785 (vc-insert-file (concat dirname "CVS/Entries"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
786 (goto-char (point-min))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
787 ;; make sure the file name is searched
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
788 ;; case-sensitively
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
789 (setq case-fold-search nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (cond
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
791 ;; normal entry
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 ((re-search-forward
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
793 (concat "^/" (regexp-quote basename)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
794 "/\\([^/]*\\)/[^ /]* \\([A-Z][a-z][a-z]\\) *\\([0-9]*\\) \\([0-9]*\\):\\([0-9]*\\):\\([0-9]*\\) \\([0-9]*\\)")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 nil t)
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
796 (setq case-fold-search fold) ;; restore the old value
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
797 ;; We found it. Store away version number now that we
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
798 ;; are anyhow so close to finding it.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
799 (vc-file-setprop file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
800 'vc-workfile-version
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
801 (match-string 1))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
802 ;; If the file hasn't been modified since checkout,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
803 ;; store the checkout-time.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
804 (let ((mtime (nth 5 (file-attributes file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
805 (second (string-to-number (match-string 6)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
806 (minute (string-to-number (match-string 5)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
807 (hour (string-to-number (match-string 4)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
808 (day (string-to-number (match-string 3)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
809 (year (string-to-number (match-string 7))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
810 (if (equal mtime
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
811 (encode-time
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
812 second minute hour day
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
813 (/ (string-match
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
814 (match-string 2)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
815 "xxxJanFebMarAprMayJunJulAugSepOctNovDec")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
816 3)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
817 year 0))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
818 (vc-file-setprop file 'vc-checkout-time mtime)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
819 (vc-file-setprop file 'vc-checkout-time 0)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
820 (throw 'found (cons (concat dirname "CVS/Entries") 'CVS)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
821 ;; entry for a "locally added" file (not yet committed)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
822 ((re-search-forward
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
823 (concat "^/" (regexp-quote basename) "/0/Initial ") nil t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
824 (setq case-fold-search fold) ;; restore the old value
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
825 (vc-file-setprop file 'vc-checkout-time 0)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
826 (vc-file-setprop file 'vc-workfile-version "0")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
827 (throw 'found (cons (concat dirname "CVS/Entries") 'CVS)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
828 (t (setq case-fold-search fold) ;; restore the old value
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
829 nil)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
830 (kill-buffer buffer)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
832 (defun vc-buffer-backend ()
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
833 "Return the version-control type of the visited file, or nil if none."
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
834 (if (eq vc-buffer-backend t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
835 (setq vc-buffer-backend (vc-backend (buffer-file-name)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
836 vc-buffer-backend))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (defun vc-toggle-read-only (&optional verbose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 "Change read-only status of current buffer, perhaps via version control.
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
840 If the buffer is visiting a file registered with version control,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
841 then check the file in or out. Otherwise, just change the read-only flag
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
842 of the buffer. With prefix argument, ask for version number."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (interactive "P")
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
844 (if (vc-backend (buffer-file-name))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
845 (vc-next-action verbose)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
846 (toggle-read-only)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (define-key global-map "\C-x\C-q" 'vc-toggle-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
849 (defun vc-after-save ()
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
850 ;; Function to be called by basic-save-buffer (in files.el).
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
851 ;; If the file in the current buffer is under version control,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
852 ;; not locked, and the checkout model for it is `implicit',
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
853 ;; mark it "locked" and redisplay the mode line.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
854 (let ((file (buffer-file-name)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
855 (and (vc-file-getprop file 'vc-backend)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
856 ;; ...check the property directly, not through the function of the
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
857 ;; same name. Otherwise Emacs would check for a master file
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
858 ;; each time a non-version-controlled buffer is saved.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
859 ;; The property is computed when the file is visited, so if it
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
860 ;; is `nil' now, it is certain that the file is NOT
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
861 ;; version-controlled.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
862 (or (and (equal (vc-file-getprop file 'vc-checkout-time)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
863 (nth 5 (file-attributes file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
864 ;; File has been saved in the same second in which
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
865 ;; it was checked out. Clear the checkout-time
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
866 ;; to avoid confusion.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
867 (vc-file-setprop file 'vc-checkout-time nil))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
868 t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
869 (not (vc-locking-user file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
870 (eq (vc-checkout-model file) 'implicit)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
871 (vc-file-setprop file 'vc-locking-user (vc-user-login-name))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
872 (or (and (eq (vc-backend file) 'CVS)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
873 (vc-file-setprop file 'vc-cvs-status nil))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
874 t)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
875 (vc-mode-line file))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (defun vc-mode-line (file &optional label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 "Set `vc-mode' to display type of version control for FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 The value is set in the current buffer, which should be the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 visiting FILE. Second optional arg LABEL is put in place of version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 control system name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (interactive (list buffer-file-name nil))
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
883 (let ((vc-type (vc-backend file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
884 (setq vc-mode
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
885 (and vc-type
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
886 (concat " " (or label (symbol-name vc-type))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
887 (and vc-display-status (vc-status file)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
888 ;; If the file is locked by some other user, make
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
889 ;; the buffer read-only. Like this, even root
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
890 ;; cannot modify a file that someone else has locked.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
891 (and vc-type
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
892 (equal file (buffer-file-name))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
893 (vc-locking-user file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
894 (not (string= (vc-user-login-name) (vc-locking-user file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
895 (setq buffer-read-only t))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
896 ;; If the user is root, and the file is not owner-writable,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
897 ;; then pretend that we can't write it
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
898 ;; even though we can (because root can write anything).
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
899 ;; This way, even root cannot modify a file that isn't locked.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
900 (and vc-type
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
901 (equal file (buffer-file-name))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
902 (not buffer-read-only)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
903 (zerop (user-real-uid))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
904 (zerop (logand (file-modes (buffer-file-name)) 128))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
905 (setq buffer-read-only t))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
906 (force-mode-line-update)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
907 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
908 vc-type))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
910 (defun vc-status (file)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
911 ;; Return string for placement in modeline by `vc-mode-line'.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
912 ;; Format:
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
913 ;;
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
914 ;; "-REV" if the revision is not locked
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
915 ;; ":REV" if the revision is locked by the user
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
916 ;; ":LOCKER:REV" if the revision is locked by somebody else
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
917 ;; " @@" for a CVS file that is added, but not yet committed
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
918 ;;
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
919 ;; In the CVS case, a "locked" working file is a
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
920 ;; working file that is modified with respect to the master.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
921 ;; The file is "locked" from the moment when the user saves
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
922 ;; the modified buffer.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
923 ;;
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
924 ;; This function assumes that the file is registered.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
926 (let ((locker (vc-locking-user file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
927 (rev (vc-workfile-version file)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
928 (cond ((string= "0" rev)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
929 " @@")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
930 ((not locker)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
931 (concat "-" rev))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
932 ((string= locker (vc-user-login-name))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
933 (concat ":" rev))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
934 (t
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
935 (concat ":" locker ":" rev)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
937 (defun vc-follow-link ()
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
938 ;; If the current buffer visits a symbolic link, this function makes it
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
939 ;; visit the real file instead. If the real file is already visited in
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
940 ;; another buffer, make that buffer current, and kill the buffer
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
941 ;; that visits the link.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
942 (let* ((truename (abbreviate-file-name (file-chase-links buffer-file-name)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
943 (true-buffer (find-buffer-visiting truename))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
944 (this-buffer (current-buffer)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
945 (if (eq true-buffer this-buffer)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
946 (progn
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
947 (kill-buffer this-buffer)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
948 ;; In principle, we could do something like set-visited-file-name.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
949 ;; However, it can't be exactly the same as set-visited-file-name.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
950 ;; I'm not going to work out the details right now. -- rms.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
951 (set-buffer (find-file-noselect truename)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
952 (set-buffer true-buffer)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
953 (kill-buffer this-buffer))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 ;;; install a call to the above as a find-file hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (defun vc-find-file-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 ;; Recompute whether file is version controlled,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 ;; if user has killed the buffer and revisited.
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
959 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
960 (buffer-file-name
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
961 (vc-file-clearprops buffer-file-name)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
962 (cond
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
963 ((vc-backend buffer-file-name)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
964 (vc-mode-line buffer-file-name)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
965 (cond ((not vc-make-backup-files)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
966 ;; Use this variable, not make-backup-files,
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
967 ;; because this is for things that depend on the file name.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
968 (make-local-variable 'backup-inhibited)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
969 (setq backup-inhibited t))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
970 ((let* ((link (file-symlink-p buffer-file-name))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
971 (link-type (and link (vc-backend (file-chase-links link)))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
972 (if link-type
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
973 (cond ((eq vc-follow-symlinks nil)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
974 (message
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
975 "Warning: symbolic link to %s-controlled source file" link-type))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
976 ((or (not (eq vc-follow-symlinks 'ask))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
977 ;; If we already visited this file by following
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
978 ;; the link, don't ask again if we try to visit
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
979 ;; it again. GUD does that, and repeated questions
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
980 ;; are painful.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
981 (get-file-buffer
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
982 (abbreviate-file-name (file-chase-links buffer-file-name))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
983
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
984 (vc-follow-link)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
985 (message "Followed link to %s" buffer-file-name)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
986 (vc-find-file-hook))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
987 (t
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
988 (if (yes-or-no-p (format
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
989 "Symbolic link to %s-controlled source file; follow link? " link-type))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
990 (progn (vc-follow-link)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
991 (message "Followed link to %s" buffer-file-name)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
992 (vc-find-file-hook))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
993 (message
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
994 "Warning: editing through the link bypasses version control")
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
995 ))))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (add-hook 'find-file-hooks 'vc-find-file-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 ;;; more hooks, this time for file-not-found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (defun vc-file-not-found-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 "When file is not found, try to check it out from RCS or SCCS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 Returns t if checkout was successful, nil otherwise."
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1003 (if (vc-backend buffer-file-name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (require 'vc)
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1006 (setq default-directory (file-name-directory (buffer-file-name)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (not (vc-error-occurred (vc-checkout buffer-file-name))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (add-hook 'find-file-not-found-hooks 'vc-file-not-found-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1011 ;; Discard info about a file when we kill its buffer.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1012 (defun vc-kill-buffer-hook ()
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1013 (if (stringp (buffer-file-name))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1014 (progn
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1015 (vc-file-clearprops (buffer-file-name))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1016 (kill-local-variable 'vc-buffer-backend))))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1017
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1018 ;;;(add-hook 'kill-buffer-hook 'vc-kill-buffer-hook)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1019
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ;;; Now arrange for bindings and autoloading of the main package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ;;; Bindings for this have to go in the global map, as we'll often
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;;; want to call them from random buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1024 (setq vc-prefix-map (lookup-key global-map "\C-xv"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1025 (if (not (keymapp vc-prefix-map))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1026 (progn
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1027 (setq vc-prefix-map (make-sparse-keymap))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1028 (define-key global-map "\C-xv" vc-prefix-map)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1029 (define-key vc-prefix-map "a" 'vc-update-change-log)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1030 (define-key vc-prefix-map "c" 'vc-cancel-version)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1031 (define-key vc-prefix-map "d" 'vc-directory)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1032 (define-key vc-prefix-map "h" 'vc-insert-headers)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1033 (define-key vc-prefix-map "i" 'vc-register)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1034 (define-key vc-prefix-map "l" 'vc-print-log)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1035 (define-key vc-prefix-map "r" 'vc-retrieve-snapshot)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1036 (define-key vc-prefix-map "s" 'vc-create-snapshot)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1037 (define-key vc-prefix-map "u" 'vc-revert-buffer)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1038 (define-key vc-prefix-map "v" 'vc-next-action)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1039 (define-key vc-prefix-map "=" 'vc-diff)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1040 (define-key vc-prefix-map "~" 'vc-version-other-window)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1042 ;; Emacs menus
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1043 ;(if (not (boundp 'vc-menu-map))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1044 ; ;; Don't do the menu bindings if menu-bar.el wasn't loaded to defvar
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1045 ; ;; vc-menu-map.
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1046 ; ()
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1047 ; ;;(define-key vc-menu-map [show-files]
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1048 ; ;; '("Show Files under VC" . (vc-directory t)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1049 ; (define-key vc-menu-map [vc-directory] '("Show Locked Files" . vc-directory))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1050 ; (define-key vc-menu-map [separator1] '("----"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1051 ; (define-key vc-menu-map [vc-rename-file] '("Rename File" . vc-rename-file))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1052 ; (define-key vc-menu-map [vc-version-other-window]
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1053 ; '("Show Other Version" . vc-version-other-window))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1054 ; (define-key vc-menu-map [vc-diff] '("Compare with Last Version" . vc-diff))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1055 ; (define-key vc-menu-map [vc-update-change-log]
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1056 ; '("Update ChangeLog" . vc-update-change-log))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1057 ; (define-key vc-menu-map [vc-print-log] '("Show History" . vc-print-log))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1058 ; (define-key vc-menu-map [separator2] '("----"))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1059 ; (define-key vc-menu-map [undo] '("Undo Last Check-In" . vc-cancel-version))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1060 ; (define-key vc-menu-map [vc-revert-buffer]
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1061 ; '("Revert to Last Version" . vc-revert-buffer))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1062 ; (define-key vc-menu-map [vc-insert-header]
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1063 ; '("Insert Header" . vc-insert-headers))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1064 ; (define-key vc-menu-map [vc-menu-check-in] '("Check In" . vc-next-action))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1065 ; (define-key vc-menu-map [vc-check-out] '("Check Out" . vc-toggle-read-only))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1066 ; (define-key vc-menu-map [vc-register] '("Register" . vc-register)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1068 ;(put 'vc-rename-file 'menu-enable 'vc-mode)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1069 ;(put 'vc-version-other-window 'menu-enable 'vc-mode)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1070 ;(put 'vc-diff 'menu-enable 'vc-mode)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1071 ;(put 'vc-update-change-log 'menu-enable
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1072 ; '(eq (vc-buffer-backend) 'RCS))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1073 ;(put 'vc-print-log 'menu-enable 'vc-mode)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1074 ;(put 'vc-cancel-version 'menu-enable 'vc-mode)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1075 ;(put 'vc-revert-buffer 'menu-enable 'vc-mode)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1076 ;(put 'vc-insert-headers 'menu-enable 'vc-mode)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1077 ;(put 'vc-next-action 'menu-enable 'vc-mode)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1078 ;(put 'vc-toggle-read-only 'menu-enable 'vc-mode)
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1079 ;(put 'vc-register 'menu-enable '(and buffer-file-name (not vc-mode)))
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1080
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (defconst vc-menu
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1082 '("VC"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 :filter vc-menu-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 ["" vc-next-action buffer-file-name nil]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 ;;["Show Locked Files" vc-directory t] ;; needs new dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 ["Revert to Last Revision" vc-revert-buffer vc-mode nil]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 ["Cancel Last Checkin" vc-cancel-version vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 ["Rename File" vc-rename-this-file vc-mode nil]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 ["Diff Against Last Version" vc-diff vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 ["Diff Between Revisions..." vc-version-diff vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 ;;["Ediff Between Revisions..." ediff-revision vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 ["Visit Other Version..." vc-version-other-window vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 ["Show Edit History" vc-print-log vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 ;; The two commented out List functions simply don't work at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 ;; moment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 ;;["List Locked Files" (vc-directory '(16)) t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 ["List Locked Files Any User" vc-directory t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 ;;["List Registered Files" (vc-directory '(4)) t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 ["Create Snapshot" vc-create-snapshot t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 ["Retrieve Snapshot" vc-retrieve-snapshot t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 ["CVS Update Directory" cvs-update t] ; pcl-cvs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 ;;["Show File Status" vc-cvs-file-status vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 "Menubar entry for using the revision control system.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (defun vc-menu-filter (menu-items)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (let* ((result menu-items) ; modify in-place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (case-fold-search t)
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1114 (type (vc-backend buffer-file-name))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (file (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (file-name-nondirectory buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 op owner item status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (setq op (cond ((null type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 "Register File")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 ((eq type 'CVS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (setq status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (vc-file-getprop buffer-file-name 'cvs-status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (if status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (cdr (assoc status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 '(("Locally Modified" . "Commit")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 ("Needs Merge" . "Merge with repository")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 ("Up-to-date" . "Do nothing to")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 ("Needs Checkout" . "Update"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 ;; #### - we're not gonna call cvs status just to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 ;; post a lousy menu...that's insane!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 "Next action on"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 ;; these are all for RCS and SCCS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 ((not (setq owner (vc-file-owner file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 ;; #### - ugh! this is broken.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 ;; vc-file-owner is not a suitable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 ;; substitute for vc-locking-user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 "Check out File")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 ((not (string-equal owner (user-login-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 "Steal File Lock")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (t "Check in File")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (while (setq item (pop menu-items))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (and (vectorp item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (cond ((eq 'vc-next-action (aref item 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (aset item 0 op)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (aset item 3 file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 ((eq 'vc-file-status (aref item 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (aset item 2 (eq 'CVS type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (aset item 3 file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 ((> (length item) 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (aset item 3 file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (add-hook 'before-init-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 #'(lambda () (and (featurep 'menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 current-menubar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (car (find-menu-item current-menubar '("Tools")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (add-submenu '("Tools") vc-menu "Compare")
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
1160 (add-menu-button '("Tools") "---" "Compare"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
1163 ;;; End XEmacs menus
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (provide 'vc-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 ;;; vc-hooks.el ends here