2232
|
1 ;;; vc-hooks.el --- resident support for version-control
|
904
|
2
|
74442
|
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
|
100908
|
4 ;; 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
904
|
5
|
31382
|
6 ;; Author: FSF (see vc.el for full credits)
|
|
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
|
904
|
8
|
|
9 ;; This file is part of GNU Emacs.
|
|
10
|
94678
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
|
904
|
12 ;; it under the terms of the GNU General Public License as published by
|
94678
|
13 ;; the Free Software Foundation, either version 3 of the License, or
|
|
14 ;; (at your option) any later version.
|
904
|
15
|
|
16 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
94747
|
19 ;; GNU General Public License for more details.
|
904
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
94678
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
904
|
23
|
|
24 ;;; Commentary:
|
|
25
|
31382
|
26 ;; This is the always-loaded portion of VC. It takes care of
|
|
27 ;; VC-related activities that are done when you visit a file, so that
|
|
28 ;; vc.el itself is loaded only when you use a VC command. See the
|
|
29 ;; commentary of vc.el.
|
904
|
30
|
|
31 ;;; Code:
|
|
32
|
33856
|
33 (eval-when-compile
|
|
34 (require 'cl))
|
31404
|
35
|
11604
|
36 ;; Customization Variables (the rest is in vc.el)
|
|
37
|
49620
c1b2182d8ca1
(vc-ignore-vc-files, vc-master-templates, vc-header-alist): Add obsolescence
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
38 (defvar vc-ignore-vc-files nil)
|
52300
2672198e6a12
(vc-ignore-vc-files, vc-master-templates): Better explain obsolescence, and
André Spiegel <spiegel@gnu.org>
diff
changeset
|
39 (make-obsolete-variable 'vc-ignore-vc-files
|
94150
d03fe9cb1cf4
(vc-ignore-vc-files, vc-master-templates, vc-header-alist):
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
40 "set `vc-handled-backends' to nil to disable VC."
|
d03fe9cb1cf4
(vc-ignore-vc-files, vc-master-templates, vc-header-alist):
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
41 "21.1")
|
52300
2672198e6a12
(vc-ignore-vc-files, vc-master-templates): Better explain obsolescence, and
André Spiegel <spiegel@gnu.org>
diff
changeset
|
42
|
49620
c1b2182d8ca1
(vc-ignore-vc-files, vc-master-templates, vc-header-alist): Add obsolescence
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
43 (defvar vc-master-templates ())
|
55099
|
44 (make-obsolete-variable 'vc-master-templates
|
|
45 "to define master templates for a given BACKEND, use
|
52300
2672198e6a12
(vc-ignore-vc-files, vc-master-templates): Better explain obsolescence, and
André Spiegel <spiegel@gnu.org>
diff
changeset
|
46 vc-BACKEND-master-templates. To enable or disable VC for a given
|
94150
d03fe9cb1cf4
(vc-ignore-vc-files, vc-master-templates, vc-header-alist):
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
47 BACKEND, use `vc-handled-backends'."
|
d03fe9cb1cf4
(vc-ignore-vc-files, vc-master-templates, vc-header-alist):
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
48 "21.1")
|
52300
2672198e6a12
(vc-ignore-vc-files, vc-master-templates): Better explain obsolescence, and
André Spiegel <spiegel@gnu.org>
diff
changeset
|
49
|
49620
c1b2182d8ca1
(vc-ignore-vc-files, vc-master-templates, vc-header-alist): Add obsolescence
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
50 (defvar vc-header-alist ())
|
94150
d03fe9cb1cf4
(vc-ignore-vc-files, vc-master-templates, vc-header-alist):
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
51 (make-obsolete-variable 'vc-header-alist 'vc-BACKEND-header "21.1")
|
11604
|
52
|
77591
ec47afd2d1db
(vc-ignore-dir-regexp): Add /.../ for the DFS filesystem.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
53 (defcustom vc-ignore-dir-regexp
|
ec47afd2d1db
(vc-ignore-dir-regexp): Add /.../ for the DFS filesystem.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
54 ;; Stop SMB, automounter, AFS, and DFS host lookups.
|
99130
e152a404d947
* files.el (locate-dominating-stop-dir-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
55 locate-dominating-stop-dir-regexp
|
73351
|
56 "Regexp matching directory names that are not under VC's control.
|
57079
|
57 The default regexp prevents fruitless and time-consuming attempts
|
|
58 to determine the VC status in directories in which filenames are
|
73351
|
59 interpreted as hostnames."
|
|
60 :type 'regexp
|
|
61 :group 'vc)
|
57079
|
62
|
94730
|
63 (defcustom vc-handled-backends '(RCS CVS SVN SCCS Bzr Git Hg Mtn Arch)
|
78791
|
64 ;; RCS, CVS, SVN and SCCS come first because they are per-dir
|
|
65 ;; rather than per-tree. RCS comes first because of the multibackend
|
|
66 ;; support intended to use RCS for local commits (with a remote CVS server).
|
|
67 "List of version control backends for which VC will be used.
|
31382
|
68 Entries in this list will be tried in order to determine whether a
|
|
69 file is under that sort of version control.
|
|
70 Removing an entry from the list prevents VC from being activated
|
|
71 when visiting a file managed by that backend.
|
|
72 An empty list disables VC altogether."
|
|
73 :type '(repeat symbol)
|
81902
|
74 :version "23.1"
|
20413
|
75 :group 'vc)
|
13378
96ff45331eb4
(vc-utc-string): Use timezone of TIMEVAL for the correction, not the
André Spiegel <spiegel@gnu.org>
diff
changeset
|
76
|
87523
fe5c2c0f8dcf
* progmodes/grep.el (grep-find-ignored-directories): Initialize
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
77 ;; Note: we don't actually have a darcs back end yet.
|
94730
|
78 ;; Also, Meta-CVS (corresponsding to MCVS) is unsupported.
|
91584
|
79 (defcustom vc-directory-exclusion-list '("SCCS" "RCS" "CVS" "MCVS"
|
|
80 ".svn" ".git" ".hg" ".bzr"
|
87523
fe5c2c0f8dcf
* progmodes/grep.el (grep-find-ignored-directories): Initialize
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
81 "_MTN" "_darcs" "{arch}")
|
87446
168445c0b213
* vc-hooks.el, vc.el: Move vc-directory-exclusion-list from vc.el
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
82 "List of directory names to be ignored when walking directory trees."
|
168445c0b213
* vc-hooks.el, vc.el: Move vc-directory-exclusion-list from vc.el
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
83 :type '(repeat string)
|
20413
|
84 :group 'vc)
|
13378
96ff45331eb4
(vc-utc-string): Use timezone of TIMEVAL for the correction, not the
André Spiegel <spiegel@gnu.org>
diff
changeset
|
85
|
94190
fad57210c7d2
* lisp/vc-sccs.el (vc-sccs-do-command): New fun. Use the "sccs" command.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
86 (defcustom vc-path nil
|
81835
|
87 "List of extra directories to search for version control commands."
|
20413
|
88 :type '(repeat directory)
|
|
89 :group 'vc)
|
11604
|
90
|
20413
|
91 (defcustom vc-make-backup-files nil
|
81835
|
92 "If non-nil, backups of registered files are made as with other files.
|
20413
|
93 If nil (the default), files covered by version control don't get backups."
|
|
94 :type 'boolean
|
51480
|
95 :group 'vc
|
|
96 :group 'backup)
|
904
|
97
|
20413
|
98 (defcustom vc-follow-symlinks 'ask
|
81835
|
99 "What to do if visiting a symbolic link to a file under version control.
|
31382
|
100 Editing such a file through the link bypasses the version control system,
|
|
101 which is dangerous and probably not what you want.
|
|
102
|
|
103 If this variable is t, VC follows the link and visits the real file,
|
14142
|
104 telling you about it in the echo area. If it is `ask', VC asks for
|
|
105 confirmation whether it should follow the link. If nil, the link is
|
20413
|
106 visited and a warning displayed."
|
31382
|
107 :type '(choice (const :tag "Ask for confirmation" ask)
|
|
108 (const :tag "Visit link and warn" nil)
|
|
109 (const :tag "Follow link" t))
|
20413
|
110 :group 'vc)
|
14142
|
111
|
20413
|
112 (defcustom vc-display-status t
|
81835
|
113 "If non-nil, display revision number and lock status in modeline.
|
20413
|
114 Otherwise, not displayed."
|
|
115 :type 'boolean
|
|
116 :group 'vc)
|
|
117
|
3900
|
118
|
20413
|
119 (defcustom vc-consult-headers t
|
81835
|
120 "If non-nil, identify work files by searching for version headers."
|
20413
|
121 :type 'boolean
|
|
122 :group 'vc)
|
11604
|
123
|
20413
|
124 (defcustom vc-keep-workfiles t
|
81835
|
125 "If non-nil, don't delete working files after registering changes.
|
11604
|
126 If the back-end is CVS, workfiles are always kept, regardless of the
|
20413
|
127 value of this flag."
|
|
128 :type 'boolean
|
|
129 :group 'vc)
|
11604
|
130
|
20413
|
131 (defcustom vc-mistrust-permissions nil
|
81835
|
132 "If non-nil, don't assume permissions/ownership track version-control status.
|
31382
|
133 If nil, do rely on the permissions.
|
20413
|
134 See also variable `vc-consult-headers'."
|
|
135 :type 'boolean
|
|
136 :group 'vc)
|
12914
|
137
|
|
138 (defun vc-mistrust-permissions (file)
|
31382
|
139 "Internal access function to variable `vc-mistrust-permissions' for FILE."
|
12914
|
140 (or (eq vc-mistrust-permissions 't)
|
|
141 (and vc-mistrust-permissions
|
31382
|
142 (funcall vc-mistrust-permissions
|
12914
|
143 (vc-backend-subdirectory-name file)))))
|
|
144
|
98675
2cae4bd13e67
* vc-hooks.el (vc-stay-local): Add a new choice and default to it.
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
145 (defcustom vc-stay-local 'only-file
|
81835
|
146 "Non-nil means use local operations when possible for remote repositories.
|
51761
|
147 This avoids slow queries over the network and instead uses heuristics
|
|
148 and past information to determine the current status of a file.
|
|
149
|
98675
2cae4bd13e67
* vc-hooks.el (vc-stay-local): Add a new choice and default to it.
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
150 If value is the symbol `only-file' `vc-dir' will connect to the
|
2cae4bd13e67
* vc-hooks.el (vc-stay-local): Add a new choice and default to it.
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
151 server, but heuristics will be used to determine the status for
|
2cae4bd13e67
* vc-hooks.el (vc-stay-local): Add a new choice and default to it.
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
152 all other VC operations.
|
2cae4bd13e67
* vc-hooks.el (vc-stay-local): Add a new choice and default to it.
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
153
|
51761
|
154 The value can also be a regular expression or list of regular
|
|
155 expressions to match against the host name of a repository; then VC
|
|
156 only stays local for hosts that match it. Alternatively, the value
|
|
157 can be a list of regular expressions where the first element is the
|
|
158 symbol `except'; then VC always stays local except for hosts matched
|
|
159 by these regular expressions."
|
98675
2cae4bd13e67
* vc-hooks.el (vc-stay-local): Add a new choice and default to it.
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
160 :type '(choice
|
2cae4bd13e67
* vc-hooks.el (vc-stay-local): Add a new choice and default to it.
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
161 (const :tag "Always stay local" t)
|
99192
|
162 (const :tag "Only for file operations" only-file)
|
51761
|
163 (const :tag "Don't stay local" nil)
|
|
164 (list :format "\nExamine hostname and %v" :tag "Examine hostname ..."
|
|
165 (set :format "%v" :inline t (const :format "%t" :tag "don't" except))
|
|
166 (regexp :format " stay local,\n%t: %v" :tag "if it matches")
|
|
167 (repeat :format "%v%i\n" :inline t (regexp :tag "or"))))
|
98675
2cae4bd13e67
* vc-hooks.el (vc-stay-local): Add a new choice and default to it.
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
168 :version "23.1"
|
51761
|
169 :group 'vc)
|
|
170
|
|
171 (defun vc-stay-local-p (file)
|
|
172 "Return non-nil if VC should stay local when handling FILE.
|
82058
|
173 This uses the `repository-hostname' backend operation.
|
|
174 If FILE is a list of files, return non-nil if any of them
|
|
175 individually should stay local."
|
81958
|
176 (if (listp file)
|
82058
|
177 (delq nil (mapcar 'vc-stay-local-p file))
|
81958
|
178 (let* ((backend (vc-backend file))
|
|
179 (sym (vc-make-backend-sym backend 'stay-local))
|
101673
|
180 (stay-local (if (boundp sym) (symbol-value sym) vc-stay-local)))
|
81958
|
181 (if (symbolp stay-local) stay-local
|
|
182 (let ((dirname (if (file-directory-p file)
|
|
183 (directory-file-name file)
|
|
184 (file-name-directory file))))
|
|
185 (eq 'yes
|
|
186 (or (vc-file-getprop dirname 'vc-stay-local-p)
|
|
187 (vc-file-setprop
|
|
188 dirname 'vc-stay-local-p
|
|
189 (let ((hostname (vc-call-backend
|
|
190 backend 'repository-hostname dirname)))
|
|
191 (if (not hostname)
|
|
192 'no
|
|
193 (let ((default t))
|
|
194 (if (eq (car-safe stay-local) 'except)
|
|
195 (setq default nil stay-local (cdr stay-local)))
|
|
196 (when (consp stay-local)
|
|
197 (setq stay-local
|
|
198 (mapconcat 'identity stay-local "\\|")))
|
|
199 (if (if (string-match stay-local hostname)
|
|
200 default (not default))
|
|
201 'yes 'no))))))))))))
|
51761
|
202
|
46723
|
203 ;;; This is handled specially now.
|
904
|
204 ;; Tell Emacs about this new kind of minor mode
|
46723
|
205 ;; (add-to-list 'minor-mode-alist '(vc-mode vc-mode))
|
904
|
206
|
2491
|
207 (make-variable-buffer-local 'vc-mode)
|
2620
|
208 (put 'vc-mode 'permanent-local t)
|
904
|
209
|
38373
|
210 (defun vc-mode (&optional arg)
|
|
211 ;; Dummy function for C-h m
|
|
212 "Version Control minor mode.
|
|
213 This minor mode is automatically activated whenever you visit a file under
|
|
214 control of one of the revision control systems in `vc-handled-backends'.
|
|
215 VC commands are globally reachable under the prefix `\\[vc-prefix-map]':
|
|
216 \\{vc-prefix-map}")
|
|
217
|
31404
|
218 (defmacro vc-error-occurred (&rest body)
|
40851
|
219 `(condition-case nil (progn ,@body nil) (error t)))
|
31404
|
220
|
904
|
221 ;; We need a notion of per-file properties because the version
|
11598
|
222 ;; control state of a file is expensive to derive --- we compute
|
31382
|
223 ;; them when the file is initially found, keep them up to date
|
11598
|
224 ;; during any subsequent VC operations, and forget them when
|
|
225 ;; the buffer is killed.
|
904
|
226
|
40851
|
227 (defvar vc-file-prop-obarray (make-vector 17 0)
|
904
|
228 "Obarray for per-file properties.")
|
|
229
|
31404
|
230 (defvar vc-touched-properties nil)
|
|
231
|
904
|
232 (defun vc-file-setprop (file property value)
|
31382
|
233 "Set per-file VC PROPERTY for FILE to VALUE."
|
31404
|
234 (if (and vc-touched-properties
|
|
235 (not (memq property vc-touched-properties)))
|
|
236 (setq vc-touched-properties (append (list property)
|
|
237 vc-touched-properties)))
|
904
|
238 (put (intern file vc-file-prop-obarray) property value))
|
|
239
|
|
240 (defun vc-file-getprop (file property)
|
31404
|
241 "Get per-file VC PROPERTY for FILE."
|
904
|
242 (get (intern file vc-file-prop-obarray) property))
|
|
243
|
11604
|
244 (defun vc-file-clearprops (file)
|
31382
|
245 "Clear all VC properties of FILE."
|
98429
b87cc3b45aa5
* vc-hooks.el (vc-file-clearprops): Revert change from 2008-09-29.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
246 (setplist (intern file vc-file-prop-obarray) nil))
|
11604
|
247
|
31382
|
248
|
|
249 ;; We keep properties on each symbol naming a backend as follows:
|
|
250 ;; * `vc-functions': an alist mapping vc-FUNCTION to vc-BACKEND-FUNCTION.
|
11604
|
251
|
31382
|
252 (defun vc-make-backend-sym (backend sym)
|
|
253 "Return BACKEND-specific version of VC symbol SYM."
|
|
254 (intern (concat "vc-" (downcase (symbol-name backend))
|
|
255 "-" (symbol-name sym))))
|
11604
|
256
|
31382
|
257 (defun vc-find-backend-function (backend fun)
|
|
258 "Return BACKEND-specific implementation of FUN.
|
47918
|
259 If there is no such implementation, return the default implementation;
|
31382
|
260 if that doesn't exist either, return nil."
|
|
261 (let ((f (vc-make-backend-sym backend fun)))
|
|
262 (if (fboundp f) f
|
|
263 ;; Load vc-BACKEND.el if needed.
|
|
264 (require (intern (concat "vc-" (downcase (symbol-name backend)))))
|
|
265 (if (fboundp f) f
|
|
266 (let ((def (vc-make-backend-sym 'default fun)))
|
|
267 (if (fboundp def) (cons def backend) nil))))))
|
|
268
|
|
269 (defun vc-call-backend (backend function-name &rest args)
|
|
270 "Call for BACKEND the implementation of FUNCTION-NAME with the given ARGS.
|
|
271 Calls
|
11604
|
272
|
31382
|
273 (apply 'vc-BACKEND-FUN ARGS)
|
|
274
|
|
275 if vc-BACKEND-FUN exists (after trying to find it in vc-BACKEND.el)
|
|
276 and else calls
|
|
277
|
|
278 (apply 'vc-default-FUN BACKEND ARGS)
|
|
279
|
|
280 It is usually called via the `vc-call' macro."
|
51370
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
281 (let ((f (assoc function-name (get backend 'vc-functions))))
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
282 (if f (setq f (cdr f))
|
31382
|
283 (setq f (vc-find-backend-function backend function-name))
|
51370
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
284 (push (cons function-name f) (get backend 'vc-functions)))
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
285 (cond
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
286 ((null f)
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
287 (error "Sorry, %s is not implemented for %s" function-name backend))
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
288 ((consp f) (apply (car f) (cdr f) args))
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
289 (t (apply f args)))))
|
31382
|
290
|
|
291 (defmacro vc-call (fun file &rest args)
|
82293
|
292 "A convenience macro for calling VC backend functions.
|
|
293 Functions called by this macro must accept FILE as the first argument.
|
94548
|
294 ARGS specifies any additional arguments. FUN should be unquoted.
|
|
295 BEWARE!! FILE is evaluated twice!!"
|
31382
|
296 `(vc-call-backend (vc-backend ,file) ',fun ,file ,@args))
|
|
297
|
|
298 (defsubst vc-parse-buffer (pattern i)
|
|
299 "Find PATTERN in the current buffer and return its Ith submatch."
|
|
300 (goto-char (point-min))
|
|
301 (if (re-search-forward pattern nil t)
|
|
302 (match-string i)))
|
11598
|
303
|
12251
|
304 (defun vc-insert-file (file &optional limit blocksize)
|
31382
|
305 "Insert the contents of FILE into the current buffer.
|
|
306
|
|
307 Optional argument LIMIT is a regexp. If present, the file is inserted
|
|
308 in chunks of size BLOCKSIZE (default 8 kByte), until the first
|
47918
|
309 occurrence of LIMIT is found. Anything from the start of that occurrence
|
46542
|
310 to the end of the buffer is then deleted. The function returns
|
|
311 non-nil if FILE exists and its contents were successfully inserted."
|
12367
f268f652055e
(vc-insert-file): Erase the current buffer before inserting the file.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
312 (erase-buffer)
|
33206
|
313 (when (file-exists-p file)
|
|
314 (if (not limit)
|
|
315 (insert-file-contents file)
|
94207
|
316 (unless blocksize (setq blocksize 8192))
|
33247
|
317 (let ((filepos 0))
|
|
318 (while
|
|
319 (and (< 0 (cadr (insert-file-contents
|
|
320 file nil filepos (incf filepos blocksize))))
|
|
321 (progn (beginning-of-line)
|
46542
|
322 (let ((pos (re-search-forward limit nil 'move)))
|
94207
|
323 (when pos (delete-region (match-beginning 0)
|
|
324 (point-max)))
|
46542
|
325 (not pos)))))))
|
33206
|
326 (set-buffer-modified-p nil)
|
|
327 t))
|
12251
|
328
|
98086
|
329 (defun vc-find-root (file witness)
|
57079
|
330 "Find the root of a checked out project.
|
|
331 The function walks up the directory tree from FILE looking for WITNESS.
|
98086
|
332 If WITNESS if not found, return nil, otherwise return the root."
|
99130
e152a404d947
* files.el (locate-dominating-stop-dir-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
333 (let ((locate-dominating-stop-dir-regexp
|
e152a404d947
* files.el (locate-dominating-stop-dir-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
334 (or vc-ignore-dir-regexp locate-dominating-stop-dir-regexp)))
|
e152a404d947
* files.el (locate-dominating-stop-dir-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
335 (locate-dominating-file file witness)))
|
99192
|
336
|
38373
|
337 ;; Access functions to file properties
|
|
338 ;; (Properties should be _set_ using vc-file-setprop, but
|
|
339 ;; _retrieved_ only through these functions, which decide
|
94548
|
340 ;; if the property is already known or not. A property should
|
38373
|
341 ;; only be retrieved by vc-file-getprop if there is no
|
|
342 ;; access function.)
|
11598
|
343
|
38373
|
344 ;; properties indicating the backend being used for FILE
|
31382
|
345
|
|
346 (defun vc-registered (file)
|
|
347 "Return non-nil if FILE is registered in a version control system.
|
11604
|
348
|
32070
|
349 This function performs the check each time it is called. To rely
|
|
350 on the result of a previous call, use `vc-backend' instead. If the
|
|
351 file was previously registered under a certain backend, then that
|
|
352 backend is tried first."
|
31382
|
353 (let (handler)
|
57079
|
354 (cond
|
99130
e152a404d947
* files.el (locate-dominating-stop-dir-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
355 ((and (file-name-directory file)
|
e152a404d947
* files.el (locate-dominating-stop-dir-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
356 (string-match vc-ignore-dir-regexp (file-name-directory file)))
|
85157
93de0ca0707d
Robustify a bit against filenames with no directory component.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
357 nil)
|
57079
|
358 ((and (boundp 'file-name-handler-alist)
|
|
359 (setq handler (find-file-name-handler file 'vc-registered)))
|
|
360 ;; handler should set vc-backend and return t if registered
|
|
361 (funcall handler 'vc-registered file))
|
|
362 (t
|
31382
|
363 ;; There is no file name handler.
|
|
364 ;; Try vc-BACKEND-registered for each handled BACKEND.
|
|
365 (catch 'found
|
32070
|
366 (let ((backend (vc-file-getprop file 'vc-backend)))
|
82849
|
367 (mapc
|
32070
|
368 (lambda (b)
|
|
369 (and (vc-call-backend b 'registered file)
|
|
370 (vc-file-setprop file 'vc-backend b)
|
|
371 (throw 'found t)))
|
47918
|
372 (if (or (not backend) (eq backend 'none))
|
32070
|
373 vc-handled-backends
|
|
374 (cons backend vc-handled-backends))))
|
31382
|
375 ;; File is not registered.
|
|
376 (vc-file-setprop file 'vc-backend 'none)
|
57079
|
377 nil)))))
|
31382
|
378
|
81958
|
379 (defun vc-backend (file-or-list)
|
|
380 "Return the version control type of FILE-OR-LIST, nil if it's not registered.
|
|
381 If the argument is a list, the files must all have the same back end."
|
31382
|
382 ;; `file' can be nil in several places (typically due to the use of
|
50879
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
383 ;; code like (vc-backend buffer-file-name)).
|
81958
|
384 (cond ((stringp file-or-list)
|
|
385 (let ((property (vc-file-getprop file-or-list 'vc-backend)))
|
|
386 ;; Note that internally, Emacs remembers unregistered
|
|
387 ;; files by setting the property to `none'.
|
|
388 (cond ((eq property 'none) nil)
|
|
389 (property)
|
|
390 ;; vc-registered sets the vc-backend property
|
|
391 (t (if (vc-registered file-or-list)
|
|
392 (vc-file-getprop file-or-list 'vc-backend)
|
|
393 nil)))))
|
|
394 ((and file-or-list (listp file-or-list))
|
|
395 (vc-backend (car file-or-list)))
|
|
396 (t
|
|
397 nil)))
|
|
398
|
31382
|
399
|
|
400 (defun vc-backend-subdirectory-name (file)
|
|
401 "Return where the master and lock FILEs for the current directory are kept."
|
|
402 (symbol-name (vc-backend file)))
|
11604
|
403
|
12251
|
404 (defun vc-name (file)
|
31564
|
405 "Return the master name of FILE.
|
|
406 If the file is not registered, or the master name is not known, return nil."
|
|
407 ;; TODO: This should ultimately become obsolete, at least up here
|
31382
|
408 ;; in vc-hooks.
|
12251
|
409 (or (vc-file-getprop file 'vc-name)
|
31808
25632a490236
(vc-name): Force correct computation of the value in case it is missing.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
410 ;; force computation of the property by calling
|
25632a490236
(vc-name): Force correct computation of the value in case it is missing.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
411 ;; vc-BACKEND-registered explicitly
|
25632a490236
(vc-name): Force correct computation of the value in case it is missing.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
412 (if (and (vc-backend file)
|
25632a490236
(vc-name): Force correct computation of the value in case it is missing.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
413 (vc-call-backend (vc-backend file) 'registered file))
|
21356
|
414 (vc-file-getprop file 'vc-name))))
|
11604
|
415
|
94481
|
416 (defun vc-checkout-model (backend files)
|
|
417 "Indicate how FILES are checked out.
|
11604
|
418
|
94481
|
419 If FILES are not registered, this function always returns nil.
|
42021
ddb97861a688
(vc-checkout-model, vc-state, vc-workfile-version): Return nil if
André Spiegel <spiegel@gnu.org>
diff
changeset
|
420 For registered files, the possible values are:
|
12884
f47248851f26
(vc-fetch-master-properties): Recognize cvs status "Unresolved Conflict".
André Spiegel <spiegel@gnu.org>
diff
changeset
|
421
|
100145
|
422 'implicit FILES are always writable, and checked out `implicitly'
|
31382
|
423 when the user saves the first changes to the file.
|
11604
|
424
|
94481
|
425 'locking FILES are read-only if up-to-date; user must type
|
46453
|
426 \\[vc-next-action] before editing. Strict locking
|
31382
|
427 is assumed.
|
12251
|
428
|
94481
|
429 'announce FILES are read-only if up-to-date; user must type
|
46453
|
430 \\[vc-next-action] before editing. But other users
|
31382
|
431 may be editing at the same time."
|
94481
|
432 (vc-call-backend backend 'checkout-model files))
|
12925
|
433
|
68383
|
434 (defun vc-user-login-name (file)
|
|
435 "Return the name under which the user accesses the given FILE."
|
|
436 (or (and (eq (string-match tramp-file-name-regexp file) 0)
|
|
437 ;; tramp case: execute "whoami" via tramp
|
|
438 (let ((default-directory (file-name-directory file)))
|
|
439 (with-temp-buffer
|
|
440 (if (not (zerop (process-file "whoami" nil t)))
|
|
441 ;; fall through if "whoami" didn't work
|
|
442 nil
|
|
443 ;; remove trailing newline
|
|
444 (delete-region (1- (point-max)) (point-max))
|
|
445 (buffer-string)))))
|
|
446 ;; normal case
|
|
447 (user-login-name)
|
|
448 ;; if user-login-name is nil, return the UID as a string
|
|
449 (number-to-string (user-uid))))
|
12925
|
450
|
31382
|
451 (defun vc-state (file)
|
|
452 "Return the version control state of FILE.
|
|
453
|
42021
ddb97861a688
(vc-checkout-model, vc-state, vc-workfile-version): Return nil if
André Spiegel <spiegel@gnu.org>
diff
changeset
|
454 If FILE is not registered, this function always returns nil.
|
ddb97861a688
(vc-checkout-model, vc-state, vc-workfile-version): Return nil if
André Spiegel <spiegel@gnu.org>
diff
changeset
|
455 For registered files, the value returned is one of:
|
12251
|
456
|
31382
|
457 'up-to-date The working file is unmodified with respect to the
|
|
458 latest version on the current branch, and not locked.
|
12925
|
459
|
31382
|
460 'edited The working file has been edited by the user. If
|
|
461 locking is used for the file, this state means that
|
|
462 the current version is locked by the calling user.
|
12925
|
463
|
31382
|
464 USER The current version of the working file is locked by
|
|
465 some other USER (a string).
|
47918
|
466
|
94521
|
467 'needs-update The file has not been edited by the user, but there is
|
31382
|
468 a more recent version on the current branch stored
|
|
469 in the master file.
|
12251
|
470
|
31382
|
471 'needs-merge The file has been edited by the user, and there is also
|
|
472 a more recent version on the current branch stored in
|
|
473 the master file. This state can only occur if locking
|
|
474 is not used for the file.
|
11604
|
475
|
87444
|
476 'unlocked-changes The working version of the file is not locked,
|
31382
|
477 but the working file has been changed with respect
|
|
478 to that version. This state can only occur for files
|
|
479 with locking; it represents an erroneous condition that
|
|
480 should be resolved by the user (vc-next-action will
|
87444
|
481 prompt the user to do it).
|
|
482
|
|
483 'added Scheduled to go into the repository on the next commit.
|
87445
|
484 Often represented by vc-working-revision = \"0\" in VCSes
|
87450
71fc7b1db920
* vc-hooks.el (vc-state): Document new 'ignored and 'unregistered
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
485 with monotonic IDs like Subversion and Mercurial.
|
71fc7b1db920
* vc-hooks.el (vc-state): Document new 'ignored and 'unregistered
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
486
|
87477
b5060e79eb98
* vc-svn.el (vc-svn-parse-status): Recognize 'added, 'removed,
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
487 'removed Scheduled to be deleted from the repository on next commit.
|
91584
|
488
|
93956
|
489 'conflict The file contains conflicts as the result of a merge.
|
94150
d03fe9cb1cf4
(vc-ignore-vc-files, vc-master-templates, vc-header-alist):
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
490 For now the conflicts are text conflicts. In the
|
d03fe9cb1cf4
(vc-ignore-vc-files, vc-master-templates, vc-header-alist):
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
491 future this might be extended to deal with metadata
|
93956
|
492 conflicts too.
|
|
493
|
94150
d03fe9cb1cf4
(vc-ignore-vc-files, vc-master-templates, vc-header-alist):
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
494 'missing The file is not present in the file system, but the VC
|
93196
|
495 system still tracks it.
|
|
496
|
94729
|
497 'ignored The file showed up in a dir-status listing with a flag
|
87450
71fc7b1db920
* vc-hooks.el (vc-state): Document new 'ignored and 'unregistered
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
498 indicating the version-control system is ignoring it,
|
91584
|
499 Note: This property is not set reliably (some VCSes
|
|
500 don't have useful directory-status commands) so assume
|
87450
71fc7b1db920
* vc-hooks.el (vc-state): Document new 'ignored and 'unregistered
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
501 that any file with vc-state nil might be ignorable
|
91584
|
502 without VC knowing it.
|
87450
71fc7b1db920
* vc-hooks.el (vc-state): Document new 'ignored and 'unregistered
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
503
|
94521
|
504 'unregistered The file is not under version control.
|
87450
71fc7b1db920
* vc-hooks.el (vc-state): Document new 'ignored and 'unregistered
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
505
|
91584
|
506 A return of nil from this function means we have no information on the
|
94548
|
507 status of this file."
|
94860
|
508 ;; Note: in Emacs 22 and older, return of nil meant the file was
|
|
509 ;; unregistered. This is potentially a source of
|
|
510 ;; backward-compatibility bugs.
|
87444
|
511
|
50895
|
512 ;; FIXME: New (sub)states needed (?):
|
|
513 ;; - `copied' and `moved' (might be handled by `removed' and `added')
|
31382
|
514 (or (vc-file-getprop file 'vc-state)
|
94805
|
515 (when (> (length file) 0)
|
|
516 (let ((backend (vc-backend file)))
|
|
517 (when backend
|
|
518 (vc-file-setprop
|
|
519 file 'vc-state
|
|
520 (vc-call-backend backend 'state-heuristic file)))))))
|
11604
|
521
|
31382
|
522 (defsubst vc-up-to-date-p (file)
|
|
523 "Convenience function that checks whether `vc-state' of FILE is `up-to-date'."
|
|
524 (eq (vc-state file) 'up-to-date))
|
|
525
|
|
526 (defun vc-default-state-heuristic (backend file)
|
94548
|
527 "Default implementation of vc-BACKEND-state-heuristic.
|
31564
|
528 It simply calls the real state computation function `vc-BACKEND-state'
|
|
529 and does not employ any heuristic at all."
|
31382
|
530 (vc-call-backend backend 'state file))
|
12252
|
531
|
47226
|
532 (defun vc-workfile-unchanged-p (file)
|
|
533 "Return non-nil if FILE has not changed since the last checkout."
|
|
534 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
|
|
535 (lastmod (nth 5 (file-attributes file))))
|
97788
|
536 ;; This is a shortcut for determining when the workfile is
|
|
537 ;; unchanged. It can fail under some circumstances; see the
|
|
538 ;; discussion in bug#694.
|
|
539 (if (and checkout-time
|
|
540 ;; Tramp and Ange-FTP return this when they don't know the time.
|
|
541 (not (equal lastmod '(0 0))))
|
|
542 (equal checkout-time lastmod)
|
|
543 (let ((unchanged (vc-call workfile-unchanged-p file)))
|
|
544 (vc-file-setprop file 'vc-checkout-time (if unchanged lastmod 0))
|
|
545 unchanged))))
|
47226
|
546
|
|
547 (defun vc-default-workfile-unchanged-p (backend file)
|
|
548 "Check if FILE is unchanged by diffing against the master version.
|
|
549 Return non-nil if FILE is unchanged."
|
54783
|
550 (zerop (condition-case err
|
54561
|
551 ;; If the implementation supports it, let the output
|
|
552 ;; go to *vc*, not *vc-diff*, since this is an internal call.
|
94805
|
553 (vc-call-backend backend 'diff (list file) nil nil "*vc*")
|
54783
|
554 (wrong-number-of-arguments
|
|
555 ;; If this error came from the above call to vc-BACKEND-diff,
|
|
556 ;; try again without the optional buffer argument (for
|
|
557 ;; backward compatibility). Otherwise, resignal.
|
|
558 (if (or (not (eq (cadr err)
|
|
559 (indirect-function
|
94805
|
560 (vc-find-backend-function backend 'diff))))
|
55099
|
561 (not (eq (caddr err) 4)))
|
|
562 (signal (car err) (cdr err))
|
94805
|
563 (vc-call-backend backend 'diff (list file)))))))
|
47226
|
564
|
85139
|
565 (defun vc-working-revision (file)
|
81958
|
566 "Return the repository version from which FILE was checked out.
|
42021
ddb97861a688
(vc-checkout-model, vc-state, vc-workfile-version): Return nil if
André Spiegel <spiegel@gnu.org>
diff
changeset
|
567 If FILE is not registered, this function always returns nil."
|
85139
|
568 (or (vc-file-getprop file 'vc-working-revision)
|
94805
|
569 (let ((backend (vc-backend file)))
|
|
570 (when backend
|
|
571 (vc-file-setprop file 'vc-working-revision
|
|
572 (vc-call-backend backend 'working-revision file))))))
|
94207
|
573
|
85319
|
574 ;; Backward compatibility.
|
|
575 (define-obsolete-function-alias
|
|
576 'vc-workfile-version 'vc-working-revision "23.1")
|
|
577 (defun vc-default-working-revision (backend file)
|
|
578 (message
|
|
579 "`working-revision' not found: using the old `workfile-version' instead")
|
|
580 (vc-call-backend backend 'workfile-version file))
|
11598
|
581
|
31382
|
582 (defun vc-default-registered (backend file)
|
|
583 "Check if FILE is registered in BACKEND using vc-BACKEND-master-templates."
|
|
584 (let ((sym (vc-make-backend-sym backend 'master-templates)))
|
|
585 (unless (get backend 'vc-templates-grabbed)
|
|
586 (put backend 'vc-templates-grabbed t)
|
|
587 (set sym (append (delq nil
|
|
588 (mapcar
|
|
589 (lambda (template)
|
|
590 (and (consp template)
|
|
591 (eq (cdr template) backend)
|
|
592 (car template)))
|
52051
3507a2fac9b5
(vc-default-registered, vc-make-version-backup): Use with-no-warnings.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
593 (with-no-warnings
|
3507a2fac9b5
(vc-default-registered, vc-make-version-backup): Use with-no-warnings.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
594 vc-master-templates)))
|
31382
|
595 (symbol-value sym))))
|
|
596 (let ((result (vc-check-master-templates file (symbol-value sym))))
|
|
597 (if (stringp result)
|
|
598 (vc-file-setprop file 'vc-name result)
|
|
599 nil)))) ; Not registered
|
904
|
600
|
31382
|
601 (defun vc-possible-master (s dirname basename)
|
|
602 (cond
|
|
603 ((stringp s) (format s dirname basename))
|
|
604 ((functionp s)
|
|
605 ;; The template is a function to invoke. If the
|
|
606 ;; function returns non-nil, that means it has found a
|
|
607 ;; master. For backward compatibility, we also handle
|
|
608 ;; the case that the function throws a 'found atom
|
|
609 ;; and a pair (cons MASTER-FILE BACKEND).
|
|
610 (let ((result (catch 'found (funcall s dirname basename))))
|
|
611 (if (consp result) (car result) result)))))
|
21232
b682a769996d
(vc-sccs-project-dir, vc-search-sccs-project-dir): New functions.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
612
|
31382
|
613 (defun vc-check-master-templates (file templates)
|
42021
ddb97861a688
(vc-checkout-model, vc-state, vc-workfile-version): Return nil if
André Spiegel <spiegel@gnu.org>
diff
changeset
|
614 "Return non-nil if there is a master corresponding to FILE.
|
31382
|
615
|
|
616 TEMPLATES is a list of strings or functions. If an element is a
|
|
617 string, it must be a control string as required by `format', with two
|
|
618 string placeholders, such as \"%sRCS/%s,v\". The directory part of
|
|
619 FILE is substituted for the first placeholder, the basename of FILE
|
|
620 for the second. If a file with the resulting name exists, it is taken
|
|
621 as the master of FILE, and returned.
|
9248
|
622
|
31382
|
623 If an element of TEMPLATES is a function, it is called with the
|
|
624 directory part and the basename of FILE as arguments. It should
|
|
625 return non-nil if it finds a master; that value is then returned by
|
|
626 this function."
|
|
627 (let ((dirname (or (file-name-directory file) ""))
|
|
628 (basename (file-name-nondirectory file)))
|
|
629 (catch 'found
|
31564
|
630 (mapcar
|
31382
|
631 (lambda (s)
|
|
632 (let ((trial (vc-possible-master s dirname basename)))
|
94207
|
633 (when (and trial (file-exists-p trial)
|
|
634 ;; Make sure the file we found with name
|
|
635 ;; TRIAL is not the source file itself.
|
|
636 ;; That can happen with RCS-style names if
|
|
637 ;; the file name is truncated (e.g. to 14
|
|
638 ;; chars). See if either directory or
|
|
639 ;; attributes differ.
|
|
640 (or (not (string= dirname
|
|
641 (file-name-directory trial)))
|
|
642 (not (equal (file-attributes file)
|
|
643 (file-attributes trial)))))
|
31382
|
644 (throw 'found trial))))
|
|
645 templates))))
|
11598
|
646
|
10176
|
647 (defun vc-toggle-read-only (&optional verbose)
|
2620
|
648 "Change read-only status of current buffer, perhaps via version control.
|
46453
|
649
|
2620
|
650 If the buffer is visiting a file registered with version control,
|
94548
|
651 throw an error, because this is not a safe or really meaningful operation
|
|
652 on any version-control system newer than RCS.
|
94540
55cb4c49dc98
The day wehen vc-toggle-ready-only was a good idea is long gone.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
653
|
55cb4c49dc98
The day wehen vc-toggle-ready-only was a good idea is long gone.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
654 Otherwise, just change the read-only flag of the buffer.
|
46453
|
655
|
94540
55cb4c49dc98
The day wehen vc-toggle-ready-only was a good idea is long gone.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
656 If you bind this function to \\[toggle-read-only], then Emacs
|
55cb4c49dc98
The day wehen vc-toggle-ready-only was a good idea is long gone.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
657 will properly intercept all attempts to toggle the read-only flag
|
55cb4c49dc98
The day wehen vc-toggle-ready-only was a good idea is long gone.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
658 on version-controlled buffer."
|
10176
|
659 (interactive "P")
|
94540
55cb4c49dc98
The day wehen vc-toggle-ready-only was a good idea is long gone.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
660 (if (vc-backend buffer-file-name)
|
55cb4c49dc98
The day wehen vc-toggle-ready-only was a good idea is long gone.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
661 (error "Toggling the readability of a version controlled file is likely to wreak havoc.")
|
904
|
662 (toggle-read-only)))
|
|
663
|
32746
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
664 (defun vc-default-make-version-backups-p (backend file)
|
42021
ddb97861a688
(vc-checkout-model, vc-state, vc-workfile-version): Return nil if
André Spiegel <spiegel@gnu.org>
diff
changeset
|
665 "Return non-nil if unmodified versions should be backed up locally.
|
41956
|
666 The default is to switch off this feature."
|
32127
|
667 nil)
|
|
668
|
32746
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
669 (defun vc-version-backup-file-name (file &optional rev manual regexp)
|
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
670 "Return a backup file name for REV or the current version of FILE.
|
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
671 If MANUAL is non-nil it means that a name for backups created by
|
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
672 the user should be returned; if REGEXP is non-nil that means to return
|
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
673 a regexp for matching all such backup files, regardless of the version."
|
32949
78fabc2762c4
(vc-version-backup-file-name): Use file.~<rev>~ for manual backups and
André Spiegel <spiegel@gnu.org>
diff
changeset
|
674 (if regexp
|
78fabc2762c4
(vc-version-backup-file-name): Use file.~<rev>~ for manual backups and
André Spiegel <spiegel@gnu.org>
diff
changeset
|
675 (concat (regexp-quote (file-name-nondirectory file))
|
74939
|
676 "\\.~.+" (unless manual "\\.") "~")
|
47918
|
677 (expand-file-name (concat (file-name-nondirectory file)
|
74939
|
678 ".~" (subst-char-in-string
|
85139
|
679 ?/ ?_ (or rev (vc-working-revision file)))
|
32949
78fabc2762c4
(vc-version-backup-file-name): Use file.~<rev>~ for manual backups and
André Spiegel <spiegel@gnu.org>
diff
changeset
|
680 (unless manual ".") "~")
|
78fabc2762c4
(vc-version-backup-file-name): Use file.~<rev>~ for manual backups and
André Spiegel <spiegel@gnu.org>
diff
changeset
|
681 (file-name-directory file))))
|
32746
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
682
|
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
683 (defun vc-delete-automatic-version-backups (file)
|
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
684 "Delete all existing automatic version backups for FILE."
|
39389
|
685 (condition-case nil
|
82849
|
686 (mapc
|
39389
|
687 'delete-file
|
39417
|
688 (directory-files (or (file-name-directory file) default-directory) t
|
39389
|
689 (vc-version-backup-file-name file nil nil t)))
|
|
690 ;; Don't fail when the directory doesn't exist.
|
|
691 (file-error nil)))
|
32746
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
692
|
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
693 (defun vc-make-version-backup (file)
|
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
694 "Make a backup copy of FILE, which is assumed in sync with the repository.
|
033bb57afe0c
(vc-version-backup-file-name): New optional args MANUAL and REGEXP.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
695 Before doing that, check if there are any old backups and get rid of them."
|
32953
3632d408929e
(vc-make-version-backup): Don't do it on MS-DOS without long file
André Spiegel <spiegel@gnu.org>
diff
changeset
|
696 (unless (and (fboundp 'msdos-long-file-names)
|
52385
|
697 (not (with-no-warnings (msdos-long-file-names))))
|
32953
3632d408929e
(vc-make-version-backup): Don't do it on MS-DOS without long file
André Spiegel <spiegel@gnu.org>
diff
changeset
|
698 (vc-delete-automatic-version-backups file)
|
59978
|
699 (condition-case nil
|
|
700 (copy-file file (vc-version-backup-file-name file)
|
|
701 nil 'keep-date)
|
|
702 ;; It's ok if it doesn't work (e.g. directory not writable),
|
|
703 ;; since this is just for efficiency.
|
59996
|
704 (file-error
|
59978
|
705 (message
|
|
706 (concat "Warning: Cannot make version backup; "
|
|
707 "diff/revert therefore not local"))))))
|
32127
|
708
|
|
709 (defun vc-before-save ()
|
|
710 "Function to be called by `basic-save-buffer' (in files.el)."
|
|
711 ;; If the file on disk is still in sync with the repository,
|
|
712 ;; and version backups should be made, copy the file to
|
|
713 ;; another name. This enables local diffs and local reverting.
|
94481
|
714 (let ((file buffer-file-name)
|
|
715 backend)
|
93316
709d31efe571
(vc-before-save): Be careful not to prevent saving the file.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
716 (ignore-errors ;Be careful not to prevent saving the file.
|
94481
|
717 (and (setq backend (vc-backend file))
|
93316
709d31efe571
(vc-before-save): Be careful not to prevent saving the file.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
718 (vc-up-to-date-p file)
|
94563
a0bb8ca25a33
Clean up vc*-revision-granularity and vc*-checkout-model.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
719 (eq (vc-checkout-model backend (list file)) 'implicit)
|
94805
|
720 (vc-call-backend backend 'make-version-backups-p file)
|
93316
709d31efe571
(vc-before-save): Be careful not to prevent saving the file.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
721 (vc-make-version-backup file)))))
|
32127
|
722
|
96203
|
723 (declare-function vc-dir-resynch-file "vc-dir" (&optional fname))
|
86234
860a7a8e779e
* progmodes/octave-mod.el (inferior-octave-send-list-and-digest):
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
724
|
12914
|
725 (defun vc-after-save ()
|
31382
|
726 "Function to be called by `basic-save-buffer' (in files.el)."
|
31564
|
727 ;; If the file in the current buffer is under version control,
|
31382
|
728 ;; up-to-date, and locking is not used for the file, set
|
|
729 ;; the state to 'edited and redisplay the mode line.
|
94481
|
730 (let* ((file buffer-file-name)
|
|
731 (backend (vc-backend file)))
|
|
732 (and backend
|
12967
|
733 (or (and (equal (vc-file-getprop file 'vc-checkout-time)
|
|
734 (nth 5 (file-attributes file)))
|
|
735 ;; File has been saved in the same second in which
|
|
736 ;; it was checked out. Clear the checkout-time
|
|
737 ;; to avoid confusion.
|
|
738 (vc-file-setprop file 'vc-checkout-time nil))
|
|
739 t)
|
31382
|
740 (vc-up-to-date-p file)
|
94563
a0bb8ca25a33
Clean up vc*-revision-granularity and vc*-checkout-model.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
741 (eq (vc-checkout-model backend (list file)) 'implicit)
|
31382
|
742 (vc-file-setprop file 'vc-state 'edited)
|
|
743 (vc-mode-line file)
|
95338
|
744 ;; Try to avoid unnecessary work, a *vc-dir* buffer is only
|
|
745 ;; present if this is true.
|
|
746 (when (memq 'vc-dir-resynch-file after-save-hook)
|
|
747 (vc-dir-resynch-file file)))))
|
12884
f47248851f26
(vc-fetch-master-properties): Recognize cvs status "Unresolved Conflict".
André Spiegel <spiegel@gnu.org>
diff
changeset
|
748
|
78822
|
749 (defvar vc-menu-entry
|
|
750 '(menu-item "Version Control" vc-menu-map
|
|
751 :filter vc-menu-map-filter))
|
|
752
|
|
753 (when (boundp 'menu-bar-tools-menu)
|
|
754 ;; We do not need to worry here about the placement of this entry
|
|
755 ;; because menu-bar.el has already created the proper spot for us
|
|
756 ;; and this will simply use it.
|
|
757 (define-key menu-bar-tools-menu [vc] vc-menu-entry))
|
|
758
|
|
759 (defconst vc-mode-line-map
|
|
760 (let ((map (make-sparse-keymap)))
|
|
761 (define-key map [mode-line down-mouse-1] vc-menu-entry)
|
|
762 map))
|
|
763
|
31382
|
764 (defun vc-mode-line (file)
|
2491
|
765 "Set `vc-mode' to display type of version control for FILE.
|
904
|
766 The value is set in the current buffer, which should be the buffer
|
31382
|
767 visiting FILE."
|
32188
|
768 (interactive (list buffer-file-name))
|
50879
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
769 (let ((backend (vc-backend file)))
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
770 (if (not backend)
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
771 (setq vc-mode nil)
|
94805
|
772 (let* ((ml-string (vc-call-backend backend 'mode-line-string file))
|
82070
|
773 (ml-echo (get-text-property 0 'help-echo ml-string)))
|
|
774 (setq vc-mode
|
|
775 (concat
|
|
776 " "
|
|
777 (if (null vc-display-status)
|
|
778 (symbol-name backend)
|
|
779 (propertize
|
|
780 ml-string
|
|
781 'mouse-face 'mode-line-highlight
|
91584
|
782 'help-echo
|
82070
|
783 (concat (or ml-echo
|
|
784 (format "File under the %s version control system"
|
|
785 backend))
|
|
786 "\nmouse-1: Version Control menu")
|
|
787 'local-map vc-mode-line-map)))))
|
50879
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
788 ;; If the file is locked by some other user, make
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
789 ;; the buffer read-only. Like this, even root
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
790 ;; cannot modify a file that someone else has locked.
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
791 (and (equal file buffer-file-name)
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
792 (stringp (vc-state file))
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
793 (setq buffer-read-only t))
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
794 ;; If the user is root, and the file is not owner-writable,
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
795 ;; then pretend that we can't write it
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
796 ;; even though we can (because root can write anything).
|
95338
|
797 ;; This way, even root cannot modify a file that isn't locked.
|
|
798 (and (equal file buffer-file-name)
|
|
799 (not buffer-read-only)
|
50879
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
800 (zerop (user-real-uid))
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
801 (zerop (logand (file-modes buffer-file-name) 128))
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
802 (setq buffer-read-only t)))
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
803 (force-mode-line-update)
|
9cd7a1a60ba0
Consistently use buffer-file-name variable rather than function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
804 backend))
|
31382
|
805
|
|
806 (defun vc-default-mode-line-string (backend file)
|
|
807 "Return string for placement in modeline by `vc-mode-line' for FILE.
|
|
808 Format:
|
|
809
|
|
810 \"BACKEND-REV\" if the file is up-to-date
|
|
811 \"BACKEND:REV\" if the file is edited (or locked by the calling user)
|
|
812 \"BACKEND:LOCKER:REV\" if the file is locked by somebody else
|
904
|
813
|
31382
|
814 This function assumes that the file is registered."
|
|
815 (setq backend (symbol-name backend))
|
|
816 (let ((state (vc-state file))
|
81815
|
817 (state-echo nil)
|
85139
|
818 (rev (vc-working-revision file)))
|
81815
|
819 (propertize
|
|
820 (cond ((or (eq state 'up-to-date)
|
94521
|
821 (eq state 'needs-update))
|
81815
|
822 (setq state-echo "Up to date file")
|
|
823 (concat backend "-" rev))
|
|
824 ((stringp state)
|
|
825 (setq state-echo (concat "File locked by" state))
|
|
826 (concat backend ":" state ":" rev))
|
93124
97c5b398eee4
* vc-hooks.el (vc-default-mode-line-string): Add case for added files.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
827 ((eq state 'added)
|
97c5b398eee4
* vc-hooks.el (vc-default-mode-line-string): Add case for added files.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
828 (setq state-echo "Locally added file")
|
97c5b398eee4
* vc-hooks.el (vc-default-mode-line-string): Add case for added files.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
829 (concat backend "@" rev))
|
93956
|
830 ((eq state 'conflict)
|
|
831 (setq state-echo "File contains conflicts after the last merge")
|
|
832 (concat backend "!" rev))
|
93239
|
833 ((eq state 'removed)
|
|
834 (setq state-echo "File removed from the VC system")
|
|
835 (concat backend "!" rev))
|
|
836 ((eq state 'missing)
|
|
837 (setq state-echo "File tracked by the VC system, but missing from the file system")
|
93940
|
838 (concat backend "?" rev))
|
81815
|
839 (t
|
|
840 ;; Not just for the 'edited state, but also a fallback
|
|
841 ;; for all other states. Think about different symbols
|
94521
|
842 ;; for 'needs-update and 'needs-merge.
|
82027
1350ba0c0448
* vc-cvs.el (vc-cvs-mode-line-string): Add support for tooltips
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
843 (setq state-echo "Locally modified file")
|
81815
|
844 (concat backend ":" rev)))
|
82058
|
845 'help-echo (concat state-echo " under the " backend
|
82027
1350ba0c0448
* vc-cvs.el (vc-cvs-mode-line-string): Add support for tooltips
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
846 " version control system"))))
|
11598
|
847
|
14647
|
848 (defun vc-follow-link ()
|
31382
|
849 "If current buffer visits a symbolic link, visit the real file.
|
|
850 If the real file is already visited in another buffer, make that buffer
|
|
851 current, and kill the buffer that visits the link."
|
99788
|
852 (let* ((true-buffer (find-buffer-visiting buffer-file-truename))
|
14673
|
853 (this-buffer (current-buffer)))
|
|
854 (if (eq true-buffer this-buffer)
|
99840
|
855 (let ((truename buffer-file-truename))
|
14674
|
856 (kill-buffer this-buffer)
|
14673
|
857 ;; In principle, we could do something like set-visited-file-name.
|
|
858 ;; However, it can't be exactly the same as set-visited-file-name.
|
|
859 ;; I'm not going to work out the details right now. -- rms.
|
14674
|
860 (set-buffer (find-file-noselect truename)))
|
14673
|
861 (set-buffer true-buffer)
|
|
862 (kill-buffer this-buffer))))
|
14647
|
863
|
54397
|
864 (defun vc-default-find-file-hook (backend)
|
|
865 nil)
|
|
866
|
904
|
867 (defun vc-find-file-hook ()
|
50880
c4ef9b4c327f
(find-file-hook, find-file-not-found-hook): Don't use the old ...-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
868 "Function for `find-file-hook' activating VC mode if appropriate."
|
2218
|
869 ;; Recompute whether file is version controlled,
|
|
870 ;; if user has killed the buffer and revisited.
|
43449
|
871 (if vc-mode
|
|
872 (setq vc-mode nil))
|
31382
|
873 (when buffer-file-name
|
11598
|
874 (vc-file-clearprops buffer-file-name)
|
94692
|
875 (add-hook 'mode-line-hook 'vc-mode-line nil t)
|
11598
|
876 (cond
|
81834
|
877 ((with-demoted-errors (vc-backend buffer-file-name))
|
51370
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
878 ;; Compute the state and put it in the modeline.
|
11598
|
879 (vc-mode-line buffer-file-name)
|
51370
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
880 (unless vc-make-backup-files
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
881 ;; Use this variable, not make-backup-files,
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
882 ;; because this is for things that depend on the file name.
|
54397
|
883 (set (make-local-variable 'backup-inhibited) t))
|
|
884 ;; Let the backend setup any buffer-local things he needs.
|
|
885 (vc-call-backend (vc-backend buffer-file-name) 'find-file-hook))
|
99788
|
886 ((let ((link-type (and (not (equal buffer-file-name buffer-file-truename))
|
|
887 (vc-backend buffer-file-truename))))
|
51370
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
888 (cond ((not link-type) nil) ;Nothing to do.
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
889 ((eq vc-follow-symlinks nil)
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
890 (message
|
14142
|
891 "Warning: symbolic link to %s-controlled source file" link-type))
|
51370
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
892 ((or (not (eq vc-follow-symlinks 'ask))
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
893 ;; If we already visited this file by following
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
894 ;; the link, don't ask again if we try to visit
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
895 ;; it again. GUD does that, and repeated questions
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
896 ;; are painful.
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
897 (get-file-buffer
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
898 (abbreviate-file-name
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
899 (file-chase-links buffer-file-name))))
|
47918
|
900
|
51370
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
901 (vc-follow-link)
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
902 (message "Followed link to %s" buffer-file-name)
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
903 (vc-find-file-hook))
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
904 (t
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
905 (if (yes-or-no-p (format
|
14142
|
906 "Symbolic link to %s-controlled source file; follow link? " link-type))
|
51370
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
907 (progn (vc-follow-link)
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
908 (message "Followed link to %s" buffer-file-name)
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
909 (vc-find-file-hook))
|
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
910 (message
|
14142
|
911 "Warning: editing through the link bypasses version control")
|
51370
a7a449bb9443
(vc-call-backend): Give better error message when backend function is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
912 ))))))))
|
904
|
913
|
50880
c4ef9b4c327f
(find-file-hook, find-file-not-found-hook): Don't use the old ...-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
914 (add-hook 'find-file-hook 'vc-find-file-hook)
|
904
|
915
|
38373
|
916 ;; more hooks, this time for file-not-found
|
904
|
917 (defun vc-file-not-found-hook ()
|
31382
|
918 "When file is not found, try to check it out from version control.
|
|
919 Returns t if checkout was successful, nil otherwise.
|
52055
|
920 Used in `find-file-not-found-functions'."
|
22947
|
921 ;; When a file does not exist, ignore cached info about it
|
|
922 ;; from a previous visit.
|
98429
b87cc3b45aa5
* vc-hooks.el (vc-file-clearprops): Revert change from 2008-09-29.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
923 ;; We check that `buffer-file-name' is non-nil. It should be always
|
b87cc3b45aa5
* vc-hooks.el (vc-file-clearprops): Revert change from 2008-09-29.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
924 ;; the case, but in conjunction with Tramp, it might be nil. M. Albinus.
|
b87cc3b45aa5
* vc-hooks.el (vc-file-clearprops): Revert change from 2008-09-29.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
925 (when buffer-file-name
|
b87cc3b45aa5
* vc-hooks.el (vc-file-clearprops): Revert change from 2008-09-29.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
926 (vc-file-clearprops buffer-file-name)
|
b87cc3b45aa5
* vc-hooks.el (vc-file-clearprops): Revert change from 2008-09-29.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
927 (let ((backend (vc-backend buffer-file-name)))
|
b87cc3b45aa5
* vc-hooks.el (vc-file-clearprops): Revert change from 2008-09-29.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
928 (when backend (vc-call-backend backend 'find-file-not-found-hook)))))
|
54529
|
929
|
|
930 (defun vc-default-find-file-not-found-hook (backend)
|
78520
|
931 ;; This used to do what vc-rcs-find-file-not-found-hook does, but it only
|
|
932 ;; really makes sense for RCS. For other backends, better not do anything.
|
|
933 nil)
|
904
|
934
|
52051
3507a2fac9b5
(vc-default-registered, vc-make-version-backup): Use with-no-warnings.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
935 (add-hook 'find-file-not-found-functions 'vc-file-not-found-hook)
|
904
|
936
|
11598
|
937 (defun vc-kill-buffer-hook ()
|
31382
|
938 "Discard VC info about a file when we kill its buffer."
|
94207
|
939 (when buffer-file-name (vc-file-clearprops buffer-file-name)))
|
11598
|
940
|
47003
|
941 (add-hook 'kill-buffer-hook 'vc-kill-buffer-hook)
|
11598
|
942
|
38373
|
943 ;; Now arrange for (autoloaded) bindings of the main package.
|
|
944 ;; Bindings for this have to go in the global map, as we'll often
|
|
945 ;; want to call them from random buffers.
|
904
|
946
|
38373
|
947 ;; Autoloading works fine, but it prevents shortcuts from appearing
|
|
948 ;; in the menu because they don't exist yet when the menu is built.
|
|
949 ;; (autoload 'vc-prefix-map "vc" nil nil 'keymap)
|
|
950 (defvar vc-prefix-map
|
|
951 (let ((map (make-sparse-keymap)))
|
|
952 (define-key map "a" 'vc-update-change-log)
|
|
953 (define-key map "b" 'vc-switch-backend)
|
81958
|
954 (define-key map "c" 'vc-rollback)
|
94106
9294e3bd7d46
Rename vc-status to vc-dir and the vc-status var to vc-ewoc.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
955 (define-key map "d" 'vc-dir)
|
38373
|
956 (define-key map "g" 'vc-annotate)
|
|
957 (define-key map "h" 'vc-insert-headers)
|
|
958 (define-key map "i" 'vc-register)
|
|
959 (define-key map "l" 'vc-print-log)
|
|
960 (define-key map "m" 'vc-merge)
|
95020
4da572dc4992
Snapshot primitives globally renamed to refer to tags, documentation updated.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
961 (define-key map "r" 'vc-retrieve-tag)
|
4da572dc4992
Snapshot primitives globally renamed to refer to tags, documentation updated.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
962 (define-key map "s" 'vc-create-tag)
|
81958
|
963 (define-key map "u" 'vc-revert)
|
38373
|
964 (define-key map "v" 'vc-next-action)
|
81958
|
965 (define-key map "+" 'vc-update)
|
38373
|
966 (define-key map "=" 'vc-diff)
|
85169
708abc311fa6
Follow through on the VC terminology change (version -> revision).
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
967 (define-key map "~" 'vc-revision-other-window)
|
38373
|
968 map))
|
|
969 (fset 'vc-prefix-map vc-prefix-map)
|
31382
|
970 (define-key global-map "\C-xv" 'vc-prefix-map)
|
8982
|
971
|
78822
|
972 (defvar vc-menu-map
|
|
973 (let ((map (make-sparse-keymap "Version Control")))
|
|
974 ;;(define-key map [show-files]
|
|
975 ;; '("Show Files under VC" . (vc-directory t)))
|
95020
4da572dc4992
Snapshot primitives globally renamed to refer to tags, documentation updated.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
976 (define-key map [vc-retrieve-tag]
|
4da572dc4992
Snapshot primitives globally renamed to refer to tags, documentation updated.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
977 '(menu-item "Retrieve Tag" vc-retrieve-tag
|
4da572dc4992
Snapshot primitives globally renamed to refer to tags, documentation updated.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
978 :help "Retrieve tagged version or branch"))
|
4da572dc4992
Snapshot primitives globally renamed to refer to tags, documentation updated.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
979 (define-key map [vc-create-tag]
|
4da572dc4992
Snapshot primitives globally renamed to refer to tags, documentation updated.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
980 '(menu-item "Create Tag" vc-create-tag
|
4da572dc4992
Snapshot primitives globally renamed to refer to tags, documentation updated.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
981 :help "Create version tag"))
|
78822
|
982 (define-key map [separator1] '("----"))
|
91954
|
983 (define-key map [vc-annotate]
|
91855
|
984 '(menu-item "Annotate" vc-annotate
|
|
985 :help "Display the edit history of the current file using colors"))
|
91954
|
986 (define-key map [vc-rename-file]
|
91855
|
987 '(menu-item "Rename File" vc-rename-file
|
|
988 :help "Rename file"))
|
85169
708abc311fa6
Follow through on the VC terminology change (version -> revision).
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
989 (define-key map [vc-revision-other-window]
|
91855
|
990 '(menu-item "Show Other Version" vc-revision-other-window
|
|
991 :help "Visit another version of the current file in another window"))
|
91954
|
992 (define-key map [vc-diff]
|
91855
|
993 '(menu-item "Compare with Base Version" vc-diff
|
|
994 :help "Compare file set with the base version"))
|
78822
|
995 (define-key map [vc-update-change-log]
|
91855
|
996 '(menu-item "Update ChangeLog" vc-update-change-log
|
|
997 :help "Find change log file and add entries from recent version control logs"))
|
91954
|
998 (define-key map [vc-print-log]
|
91855
|
999 '(menu-item "Show History" vc-print-log
|
|
1000 :help "List the change log of the current file set in a window"))
|
78822
|
1001 (define-key map [separator2] '("----"))
|
|
1002 (define-key map [vc-insert-header]
|
91855
|
1003 '(menu-item "Insert Header" vc-insert-headers
|
|
1004 :help "Insert headers into a file for use with a version control system.
|
|
1005 "))
|
91954
|
1006 (define-key map [undo]
|
91855
|
1007 '(menu-item "Undo Last Check-In" vc-rollback
|
|
1008 :help "Remove the most recent changeset committed to the repository"))
|
82499
|
1009 (define-key map [vc-revert]
|
91855
|
1010 '(menu-item "Revert to Base Version" vc-revert
|
|
1011 :help "Revert working copies of the selected file set to their repository contents"))
|
78822
|
1012 (define-key map [vc-update]
|
91855
|
1013 '(menu-item "Update to Latest Version" vc-update
|
|
1014 :help "Update the current fileset's files to their tip revisions"))
|
91954
|
1015 (define-key map [vc-next-action]
|
91855
|
1016 '(menu-item "Check In/Out" vc-next-action
|
|
1017 :help "Do the next logical version control operation on the current fileset"))
|
91954
|
1018 (define-key map [vc-register]
|
91855
|
1019 '(menu-item "Register" vc-register
|
|
1020 :help "Register file set into a version control system"))
|
94106
9294e3bd7d46
Rename vc-status to vc-dir and the vc-status var to vc-ewoc.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1021 (define-key map [vc-dir]
|
9294e3bd7d46
Rename vc-status to vc-dir and the vc-status var to vc-ewoc.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1022 '(menu-item "VC Dir" vc-dir
|
93956
|
1023 :help "Show the VC status of files in a directory"))
|
78822
|
1024 map))
|
|
1025
|
|
1026 (defalias 'vc-menu-map vc-menu-map)
|
|
1027
|
93501
|
1028 (declare-function vc-responsible-backend "vc" (file &optional register))
|
|
1029
|
78822
|
1030 (defun vc-menu-map-filter (orig-binding)
|
|
1031 (if (and (symbolp orig-binding) (fboundp orig-binding))
|
|
1032 (setq orig-binding (indirect-function orig-binding)))
|
|
1033 (let ((ext-binding
|
93381
|
1034 (when vc-mode
|
93501
|
1035 (vc-call-backend
|
93381
|
1036 (if buffer-file-name
|
|
1037 (vc-backend buffer-file-name)
|
|
1038 (vc-responsible-backend default-directory))
|
|
1039 'extra-menu))))
|
78822
|
1040 ;; Give the VC backend a chance to add menu entries
|
|
1041 ;; specific for that backend.
|
|
1042 (if (null ext-binding)
|
|
1043 orig-binding
|
|
1044 (append orig-binding
|
|
1045 '((ext-menu-separator "---"))
|
|
1046 ext-binding))))
|
|
1047
|
|
1048 (defun vc-default-extra-menu (backend)
|
|
1049 nil)
|
14622
|
1050
|
904
|
1051 (provide 'vc-hooks)
|
|
1052
|
57079
|
1053 ;; arch-tag: 2e5a6fa7-1d30-48e2-8bd0-e3d335f04f32
|
904
|
1054 ;;; vc-hooks.el ends here
|