annotate lisp/packages/vc-hooks.el @ 194:2947057885e5

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