Mercurial > emacs
annotate lisp/vc.el @ 1717:aa7d6d57504b
* frame.h (struct frame): New fields `can_have_scrollbars' and
`has_vertical_scrollbars'.
(FRAME_CAN_HAVE_SCROLLBARS, FRAME_HAS_VERTICAL_SCROLLBARS): New
accessors, for both the MULTI_FRAME and non-MULTI_FRAME.
(VERTICAL_SCROLLBAR_WIDTH, WINDOW_VERTICAL_SCROLLBAR,
WINDOW_VERTICAL_SCROLLBAR_COLUMN,
WINDOW_VERTICAL_SCROLLBAR_HEIGHT): New macros.
* window.h (struct window): New field `vertical_scrollbar'.
* xterm.h (struct x_display): vertical_scrollbars,
judge_timestamp, vertical_scrollbar_extra: New fields.
(struct scrollbar): New struct.
(VERTICAL_SCROLLBAR_PIXEL_WIDTH, VERTICAL_SCROLLBAR_PIXEL_HEIGHT,
VERTICAL_SCROLLBAR_LEFT_BORDER, VERTICAL_SCROLLBAR_RIGHT_BORDER,
VERTICAL_SCROLLBAR_TOP_BORDER, VERTICAL_SCROLLBAR_BOTTOM_BORDER,
CHAR_TO_PIXEL_WIDTH, CHAR_TO_PIXEL_HEIGHT, PIXEL_TO_CHAR_WIDTH,
PIXEL_TO_CHAR_HEIGHT): New accessors and macros.
* frame.c (make_frame): Initialize the `can_have_scrollbars' and
`has_vertical_scrollbars' fields of the frame.
* term.c (term_init): Note that TERMCAP terminals don't support
scrollbars.
(mouse_position_hook): Document new args.
(set_vertical_scrollbar_hook, condemn_scrollbars_hook,
redeem_scrollbar_hook, judge_scrollbars_hook): New hooks.
* termhooks.h: Declare and document them.
(enum scrollbar_part): New type.
(struct input_event): Describe the new form of the scrollbar_click
event type. Change `part' from a Lisp_Object to an enum
scrollbar_part. Add a new field `scrollbar'.
* keyboard.c (kbd_buffer_get_event): Pass appropriate new
parameters to *mouse_position_hook, and make_lispy_movement.
* xfns.c (x_set_vertical_scrollbar): New function.
(x_figure_window_size): Use new macros to calculate frame size.
(Fx_create_frame): Note that X Windows frames do support scroll
bars. Default to "yes".
* xterm.c: #include <X11/cursorfont.h> and "window.h".
(x_vertical_scrollbar_cursor): New variable.
(x_term_init): Initialize it.
(last_mouse_bar, last_mouse_bar_frame, last_mouse_part,
last_mouse_scroll_range_start, last_mouse_scroll_range_end): New
variables.
(XTmouse_position): Use them to return scrollbar movement events.
Take new arguments, for that purpose.
(x_window_to_scrollbar, x_scrollbar_create,
x_scrollbar_set_handle, x_scrollbar_remove, x_scrollbar_move,
XTset_scrollbar, XTcondemn_scrollbars, XTredeem_scrollbar,
XTjudge_scrollbars, x_scrollbar_expose,
x_scrollbar_background_expose, x_scrollbar_handle_click,
x_scrollbar_handle_motion): New functions to implement scrollbars.
(x_term_init): Set the termhooks.h hooks to point to them.
(x_set_window_size): Use new macros to calculate frame size. Set
vertical_scrollbar_extra field.
(x_make_frame_visible): Use the frame accessor
FRAME_HAS_VERTICAL_SCROLLBARS to decide if we need to map the
frame's subwindows as well.
(XTread_socket): Use new size-calculation macros from xterm.h when
processing ConfigureNotify events.
(x_wm_set_size_hint): Use PIXEL_TO_CHAR_WIDTH and
PIXEL_TO_CHAR_HEIGHT macros.
* ymakefile (xdisp.o): This now depends on termhooks.h.
(xterm.o): This now depends on window.h.
| author | Jim Blandy <jimb@redhat.com> |
|---|---|
| date | Thu, 24 Dec 1992 06:17:18 +0000 |
| parents | 75e8a7f920c7 |
| children | 494dd05d460c |
| rev | line source |
|---|---|
| 904 | 1 ;;; vc.el --- drive a version-control system from within Emacs |
| 2 | |
| 3 ;; Copyright (C) 1992 Free Software Foundation, Inc. | |
| 4 | |
| 5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> | |
| 6 ;; Version: 4.0 | |
| 7 | |
|
1674
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
8 ;; $Id: vc.el,v 1.18 1992/11/20 19:33:38 rms Exp jimb $ |
| 904 | 9 |
| 10 ;; This file is part of GNU Emacs. | |
| 11 | |
| 12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 13 ;; it under the terms of the GNU General Public License as published by | |
| 14 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 15 ;; any later version. | |
| 16 | |
| 17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 ;; GNU General Public License for more details. | |
| 21 | |
| 22 ;; You should have received a copy of the GNU General Public License | |
| 23 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
| 24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 25 | |
| 26 ;;; Commentary: | |
| 27 | |
| 28 ;; This was designed and implemented by Eric Raymond <esr@snark.thyrsus.com>. | |
| 29 ;; Paul Eggert <eggert@twinsun.com>, Sebastian Kremer <sk@thp.uni-koeln.de>, | |
| 30 ;; and Richard Stallman contributed valuable criticism, support, and testing. | |
| 31 ;; | |
| 32 ;; Supported version-control systems presently include SCCS and RCS; | |
| 33 ;; your RCS version should be 5.6.2 or later for proper operation of | |
| 34 ;; the lock-breaking code. | |
| 35 ;; | |
| 36 ;; The RCS code assumes strict locking. You can support the RCS -x option | |
| 37 ;; by adding pairs to the vc-master-templates list. | |
| 38 ;; | |
| 39 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff | |
| 40 ;; to be installed somewhere on Emacs's path for executables. | |
| 41 ;; | |
| 42 ;; This code depends on call-process passing back the subprocess exit | |
| 43 ;; status. Thus, you need Emacs 18.58 or later to run it. | |
| 44 ;; | |
| 45 ;; The vc code maintains some internal state in order to reduce expensive | |
| 46 ;; version-control operations to a minimum. Some names are only computed | |
| 47 ;; once. If you perform version control operations with RCS/SCCS/CVS while | |
| 48 ;; vc's back is turned, or move/rename master files while vc is running, | |
| 49 ;; vc may get seriously confused. Don't do these things! | |
| 50 ;; | |
| 51 ;; Developer's notes on some concurrency issues are included at the end of | |
| 52 ;; the file. | |
| 53 | |
| 54 ;;; Code: | |
| 55 | |
| 56 (require 'vc-hooks) | |
| 57 | |
| 58 ;; General customization | |
| 59 | |
| 60 (defvar vc-default-back-end nil | |
| 61 "*Back-end actually used by this interface; may be SCCS or RCS. | |
| 62 The value is only computed when needed to avoid an expensive search.") | |
| 63 (defvar vc-diff-options '("-a" "-c1") | |
| 64 "*The command/flags list to be used in constructing diff commands.") | |
| 65 (defvar vc-suppress-confirm nil | |
| 66 "*If non-nil, reat user as expert; suppress yes-no prompts on some things.") | |
| 67 (defvar vc-keep-workfiles t | |
| 68 "*If non-nil, don't delete working files after registering changes.") | |
| 69 (defvar vc-initial-comment nil | |
| 70 "*Prompt for initial comment when a file is registered.") | |
| 71 (defvar vc-command-messages nil | |
| 72 "*Display run messages from back-end commands.") | |
| 73 (defvar vc-mistrust-permissions 'file-symlink-p | |
| 74 "*Don't assume that permissions and ownership track version-control status.") | |
| 75 | |
|
1335
d649d430148d
(vc-checkin-switches): New defvar.
Roland McGrath <roland@gnu.org>
parents:
1243
diff
changeset
|
76 (defvar vc-checkin-switches nil |
|
d649d430148d
(vc-checkin-switches): New defvar.
Roland McGrath <roland@gnu.org>
parents:
1243
diff
changeset
|
77 "*Extra switches passed to the checkin program by \\[vc-checkin].") |
|
d649d430148d
(vc-checkin-switches): New defvar.
Roland McGrath <roland@gnu.org>
parents:
1243
diff
changeset
|
78 |
|
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
79 ;;;###autoload |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
80 (defvar vc-checkin-hook nil |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
81 "*List of functions called after a vc-checkin is done. See `runs-hooks'.") |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
82 |
| 904 | 83 ;; Header-insertion hair |
| 84 | |
| 85 (defvar vc-header-alist | |
| 86 '((SCCS "\%W\%") (RCS "\$Id\$")) | |
| 87 "*Header keywords to be inserted when vc-insert-header is executed.") | |
| 88 (defconst vc-static-header-alist | |
| 89 '(("\\.c$" . | |
| 90 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n")) | |
| 91 "*Associate static header string templates with file types. A \%s in the | |
| 92 template is replaced with the first string associated with the file's | |
| 93 verson-control type in vc-header-strings.") | |
| 94 (defvar vc-comment-alist | |
| 95 '((nroff-mode ".\\\"" "")) | |
| 96 "*Special comment delimiters to be used in generating vc headers only. | |
| 97 Add an entry in this list if you need to override the normal comment-start | |
| 98 and comment-end variables. This will only be necessary if the mode language | |
| 99 is sensitive to blank lines.") | |
| 100 | |
| 101 ;; Variables the user doesn't need to know about. | |
| 102 (defvar vc-log-entry-mode nil) | |
| 103 (defvar vc-log-operation nil) | |
|
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
104 (defvar vc-log-after-operation-hook nil) |
| 904 | 105 |
|
1494
64f5e84c822b
(vc-admin): Pass t as noquery arg to vc-resynch-window.
Richard M. Stallman <rms@gnu.org>
parents:
1478
diff
changeset
|
106 (defvar vc-log-file) |
|
64f5e84c822b
(vc-admin): Pass t as noquery arg to vc-resynch-window.
Richard M. Stallman <rms@gnu.org>
parents:
1478
diff
changeset
|
107 (defvar vc-log-version) |
|
64f5e84c822b
(vc-admin): Pass t as noquery arg to vc-resynch-window.
Richard M. Stallman <rms@gnu.org>
parents:
1478
diff
changeset
|
108 |
| 904 | 109 (defconst vc-name-assoc-file "VC-names") |
| 110 | |
| 111 (defmacro vc-error-occurred (&rest body) | |
| 112 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t))) | |
| 113 | |
| 114 ;; File property caching | |
| 115 | |
| 116 (defun vc-file-clearprops (file) | |
| 117 ;; clear all properties of a given file | |
| 118 (setplist (intern file vc-file-prop-obarray) nil)) | |
| 119 | |
| 120 ;; Random helper functions | |
| 121 | |
| 122 (defun vc-name (file) | |
| 123 "Return the master name of a file, nil if it is not registered" | |
| 124 (or (vc-file-getprop file 'vc-name) | |
| 125 (vc-file-setprop file 'vc-name | |
| 126 (let ((name-and-type (vc-registered file))) | |
| 127 (and name-and-type (car name-and-type)))))) | |
| 128 | |
| 129 (defvar vc-binary-assoc nil) | |
| 130 | |
| 131 (defun vc-find-binary (name) | |
| 132 "Look for a command anywhere on the subprocess-command search path." | |
| 133 (or (cdr (assoc name vc-binary-assoc)) | |
| 134 (let ((full nil)) | |
| 135 (catch 'found | |
| 136 (mapcar | |
| 137 (function (lambda (s) | |
| 138 (if (and s (file-exists-p (setq full (concat s "/" name)))) | |
| 139 (throw 'found nil)))) | |
| 140 exec-path)) | |
| 141 (if full | |
| 142 (setq vc-binary-assoc (cons (cons name full) vc-binary-assoc))) | |
| 143 full))) | |
| 144 | |
| 145 (defun vc-do-command (okstatus command file &rest flags) | |
| 146 "Execute a version-control command, notifying user and checking for errors. | |
| 147 The command is successful if its exit status does not exceed OKSTATUS. | |
| 148 Output from COMMAND goes to buffer *vc*. The last argument of the command is | |
| 149 the master name of FILE; this is appended to an optional list of FLAGS." | |
| 150 (setq file (expand-file-name file)) | |
| 151 (if vc-command-messages | |
| 152 (message (format "Running %s on %s..." command file))) | |
| 153 (let ((obuf (current-buffer)) | |
| 154 (squeezed nil) | |
| 155 (vc-file (and file (vc-name file))) | |
| 156 status) | |
| 157 (set-buffer (get-buffer-create "*vc*")) | |
| 158 (erase-buffer) | |
|
1674
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
159 |
|
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
160 ;; This is so that command arguments typed in the *vc* buffer will |
|
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
161 ;; have reasonable defaults. |
|
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
162 (setq default-directory (file-name-directory file)) |
|
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
163 |
| 904 | 164 (mapcar |
| 165 (function (lambda (s) (and s (setq squeezed (append squeezed (list s)))))) | |
| 166 flags) | |
| 167 (if vc-file | |
| 168 (setq squeezed (append squeezed (list vc-file)))) | |
| 169 (let | |
| 170 ((default-directory (file-name-directory (or file "./")))) | |
| 171 (setq status (apply 'call-process command nil t nil squeezed)) | |
| 172 ) | |
| 173 (goto-char (point-max)) | |
| 174 (previous-line 1) | |
| 175 (if (or (not (integerp status)) (< okstatus status)) | |
| 176 (progn | |
| 177 (previous-line 1) | |
| 178 (print (cons command squeezed)) | |
| 179 (next-line 1) | |
| 180 (pop-to-buffer "*vc*") | |
| 181 (vc-shrink-to-fit) | |
| 182 (goto-char (point-min)) | |
| 183 (error (format "Running %s...FAILED (%s)" command | |
| 184 (if (integerp status) | |
| 185 (format "status %d" status) | |
| 186 status))) | |
| 187 ) | |
| 188 (if vc-command-messages | |
| 189 (message (format "Running %s...OK" command))) | |
| 190 ) | |
| 191 (set-buffer obuf) | |
| 192 status) | |
| 193 ) | |
| 194 | |
|
1635
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
195 ;;; Save a bit of the text around POSN in the current buffer, to help |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
196 ;;; us find the corresponding position again later. This works even |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
197 ;;; if all markers are destroyed or corrupted. |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
198 (defun vc-position-context (posn) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
199 (list posn |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
200 (buffer-size) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
201 (buffer-substring posn |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
202 (min (point-max) (+ posn 100))))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
203 |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
204 ;;; Return the position of CONTEXT in the current buffer, or nil if we |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
205 ;;; couldn't find it. |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
206 (defun vc-find-position-by-context (context) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
207 (let ((context-string (nth 2 context))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
208 (if (equal "" context-string) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
209 (point-max) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
210 (save-excursion |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
211 (let ((diff (- (nth 1 context) (buffer-size)))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
212 (if (< diff 0) (setq diff (- diff))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
213 (goto-char (nth 0 context)) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
214 (if (or (search-forward context-string nil t) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
215 ;; Can't use search-backward since the match may continue |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
216 ;; after point. |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
217 (progn (goto-char (- (point) diff (length context-string))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
218 ;; goto-char doesn't signal an error at |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
219 ;; beginning of buffer like backward-char would |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
220 (search-forward context-string nil t))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
221 ;; to beginning of OSTRING |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
222 (- (point) (length context-string)))))))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
223 |
| 904 | 224 (defun vc-revert-buffer1 (&optional arg no-confirm) |
| 225 ;; This code was shamelessly lifted from Sebastian Kremer's rcs.el mode. | |
|
1635
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
226 ;; Revert buffer, try to keep point and mark where user expects them in spite |
| 904 | 227 ;; of changes because of expanded version-control key words. |
| 228 ;; This is quite important since otherwise typeahead won't work as expected. | |
| 229 (interactive "P") | |
| 230 (widen) | |
|
1635
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
231 (let ((point-context (vc-position-context (point))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
232 (mark-context (if (mark) (vc-position-context (mark))))) |
| 904 | 233 (revert-buffer arg no-confirm) |
|
1635
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
234 (let ((new-point (vc-find-position-by-context point-context))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
235 (if new-point (goto-char new-point))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
236 (if mark-context |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
237 (let ((new-mark (vc-find-position-by-context mark-context))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
238 (if new-mark (set-mark new-mark)))))) |
|
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
239 |
| 904 | 240 |
| 241 (defun vc-buffer-sync () | |
| 242 ;; Make sure the current buffer and its working file are in sync | |
| 243 (if (and (buffer-modified-p) | |
| 244 (or | |
| 245 vc-suppress-confirm | |
| 246 (y-or-n-p (format "%s has been modified. Write it out? " | |
| 247 (buffer-name))))) | |
| 248 (save-buffer))) | |
| 249 | |
| 250 (defun vc-workfile-unchanged-p (file) | |
| 251 ;; Has the given workfile changed since last checkout? | |
| 252 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time)) | |
| 253 (lastmod (nth 5 (file-attributes file)))) | |
| 254 (if checkout-time | |
| 255 (equal lastmod checkout-time) | |
| 256 (if (zerop (vc-backend-diff file nil)) | |
| 257 (progn | |
| 258 (vc-file-setprop file 'vc-checkout-time lastmod) | |
| 259 t) | |
| 260 (progn | |
| 261 (vc-file-setprop file 'vc-checkout-time '(0 . 0)) | |
| 262 nil | |
| 263 )) | |
| 264 ))) | |
| 265 | |
| 927 | 266 ;; Here's the major entry point. |
| 904 | 267 |
| 927 | 268 ;;;###autoload |
| 904 | 269 (defun vc-next-action (verbose) |
| 270 "Do the next logical checkin or checkout operation on the current file. | |
| 271 If the file is not already registered, this registers it for version | |
| 272 control and then retrieves a writeable, locked copy for editing. | |
| 273 If the file is registered and not locked by anyone, this checks out | |
| 274 a writeable and locked file ready for editing. | |
| 275 If the file is checked out and locked by the calling user, this | |
| 276 first checks to see if the file has changed since checkout. If not, | |
| 277 it performs a revert. | |
| 278 If the file has been changed, this pops up a buffer for creation of | |
| 279 a log message; when the message has been entered, it checks in the | |
| 280 resulting changes along with the log message as change commentary. If | |
| 281 the variable vc-keep-workfiles is non-nil (which is its default), a | |
| 282 read-only copy of the changed file is left in place afterwards. | |
| 283 If the file is registered and locked by someone else, you are given | |
| 284 the option to steal the lock." | |
| 285 (interactive "P") | |
| 286 (if buffer-file-name | |
| 287 (let | |
| 288 (do-update owner version | |
| 289 (file buffer-file-name) | |
| 290 (vc-file (vc-name buffer-file-name)) | |
| 291 (err-msg nil) | |
| 292 owner) | |
| 293 | |
| 294 (cond | |
| 295 | |
| 296 ;; if there is no master file corresponding, create one | |
| 297 ((not vc-file) | |
| 298 (vc-register verbose) | |
| 299 (vc-next-action verbose)) | |
| 300 | |
| 301 ;; if there is no lock on the file, assert one and get it | |
| 302 ((not (setq owner (vc-locking-user file))) | |
| 303 (vc-checkout file t)) | |
| 304 | |
| 305 ;; a checked-out version exists, but the user may not own the lock | |
| 306 ((not (string-equal owner (user-login-name))) | |
| 307 (vc-steal-lock | |
| 308 file | |
| 309 (and verbose (read-string "Version to steal: ")) | |
| 310 owner)) | |
| 311 | |
| 312 ;; OK, user owns the lock on the file | |
| 313 (t (progn | |
| 314 | |
| 315 ;; give luser a chance to save before checking in. | |
| 316 (vc-buffer-sync) | |
| 317 | |
|
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
318 ;; Revert if file is unchanged and buffer is too. |
|
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
319 ;; If buffer is modified, that means the user just said no |
|
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
320 ;; to saving it; in that case, don't revert, |
|
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
321 ;; because the user might intend to save |
|
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
322 ;; after finishing the log entry. |
|
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
323 (if (and (vc-workfile-unchanged-p file) |
|
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
324 (not (buffer-modified-p))) |
| 904 | 325 (progn |
| 326 (vc-backend-revert file) | |
|
1636
c2bea3f2f8cb
(vc-next-action): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1635
diff
changeset
|
327 ;; DO NOT revert the file without asking the user! |
|
c2bea3f2f8cb
(vc-next-action): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1635
diff
changeset
|
328 (vc-resynch-window file t nil)) |
| 904 | 329 |
| 330 ;; user may want to set nonstandard parameters | |
| 331 (if verbose | |
| 332 (setq version (read-string "New version level: "))) | |
| 333 | |
| 334 ;; OK, let's do the checkin | |
| 335 (vc-checkin file version)))))) | |
| 336 (error "There is no file associated with buffer %s" (buffer-name)))) | |
| 337 | |
| 338 ;;; These functions help the vc-next-action entry point | |
| 339 | |
| 927 | 340 ;;;###autoload |
| 904 | 341 (defun vc-register (&optional override) |
| 342 "Register the current file into your version-control system." | |
| 343 (interactive "P") | |
| 344 (if (vc-name buffer-file-name) | |
| 345 (error "This file is already registered.")) | |
| 346 (vc-buffer-sync) | |
| 347 (vc-admin | |
| 348 buffer-file-name | |
| 349 (and override (read-string "Initial version level: "))) | |
| 350 ) | |
| 351 | |
|
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
352 (defun vc-resynch-window (file &optional keep noquery) |
| 904 | 353 ;; If the given file is in the current buffer, |
| 354 ;; either revert on it so we see expanded keyworks, | |
| 355 ;; or unvisit it (depending on vc-keep-workfiles) | |
|
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
356 ;; NOQUERY if non-nil inhibits confirmation for reverting. |
|
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
357 ;; NOQUERY should be t *only* if it is known the only difference |
|
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
358 ;; between the buffer and the file is due to RCS rather than user editing! |
| 904 | 359 (and (string= buffer-file-name file) |
| 360 (if keep | |
| 361 (progn | |
|
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
362 (vc-revert-buffer1 nil noquery) |
| 904 | 363 (vc-mode-line buffer-file-name)) |
| 364 (progn | |
| 365 (delete-window) | |
| 366 (kill-buffer (current-buffer)))))) | |
| 367 | |
| 368 | |
| 369 (defun vc-admin (file rev) | |
|
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
370 "Check a file into your version-control system. |
| 904 | 371 FILE is the unmodified name of the file. REV should be the base version |
| 372 level to check it in under." | |
| 373 (if vc-initial-comment | |
| 374 (progn | |
| 375 (pop-to-buffer (get-buffer-create "*VC-log*")) | |
| 376 (vc-log-mode) | |
| 377 (narrow-to-region (point-max) (point-max)) | |
| 378 (vc-mode-line file (file-name-nondirectory file)) | |
| 379 (setq vc-log-operation 'vc-backend-admin) | |
| 380 (setq vc-log-file file) | |
| 381 (setq vc-log-version rev) | |
| 382 (message "Enter initial comment. Type C-c C-c when done.")) | |
| 383 (progn | |
| 384 (vc-backend-admin file rev) | |
|
1494
64f5e84c822b
(vc-admin): Pass t as noquery arg to vc-resynch-window.
Richard M. Stallman <rms@gnu.org>
parents:
1478
diff
changeset
|
385 ;; Inhibit query here, since otherwise we always get asked. |
|
64f5e84c822b
(vc-admin): Pass t as noquery arg to vc-resynch-window.
Richard M. Stallman <rms@gnu.org>
parents:
1478
diff
changeset
|
386 (vc-resynch-window file vc-keep-workfiles t)))) |
| 904 | 387 |
| 388 (defun vc-steal-lock (file rev &optional owner) | |
| 389 "Steal the lock on the current workfile." | |
| 390 (interactive) | |
| 391 (if (not owner) | |
| 392 (setq owner (vc-locking-user file))) | |
| 393 (if (not (y-or-n-p (format "Take the lock on %s:%s from %s?" file rev owner))) | |
| 394 (error "Steal cancelled.")) | |
|
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
395 (require 'sendmail) |
|
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
396 (pop-to-buffer (get-buffer-create "*VC-mail*")) |
|
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
397 (setq default-directory (expand-file-name "~/")) |
|
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
398 (auto-save-mode auto-save-default) |
|
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
399 (mail-mode) |
|
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
400 (erase-buffer) |
|
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
401 (mail-setup owner (format "%s:%s" file rev) nil nil nil |
|
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
402 (list (list 'vc-finish-steal file rev))) |
|
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
403 (goto-char (point-max)) |
| 904 | 404 (insert |
|
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
405 (format "I stole the lock on %s:%s, " file rev) |
| 904 | 406 (current-time-string) |
|
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
407 ".\n") |
|
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
408 (message "Please explain why you stole the lock. Type C-c C-c when done.")) |
| 904 | 409 |
|
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
410 ;; This is called when the notification has been sent. |
| 904 | 411 (defun vc-finish-steal (file version) |
| 412 (vc-backend-steal file version) | |
|
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
413 (vc-resynch-window file t t)) |
| 904 | 414 |
| 415 (defun vc-checkout (file &optional writeable) | |
| 416 "Retrieve a copy of the latest version of the given file." | |
| 417 (vc-backend-checkout file writeable) | |
| 418 (if (string-equal file buffer-file-name) | |
|
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
419 (vc-resynch-window file t t)) |
| 904 | 420 ) |
| 421 | |
| 422 (defun vc-checkin (file &optional rev comment) | |
| 423 "Check in the file specified by FILE. | |
| 424 The optional argument REV may be a string specifying the new version level | |
|
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
425 \(if nil increment the current level). The file is either retained with write |
| 904 | 426 permissions zeroed, or deleted (according to the value of vc-keep-workfiles). |
| 427 COMMENT is a comment string; if omitted, a buffer is | |
| 428 popped up to accept a comment." | |
| 429 (pop-to-buffer (get-buffer-create "*VC-log*")) | |
| 430 (vc-log-mode) | |
| 431 (narrow-to-region (point-max) (point-max)) | |
| 432 (vc-mode-line file (file-name-nondirectory file)) | |
|
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
433 (setq vc-log-operation 'vc-backend-checkin |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
434 vc-log-file file |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
435 vc-log-version rev |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
436 vc-log-after-operation-hook 'vc-checkin-hook) |
| 904 | 437 (message "Enter log message. Type C-c C-c when done.") |
| 438 (if comment | |
| 439 (progn | |
| 440 (insert comment) | |
| 441 (vc-finish-logentry)))) | |
| 442 | |
| 443 (defun vc-finish-logentry () | |
| 444 "Complete the operation implied by the current log entry." | |
| 445 (interactive) | |
| 446 (goto-char (point-max)) | |
| 447 (if (not (bolp)) (newline)) | |
| 448 ;; delimit current page | |
| 449 (save-excursion | |
| 450 (widen) | |
| 451 (goto-char (point-max)) | |
| 452 (if (and (not (bobp)) (not (= (char-after (1- (point))) ?\f))) | |
| 453 (insert-char ?\f 1))) | |
| 454 (if (not (bobp)) | |
| 455 (forward-char -1)) | |
| 456 (mark-page) | |
| 457 ;; Check for errors | |
| 458 (vc-backend-logentry-check vc-log-file) | |
| 459 ;; OK, do it to it | |
| 460 (if vc-log-operation | |
| 461 (funcall vc-log-operation | |
| 462 vc-log-file | |
| 463 vc-log-version | |
| 464 (buffer-substring (region-beginning) (1- (region-end)))) | |
| 465 (error "No log operation is pending.")) | |
| 466 ;; Return to "parent" buffer of this checkin and remove checkin window | |
| 467 (pop-to-buffer (get-file-buffer vc-log-file)) | |
| 468 (delete-window (get-buffer-window "*VC-log*")) | |
| 469 (bury-buffer "*VC-log*") | |
| 470 ;; Now make sure we see the expanded headers | |
|
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
471 (vc-resynch-window buffer-file-name vc-keep-workfiles t) |
|
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
472 (run-hooks vc-log-after-operation-hook) |
| 904 | 473 ) |
| 474 | |
| 475 ;; Code for access to the comment ring | |
| 476 | |
| 477 (defun vc-next-comment () | |
| 478 "Fill the log buffer with the next message in the msg ring." | |
| 479 (interactive) | |
| 480 (widen) | |
| 481 (forward-page) | |
| 482 (if (= (point) (point-max)) | |
| 483 (goto-char (point-min))) | |
| 484 (mark-page) | |
| 485 (narrow-to-page)) | |
| 486 | |
| 487 (defun vc-previous-comment () | |
| 488 "Fill the log buffer with the previous message in the msg ring." | |
| 489 (interactive) | |
| 490 (widen) | |
| 491 (if (= (point) (point-min)) | |
| 492 (goto-char (point-max))) | |
| 493 (backward-page) | |
| 494 (mark-page) | |
| 495 (narrow-to-page)) | |
| 496 | |
| 497 (defun vc-comment-search-backward (regexp) | |
| 498 "Fill the log buffer with the last message in the msg ring matching REGEXP." | |
| 499 (interactive "sSearch backward for: ") | |
| 500 (widen) | |
| 501 (if (= (point) (point-min)) | |
| 502 (goto-char (point-max))) | |
| 503 (re-search-backward regexp nil t) | |
| 504 (mark-page) | |
| 505 (narrow-to-page)) | |
| 506 | |
| 507 (defun vc-comment-search-forward (regexp) | |
| 508 "Fill the log buffer with the next message in the msg ring matching REGEXP." | |
| 509 (interactive "sSearch forward for: ") | |
| 510 (widen) | |
| 511 (if (= (point) (point-min)) | |
| 512 (goto-char (point-max))) | |
| 513 (re-search-forward regexp nil t) | |
| 514 (mark-page) | |
| 515 (narrow-to-page)) | |
| 516 | |
| 517 ;; Additional entry points for examining version histories | |
| 518 | |
| 927 | 519 ;;;###autoload |
| 904 | 520 (defun vc-diff (historic) |
| 521 "Display diffs between file versions." | |
| 522 (interactive "P") | |
| 523 (if historic | |
| 524 (call-interactively 'vc-version-diff) | |
| 525 (let ((old | |
| 526 (and | |
| 527 current-prefix-arg | |
| 528 (read-string "Version to compare against: "))) | |
| 529 (file buffer-file-name) | |
| 530 unchanged) | |
| 531 (vc-buffer-sync) | |
| 532 (setq unchanged (vc-workfile-unchanged-p buffer-file-name)) | |
| 533 (if unchanged | |
| 534 (message (format "No changes to %s since latest version." file)) | |
| 535 (pop-to-buffer "*vc*") | |
| 536 (vc-backend-diff file nil) | |
| 537 (goto-char (point-min)) | |
| 538 ) | |
| 539 (not unchanged) | |
| 540 ) | |
| 541 ) | |
| 542 ) | |
| 543 | |
| 544 (defun vc-version-diff (file rel1 rel2) | |
| 545 "For FILE, report diffs between two stored versions REL1 and REL2 of it. | |
| 546 If FILE is a directory, generate diffs between versions for all registered | |
| 547 files in or below it." | |
| 548 (interactive "FFile or directory: \nsOlder version: \nsNewer version: ") | |
| 549 (if (string-equal rel1 "") (setq rel1 nil)) | |
| 550 (if (string-equal rel2 "") (setq rel2 nil)) | |
| 551 (if (file-directory-p file) | |
| 552 (progn | |
| 553 (set-buffer (get-buffer-create "*vc-status*")) | |
| 554 (erase-buffer) | |
| 555 (insert "Diffs between " rel1 " and " rel2 ":\n\n") | |
| 556 (set-buffer (get-buffer-create "*vc*")) | |
| 557 (vc-file-tree-walk | |
| 558 (function (lambda (f) | |
| 559 (and | |
| 560 (not (file-directory-p f)) | |
| 561 (vc-name f) | |
| 562 (vc-backend-diff f rel1 rel2)) | |
| 563 (append-to-buffer "*vc-status*" (point-min) (point-max)) | |
| 564 )) | |
| 565 default-directory) | |
| 566 (pop-to-buffer "*vc-status*") | |
| 567 (insert "\nEnd of diffs.\n") | |
| 568 (goto-char (point-min)) | |
| 569 (set-buffer-modified-p nil) | |
| 570 ) | |
| 571 (progn | |
| 572 (vc-backend-diff file rel1 rel2) | |
| 573 (goto-char (point-min)) | |
| 574 (if (equal (point-min) (point-max)) | |
| 575 (message (format "No changes to %s between %s and %s." file rel1 rel2)) | |
| 576 (pop-to-buffer "*vc*") | |
| 577 (goto-char (point-min)) | |
| 578 ) | |
| 579 ) | |
| 580 ) | |
| 581 ) | |
| 582 | |
| 583 ;; Header-insertion code | |
| 584 | |
| 927 | 585 ;;;###autoload |
| 904 | 586 (defun vc-insert-headers () |
| 587 "Insert headers in a file for use with your version-control system. | |
| 588 Headers desired are inserted at the start of the buffer, and are pulled from | |
| 589 the variable vc-header-strings" | |
| 590 (interactive) | |
| 591 (save-excursion | |
| 592 (save-restriction | |
| 593 (widen) | |
| 594 (if (or (not (vc-check-headers)) | |
| 595 (y-or-n-p "Version headers already exist. Insert another set?")) | |
| 596 (progn | |
| 597 (let* ((delims (cdr (assq major-mode vc-comment-alist))) | |
| 598 (comment-start-vc (or (car delims) comment-start "#")) | |
| 599 (comment-end-vc (or (car (cdr delims)) comment-end "")) | |
| 600 (hdstrings (cdr (assoc (vc-backend-deduce (buffer-file-name)) vc-header-alist)))) | |
| 601 (mapcar (function (lambda (s) | |
| 602 (insert comment-start-vc "\t" s "\t" | |
| 603 comment-end-vc "\n"))) | |
| 604 hdstrings) | |
| 605 (if vc-static-header-alist | |
| 606 (mapcar (function (lambda (f) | |
| 607 (if (string-match (car f) buffer-file-name) | |
| 608 (insert (format (cdr f) (car hdstrings)))))) | |
| 609 vc-static-header-alist)) | |
| 610 ) | |
| 611 ))))) | |
| 612 | |
| 613 ;; Status-checking functions | |
| 614 | |
| 927 | 615 ;;;###autoload |
| 904 | 616 (defun vc-directory (verbose) |
| 617 "Show version-control status of all files under the current directory." | |
| 618 (interactive "P") | |
| 619 (let ((dir (substring default-directory 0 (1- (length default-directory)))) | |
| 620 nonempty) | |
| 621 (save-excursion | |
| 622 (set-buffer (get-buffer-create "*vc-status*")) | |
| 623 (erase-buffer) | |
| 624 (vc-file-tree-walk | |
| 625 (function (lambda (f) | |
| 626 (if (vc-registered f) | |
| 627 (let ((user (vc-locking-user f))) | |
| 628 (if (or user verbose) | |
| 629 (insert (format | |
| 630 "%s %s\n" | |
| 631 (concat user) f))))))) | |
| 632 dir) | |
| 633 (setq nonempty (not (zerop (buffer-size))))) | |
| 634 (if nonempty | |
| 635 (progn | |
| 636 (pop-to-buffer "*vc-status*" t) | |
| 637 (vc-shrink-to-fit) | |
| 638 (goto-char (point-min))) | |
| 639 (message "No files are currently registered under %s" dir)) | |
| 640 )) | |
| 641 | |
| 642 ;; Named-configuration support for SCCS | |
| 643 | |
| 644 (defun vc-add-triple (name file rev) | |
| 645 (save-excursion | |
| 646 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file)) | |
| 647 (goto-char (point-max)) | |
| 648 (insert name "\t:\t" file "\t" rev "\n") | |
| 649 (basic-save-buffer) | |
| 650 (kill-buffer (current-buffer)) | |
| 651 )) | |
| 652 | |
| 653 (defun vc-record-rename (file newname) | |
| 654 (save-excursion | |
| 655 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file)) | |
| 656 (goto-char (point-min)) | |
| 657 (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname)) | |
| 658 (basic-save-buffer) | |
| 659 (kill-buffer (current-buffer)) | |
| 660 )) | |
| 661 | |
| 662 (defun vc-lookup-triple (file name) | |
| 663 (or | |
| 664 name | |
| 665 (let ((firstchar (aref name 0))) | |
| 666 (and (>= firstchar ?0) (<= firstchar ?9) name)) | |
| 667 (car (vc-master-info | |
| 668 (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file) | |
| 669 (list (concat name "\t:\t" file "\t\\(.+\\)")))) | |
| 670 )) | |
| 671 | |
| 672 ;; Named-configuration entry points | |
| 673 | |
| 674 (defun vc-quiescent-p () | |
| 675 ;; Is the current directory ready to be snapshot? | |
| 676 (let ((dir (substring default-directory 0 (1- (length default-directory))))) | |
| 677 (catch 'quiet | |
| 678 (vc-file-tree-walk | |
| 679 (function (lambda (f) | |
| 680 (if (and (vc-registered f) (vc-locking-user f)) | |
| 681 (throw 'quiet nil)))) | |
| 682 dir) | |
| 683 t))) | |
| 684 | |
| 927 | 685 ;;;###autoload |
| 904 | 686 (defun vc-create-snapshot (name) |
| 687 "Make a snapshot called NAME. | |
| 688 The snapshot is made from all registered files at or below the current | |
| 689 directory. For each file, the version level of its latest | |
| 690 version becomes part of the named configuration." | |
| 691 (interactive "sNew snapshot name: ") | |
| 692 (if (not (vc-quiescent-p)) | |
| 693 (error "Can't make a snapshot, locked files are in the way.") | |
| 694 (vc-file-tree-walk | |
| 695 (function (lambda (f) (and | |
| 696 (not (file-directory-p f)) | |
| 697 (vc-name f) | |
| 698 (vc-backend-assign-name f name)))) | |
| 699 default-directory) | |
| 700 )) | |
| 701 | |
| 927 | 702 ;;;###autoload |
| 904 | 703 (defun vc-retrieve-snapshot (name) |
| 704 "Retrieve the snapshot called NAME. | |
| 705 This function fails if any files are locked at or below the current directory | |
| 706 Otherwise, all registered files are checked out (unlocked) at their version | |
| 707 levels in the snapshot." | |
| 708 (interactive "sSnapshot name to retrieve: ") | |
| 709 (if (not (vc-quiescent-p)) | |
| 710 (error "Can't retrieve a snapshot, locked files are in the way.") | |
| 711 (vc-file-tree-walk | |
| 712 (function (lambda (f) (and | |
| 713 (not (file-directory-p f)) | |
| 714 (vc-name f) | |
| 715 (vc-error-occurred (vc-backend-checkout f nil name))))) | |
| 716 default-directory) | |
| 717 )) | |
| 718 | |
| 719 ;; Miscellaneous other entry points | |
| 720 | |
| 927 | 721 ;;;###autoload |
| 904 | 722 (defun vc-print-log () |
| 723 "List the change log of the current buffer in a window." | |
| 724 (interactive) | |
| 725 (if (and buffer-file-name (vc-name buffer-file-name)) | |
| 726 (progn | |
| 727 (vc-backend-print-log buffer-file-name) | |
| 728 (pop-to-buffer (get-buffer-create "*vc*")) | |
| 729 (goto-char (point-min)) | |
| 730 ) | |
| 731 (error "There is no version-control master associated with this buffer") | |
| 732 ) | |
| 733 ) | |
| 734 | |
| 927 | 735 ;;;###autoload |
| 904 | 736 (defun vc-revert-buffer () |
| 952 | 737 "Revert the current buffer's file back to the latest checked-in version. |
| 738 This asks for confirmation if the buffer contents are not identical | |
| 739 to that version." | |
| 904 | 740 (interactive) |
| 741 (let ((file buffer-file-name) | |
| 742 (obuf (current-buffer)) (changed (vc-diff nil))) | |
| 952 | 743 (if (and changed (or vc-suppress-confirm |
| 744 (not (yes-or-no-p "Discard changes? ")))) | |
| 904 | 745 (progn |
| 746 (delete-window) | |
| 747 (error "Revert cancelled.")) | |
| 748 (set-buffer obuf)) | |
| 749 (if changed | |
| 750 (delete-window)) | |
| 751 (vc-backend-revert file) | |
|
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
752 (vc-resynch-window file t t) |
| 904 | 753 ) |
| 754 ) | |
| 755 | |
| 927 | 756 ;;;###autoload |
| 904 | 757 (defun vc-cancel-version (norevert) |
| 758 "Undo your latest checkin." | |
| 759 (interactive "P") | |
| 760 (let ((target (vc-your-latest-version (buffer-file-name)))) | |
| 761 (if (null target) | |
| 762 (error "You didn't check in the last change.")) | |
|
1575
ae13f4027ebd
(vc-cancel-version): Use yes-or-no-p.
Richard M. Stallman <rms@gnu.org>
parents:
1494
diff
changeset
|
763 (and (yes-or-no-p (format "Remove version %s from master? " target)) |
| 904 | 764 (vc-backend-uncheck (buffer-file-name) target))) |
| 765 (if norevert | |
| 766 (vc-mode-line (buffer-file-name)) | |
| 767 (vc-checkout (buffer-file-name) nil)) | |
| 768 ) | |
| 769 | |
| 770 (defun vc-rename-file (old new) | |
| 771 "Rename a file, taking its master files with it." | |
| 772 (interactive "fOld name: \nFNew name: ") | |
| 773 (let ((oldbuf (get-file-buffer old))) | |
| 774 (if (buffer-modified-p oldbuf) | |
| 775 (error "Please save files before moving them.")) | |
| 776 (if (get-file-buffer new) | |
| 777 (error "Already editing new file name.")) | |
| 778 (let ((oldmaster (vc-name old))) | |
| 779 (if oldmaster | |
| 780 (if (vc-locking-user old) | |
| 781 (error "Please check in files before moving them.")) | |
| 782 (if (or (file-symlink-p oldmaster) | |
|
1243
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
783 ;; This had FILE, I changed it to OLD. -- rms. |
|
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
784 (file-symlink-p (vc-backend-subdirectory-name old))) |
| 904 | 785 (error "This is not a safe thing to do in the presence of symbolic links.")) |
| 786 (rename-file oldmaster (vc-name new))) | |
| 787 (if (or (not oldmaster) (file-exists-p old)) | |
| 788 (rename-file old new))) | |
| 789 ; ?? Renaming a file might change its contents due to keyword expansion. | |
| 790 ; We should really check out a new copy if the old copy was precisely equal | |
| 791 ; to some checked in version. However, testing for this is tricky.... | |
| 792 (if oldbuf | |
| 793 (save-excursion | |
| 794 (set-buffer oldbuf) | |
| 795 (set-visited-file-name new) | |
| 796 (set-buffer-modified-p nil)))) | |
|
1243
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
797 ;; This had FILE, I changed it to OLD. -- rms. |
|
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
798 (vc-backend-dispatch old |
| 904 | 799 (vc-record-rename old new) |
| 800 nil) | |
| 801 ) | |
| 802 | |
| 927 | 803 ;;;###autoload |
|
1226
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
804 (defun vc-update-change-log (&rest args) |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
805 "Find change log file and add entries from recent RCS logs. |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
806 The mark is left at the end of the text prepended to the change log. |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
807 With prefix arg of C-u, only find log entries for the current buffer's file. |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
808 With any numeric prefix arg, find log entries for all files currently visited. |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
809 From a program, any arguments are passed to the `rcs2log' script." |
|
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
810 (interactive |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
811 (cond ((consp current-prefix-arg) ;C-u |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
812 (list buffer-file-name)) |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
813 (current-prefix-arg ;Numeric argument. |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
814 (let ((files nil) |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
815 (buffers (buffer-list)) |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
816 file) |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
817 (while buffers |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
818 (setq file (buffer-file-name (car buffers))) |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
819 (and file (vc-backend-deduce file) |
|
1232
2c56a159c9b6
(vc-update-change-log): Use file-relative-name.
Roland McGrath <roland@gnu.org>
parents:
1227
diff
changeset
|
820 (setq files (cons (file-relative-name file) files))) |
|
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
821 (setq buffers (cdr buffers))) |
|
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
822 files)))) |
|
1226
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
823 (find-file-other-window "ChangeLog") |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
824 (vc-buffer-sync) |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
825 (undo-boundary) |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
826 (goto-char (point-min)) |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
827 (message "Computing change log entries...") |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
828 (shell-command (mapconcat 'identity (cons "rcs2log" args) " ") t) |
|
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
829 (message "Computing change log entries... done")) |
| 904 | 830 |
| 831 ;; Functions for querying the master and lock files. | |
| 832 | |
| 833 (defun match-substring (bn) | |
| 834 (buffer-substring (match-beginning bn) (match-end bn))) | |
| 835 | |
| 836 (defun vc-parse-buffer (patterns &optional file properties) | |
| 837 ;; Use PATTERNS to parse information out of the current buffer | |
| 838 ;; by matching each regular expression in the list and returning \\1. | |
| 839 ;; If a regexp has two tag brackets, assume the second is a date | |
| 840 ;; field and we want the most recent entry matching the template. | |
| 841 ;; If FILE and PROPERTIES are given, the latter must be a list of | |
| 842 ;; properties of the same length as PATTERNS; each property is assigned | |
| 843 ;; the corresponding value. | |
| 844 (mapcar (function (lambda (p) | |
| 845 (goto-char (point-min)) | |
| 846 (if (string-match "\\\\(.*\\\\(" p) | |
| 847 (let ((latest-date "") (latest-val)) | |
| 848 (while (re-search-forward p nil t) | |
| 849 (let ((date (match-substring 2))) | |
| 850 (if (string< latest-date date) | |
| 851 (progn | |
| 852 (setq latest-date date) | |
| 853 (setq latest-val | |
| 854 (match-substring 1)))))) | |
| 855 latest-val)) | |
| 856 (prog1 | |
| 857 (and (re-search-forward p nil t) | |
| 858 (let ((value (match-substring 1))) | |
| 859 (if file | |
| 860 (vc-file-setprop file (car properties) value)) | |
| 861 value)) | |
| 862 (setq properties (cdr properties))))) | |
| 863 patterns) | |
| 864 ) | |
| 865 | |
| 866 (defun vc-master-info (file fields &optional rfile properties) | |
| 867 ;; Search for information in a master file. | |
| 868 (if (and file (file-exists-p file)) | |
| 869 (save-excursion | |
| 870 (let ((buf)) | |
| 871 (setq buf (create-file-buffer file)) | |
| 872 (set-buffer buf)) | |
| 873 (erase-buffer) | |
| 874 (insert-file-contents file nil) | |
| 875 (set-buffer-modified-p nil) | |
| 876 (auto-save-mode nil) | |
| 877 (prog1 | |
| 878 (vc-parse-buffer fields rfile properties) | |
| 879 (kill-buffer (current-buffer))) | |
| 880 ) | |
| 881 (if rfile | |
| 882 (mapcar | |
| 883 (function (lambda (p) (vc-file-setprop rfile p nil))) | |
| 884 properties)) | |
| 885 ) | |
| 886 ) | |
| 887 | |
| 888 (defun vc-log-info (command file patterns &optional properties) | |
| 889 ;; Search for information in log program output | |
| 890 (if (and file (file-exists-p file)) | |
| 891 (save-excursion | |
| 892 (let ((buf)) | |
| 893 (setq buf (get-buffer-create "*vc*")) | |
| 894 (set-buffer buf)) | |
| 895 (apply 'vc-do-command 0 command file nil) | |
| 896 (set-buffer-modified-p nil) | |
| 897 (prog1 | |
| 898 (vc-parse-buffer patterns file properties) | |
| 899 (kill-buffer (current-buffer)) | |
| 900 ) | |
| 901 ) | |
| 902 (if file | |
| 903 (mapcar | |
| 904 (function (lambda (p) (vc-file-setprop file p nil))) | |
| 905 properties)) | |
| 906 ) | |
| 907 ) | |
| 908 | |
| 909 (defun vc-locking-user (file) | |
| 910 "Return the name of the person currently holding a lock on FILE. | |
| 911 Return nil if there is no such person." | |
| 912 (if (or (not vc-keep-workfiles) | |
| 913 (eq vc-mistrust-permissions 't) | |
| 914 (and vc-mistrust-permissions | |
| 915 (funcall vc-mistrust-permissions (vc-backend-subdirectory-name file)))) | |
| 916 (vc-true-locking-user file) | |
| 917 ;; This implementation assumes that any file which is under version | |
| 918 ;; control and has -rw-r--r-- is locked by its owner. This is true | |
| 919 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--. | |
| 920 ;; We have to be careful not to exclude files with execute bits on; | |
| 921 ;; scripts can be under version control too. The advantage of this | |
| 922 ;; hack is that calls to the very expensive vc-fetch-properties | |
| 923 ;; function only have to be made if (a) the file is locked by someone | |
| 924 ;; other than the current user, or (b) some untoward manipulation | |
| 925 ;; behind vc's back has twiddled the `group' or `other' write bits. | |
| 926 (let ((attributes (file-attributes file))) | |
| 927 (cond ((string-match ".r-.r-.r-." (nth 8 attributes)) | |
| 928 nil) | |
| 929 ((and (= (nth 2 attributes) (user-uid)) | |
| 930 (string-match ".rw.r-.r-." (nth 8 attributes))) | |
| 931 (user-login-name)) | |
| 932 (t | |
| 933 (vc-true-locking-user file)))))) | |
| 934 | |
| 935 (defun vc-true-locking-user (file) | |
| 936 ;; The slow but reliable version | |
| 937 (vc-fetch-properties file) | |
| 938 (vc-file-getprop file 'vc-locking-user)) | |
| 939 | |
| 940 (defun vc-latest-version (file) | |
| 941 ;; Return version level of the latest version of FILE | |
| 942 (vc-fetch-properties file) | |
| 943 (vc-file-getprop file 'vc-latest-version)) | |
| 944 | |
| 945 (defun vc-your-latest-version (file) | |
| 946 ;; Return version level of the latest version of FILE checked in by you | |
| 947 (vc-fetch-properties file) | |
| 948 (vc-file-getprop file 'vc-your-latest-version)) | |
| 949 | |
| 950 ;; Collect back-end-dependent stuff here | |
| 951 ;; | |
| 952 ;; Everything eventually funnels through these functions. To implement | |
| 953 ;; support for a new version-control system, add another branch to the | |
| 954 ;; vc-backend-dispatch macro (in vc-hooks.el) and fill it in in each call. | |
| 955 | |
| 956 (defmacro vc-backend-dispatch (f s r) | |
| 957 "Execute FORM1 or FORM2 depending on whether we're using SCCS or RCS." | |
| 958 (list 'let (list (list 'type (list 'vc-backend-deduce f))) | |
| 959 (list 'cond | |
| 960 (list (list 'eq 'type (quote 'SCCS)) s) ;; SCCS | |
| 961 (list (list 'eq 'type (quote 'RCS)) r) ;; RCS | |
| 962 ))) | |
| 963 | |
| 964 (defun vc-lock-file (file) | |
| 965 ;; Generate lock file name corresponding to FILE | |
| 966 (let ((master (vc-name file))) | |
| 967 (and | |
| 968 master | |
| 969 (string-match "\\(.*/\\)s\\.\\(.*\\)" master) | |
| 970 (concat | |
| 971 (substring master (match-beginning 1) (match-end 1)) | |
| 972 "p." | |
| 973 (substring master (match-beginning 2) (match-end 2)))))) | |
| 974 | |
| 975 | |
| 976 (defun vc-fetch-properties (file) | |
| 977 ;; Re-fetch all properties associated with the given file. | |
| 978 ;; Currently these properties are: | |
| 979 ;; vc-locking-user | |
| 980 ;; vc-locked-version | |
| 981 ;; vc-latest-version | |
| 982 ;; vc-your-latest-version | |
| 983 (vc-backend-dispatch | |
| 984 file | |
| 985 ;; SCCS | |
| 986 (progn | |
| 987 (vc-master-info (vc-lock-file file) | |
| 988 (list | |
| 989 "^[^ ]+ [^ ]+ \\([^ ]+\\)" | |
| 990 "^\\([^ ]+\\)") | |
| 991 file | |
| 992 '(vc-locking-user vc-locked-version)) | |
| 993 (vc-master-info (vc-name file) | |
| 994 (list | |
| 995 "^\001d D \\([^ ]+\\)" | |
| 996 (concat "^\001d D \\([^ ]+\\) .* " | |
| 997 (regexp-quote (user-login-name)) " ") | |
| 998 ) | |
| 999 file | |
| 1000 '(vc-latest-version vc-your-latest-version)) | |
| 1001 ) | |
| 1002 ;; RCS | |
| 1003 (vc-log-info "rlog" file | |
| 1004 (list | |
| 1005 "^locks: strict\n\t\\([^:]+\\)" | |
| 1006 "^locks: strict\n\t[^:]+: \\(.+\\)" | |
| 1007 "^revision[\t ]+\\([0-9.]+\\).*\ndate: \\([ /0-9:]+\\);" | |
| 1008 (concat | |
| 1009 "^revision[\t ]+\\([0-9.]+\\).*locked by: " | |
| 1010 (regexp-quote (user-login-name)) | |
| 1011 ";\ndate: \\([ /0-9:]+\\);")) | |
| 1012 '(vc-locking-user vc-locked-version | |
| 1013 vc-latest-version vc-your-latest-version)) | |
| 1014 )) | |
| 1015 | |
| 1016 (defun vc-backend-subdirectory-name (&optional file) | |
| 1017 ;; Where the master and lock files for the current directory are kept | |
| 1018 (symbol-name | |
| 1019 (or | |
| 1020 (and file (vc-backend-deduce file)) | |
| 1021 vc-default-back-end | |
| 1022 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS))))) | |
| 1023 | |
| 1024 (defun vc-backend-admin (file &optional rev comment) | |
| 1025 ;; Register a file into the version-control system | |
| 1026 ;; Automatically retrieves a read-only version of the file with | |
| 1027 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise | |
| 1028 ;; it deletes the workfile. | |
| 1029 (vc-file-clearprops file) | |
| 1030 (or vc-default-back-end | |
| 1031 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS))) | |
| 1032 (message "Registering %s..." file) | |
| 1033 (let ((backend | |
| 1034 (cond | |
| 1035 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end) | |
| 1036 ((file-exists-p "RCS") 'RCS) | |
| 1037 ((file-exists-p "SCCS") 'SCCS) | |
| 1038 (t vc-default-back-end)))) | |
| 1039 (cond ((eq backend 'SCCS) | |
| 1040 (vc-do-command 0 "admin" file ;; SCCS | |
| 1041 (and rev (concat "-r" rev)) | |
| 1042 "-fb" | |
| 1043 (concat "-i" file) | |
| 1044 (and comment (concat "-y" comment)) | |
| 1045 (format | |
| 1046 (car (rassq 'SCCS vc-master-templates)) | |
| 1047 (or (file-name-directory file) "") | |
| 1048 (file-name-nondirectory file))) | |
| 1049 (delete-file file) | |
| 1050 (if vc-keep-workfiles | |
| 1051 (vc-do-command 0 "get" file))) | |
| 1052 ((eq backend 'RCS) | |
| 1053 (vc-do-command 0 "ci" file ;; RCS | |
| 1054 (concat (if vc-keep-workfiles "-u" "-r") rev) | |
| 1055 (and comment (concat "-t-" comment)) | |
| 1056 file) | |
| 1057 ))) | |
| 1058 (message "Registering %s...done" file) | |
| 1059 ) | |
| 1060 | |
| 1061 (defun vc-backend-checkout (file &optional writeable rev) | |
| 1062 ;; Retrieve a copy of a saved version into a workfile | |
| 1063 (message "Checking out %s..." file) | |
| 1064 (vc-backend-dispatch file | |
| 1065 (progn | |
| 1066 (vc-do-command 0 "get" file ;; SCCS | |
| 1067 (if writeable "-e") | |
| 1068 (and rev (concat "-r" (vc-lookup-triple file rev)))) | |
| 1069 ) | |
| 1070 (vc-do-command 0 "co" file ;; RCS | |
| 1071 (if writeable "-l") | |
| 1072 (and rev (concat "-r" rev))) | |
| 1073 ) | |
| 1074 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file))) | |
| 1075 (message "Checking out %s...done" file) | |
| 1076 ) | |
| 1077 | |
| 1078 (defun vc-backend-logentry-check (file) | |
| 1079 (vc-backend-dispatch file | |
| 1080 (if (>= (- (region-end) (region-beginning)) 512) ;; SCCS | |
| 1081 (progn | |
| 1082 (goto-char 512) | |
| 1083 (error | |
| 1084 "Log must be less than 512 characters. Point is now at char 512."))) | |
| 1085 nil) | |
| 1086 ) | |
| 1087 | |
| 1088 (defun vc-backend-checkin (file &optional rev comment) | |
| 1089 ;; Register changes to FILE as level REV with explanatory COMMENT. | |
| 1090 ;; Automatically retrieves a read-only version of the file with | |
| 1091 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise | |
| 1092 ;; it deletes the workfile. | |
| 1093 (message "Checking in %s..." file) | |
|
1337
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1094 (save-excursion |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1095 ;; Change buffers to get local value of vc-checkin-switches. |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1096 (set-buffer (or (get-file-buffer file) (current-buffer))) |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1097 (vc-backend-dispatch file |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1098 (progn |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1099 (apply 'vc-do-command 0 "delta" file |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1100 (if rev (concat "-r" rev)) |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1101 (concat "-y" comment) |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1102 vc-checkin-switches) |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1103 (if vc-keep-workfiles |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1104 (vc-do-command 0 "get" file)) |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1105 ) |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1106 (apply 'vc-do-command 0 "ci" file |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1107 (concat (if vc-keep-workfiles "-u" "-r") rev) |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1108 (concat "-m" comment) |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1109 vc-checkin-switches) |
|
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1110 )) |
| 904 | 1111 (vc-file-setprop file 'vc-locking-user nil) |
| 1112 (message "Checking in %s...done" file) | |
| 1113 ) | |
| 1114 | |
| 1115 (defun vc-backend-revert (file) | |
| 1116 ;; Revert file to latest checked-in version. | |
| 1117 (message "Reverting %s..." file) | |
| 1118 (vc-backend-dispatch | |
| 1119 file | |
| 1120 (progn ;; SCCS | |
| 1121 (vc-do-command 0 "unget" file nil) | |
| 1122 (vc-do-command 0 "get" file nil)) | |
| 1123 (progn | |
| 1124 (delete-file file) ;; RCS | |
| 1125 (vc-do-command 0 "co" file "-u"))) | |
| 1126 (vc-file-setprop file 'vc-locking-user nil) | |
| 1127 (message "Reverting %s...done" file) | |
| 1128 ) | |
| 1129 | |
| 1130 (defun vc-backend-steal (file &optional rev) | |
| 1131 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M. | |
| 1132 (message "Stealing lock on %s..." file) | |
| 1133 (progn | |
| 1134 (vc-do-command 0 "unget" file "-n" (if rev (concat "-r" rev))) | |
| 1135 (vc-do-command 0 "get" file "-g" (if rev (concat "-r" rev))) | |
| 1136 ) | |
| 1137 (progn | |
|
1344
8d047d2d2592
(vc-backend-steal): Put filename after options in rcs commands.
Richard M. Stallman <rms@gnu.org>
parents:
1343
diff
changeset
|
1138 (vc-do-command 0 "rcs" "-M" (concat "-u" rev) file) |
|
1352
a8623439066b
(vc-backend-steal): Delete the workfile after the rcs -M -u.
Richard M. Stallman <rms@gnu.org>
parents:
1344
diff
changeset
|
1139 (delete-file file) |
|
1344
8d047d2d2592
(vc-backend-steal): Put filename after options in rcs commands.
Richard M. Stallman <rms@gnu.org>
parents:
1343
diff
changeset
|
1140 (vc-do-command 0 "rcs" (concat "-l" rev) file) |
| 904 | 1141 ) |
| 1142 (vc-file-setprop file 'vc-locking-user (user-login-name)) | |
| 1143 (message "Stealing lock on %s...done" file) | |
| 1144 ) | |
| 1145 | |
| 1146 (defun vc-backend-uncheck (file target) | |
| 1147 ;; Undo the latest checkin. Note: this code will have to get a lot | |
| 1148 ;; smarter when we support multiple branches. | |
| 1149 (message "Removing last change from %s..." file) | |
| 1150 (vc-backend-dispatch file | |
| 1151 (vc-do-command 0 "rmdel" file (concat "-r" target)) | |
| 1152 (vc-do-command 0 "rcs" file (concat "-o" target)) | |
| 1153 ) | |
| 1154 (message "Removing last change from %s...done" file) | |
| 1155 ) | |
| 1156 | |
| 1157 (defun vc-backend-print-log (file) | |
| 1158 ;; Print change log associated with FILE to buffer *vc*. | |
| 1159 (vc-do-command 0 | |
| 1160 (vc-backend-dispatch file "prs" "rlog") | |
| 1161 file) | |
| 1162 ) | |
| 1163 | |
| 1164 (defun vc-backend-assign-name (file name) | |
| 1165 ;; Assign to a FILE's latest version a given NAME. | |
| 1166 (vc-backend-dispatch file | |
| 1167 (vc-add-triple name file (vc-latest-version file)) ;; SCCS | |
| 1168 (vc-do-command 0 "rcs" file (concat "-n" name ":")) ;; RCS | |
| 1169 )) | |
| 1170 | |
| 1171 (defun vc-backend-diff (file oldvers &optional newvers) | |
| 1172 ;; Get a difference report between two versions | |
| 1173 (apply 'vc-do-command 1 | |
| 1174 (or (vc-backend-dispatch file "vcdiff" "rcsdiff") | |
| 1175 (error (format "File %s is not under version control." file))) | |
| 1176 file | |
| 1177 (and oldvers (concat "-r" oldvers)) | |
| 1178 (and newvers (concat "-r" newvers)) | |
| 1179 vc-diff-options | |
| 1180 )) | |
| 1181 | |
| 1182 (defun vc-check-headers () | |
| 1183 "Check if the current file has any headers in it." | |
| 1184 (interactive) | |
| 1185 (save-excursion | |
| 1186 (goto-char (point-min)) | |
| 1187 (vc-backend-dispatch buffer-file-name | |
| 1188 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS | |
| 1189 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS | |
| 1190 ) | |
| 1191 )) | |
| 1192 | |
| 1193 ;; Back-end-dependent stuff ends here. | |
| 1194 | |
| 1195 ;; Set up key bindings for use while editing log messages | |
| 1196 | |
| 1197 (defun vc-log-mode () | |
| 1198 "Minor mode for driving version-control tools. | |
| 1199 These bindings are added to the global keymap when you enter this mode: | |
| 1200 \\[vc-next-action] perform next logical version-control operation on current file | |
| 1201 \\[vc-register] register current file | |
| 1202 \\[vc-toggle-read-only] like next-action, but won't register files | |
| 1203 \\[vc-insert-headers] insert version-control headers in current file | |
| 1204 \\[vc-print-log] display change history of current file | |
| 1205 \\[vc-revert-buffer] revert buffer to latest version | |
| 1206 \\[vc-cancel-version] undo latest checkin | |
| 1207 \\[vc-diff] show diffs between file versions | |
| 1208 \\[vc-directory] show all files locked by any user in or below . | |
| 1209 \\[vc-update-change-log] add change log entry from recent checkins | |
| 1210 | |
| 1211 While you are entering a change log message for a version, the following | |
| 1212 additional bindings will be in effect. | |
| 1213 | |
| 1214 \\[vc-finish-logentry] proceed with check in, ending log message entry | |
| 1215 | |
| 1216 Whenever you do a checkin, your log comment is added to a ring of | |
| 1217 saved comments. These can be recalled as follows: | |
| 1218 | |
| 1219 \\[vc-next-comment] replace region with next message in comment ring | |
| 1220 \\[vc-previous-comment] replace region with previous message in comment ring | |
| 1221 \\[vc-search-comment-reverse] search backward for regexp in the comment ring | |
| 1222 \\[vc-search-comment-forward] search backward for regexp in the comment ring | |
| 1223 | |
| 1224 Entry to the change-log submode calls the value of text-mode-hook, then | |
| 1225 the value of vc-log-mode-hook. | |
| 1226 | |
| 1227 Global user options: | |
| 1228 vc-initial-comment If non-nil, require user to enter a change | |
| 1229 comment upon first checkin of the file. | |
| 1230 | |
| 1231 vc-keep-workfiles Non-nil value prevents workfiles from being | |
| 1232 deleted when changes are checked in | |
| 1233 | |
| 1234 vc-suppress-confirm Suppresses some confirmation prompts, | |
| 1235 notably for reversions. | |
| 1236 | |
| 1237 vc-diff-options A list consisting of the flags | |
| 1238 to be used for generating context diffs. | |
| 1239 | |
| 1240 vc-header-strings Which keywords to insert when adding headers | |
| 1241 with \\[vc-insert-headers]. Defaults to | |
| 1242 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under RCS. | |
| 1243 | |
| 1244 vc-static-header-alist By default, version headers inserted in C files | |
| 1245 get stuffed in a static string area so that | |
| 1246 ident(RCS) or what(SCCS) can see them in the | |
| 1247 compiled object code. You can override this | |
| 1248 by setting this variable to nil, or change | |
| 1249 the header template by changing it. | |
| 1250 | |
| 1251 vc-command-messages if non-nil, display run messages from the | |
| 1252 actual version-control utilities (this is | |
| 1253 intended primarily for people hacking vc | |
| 1254 itself). | |
| 1255 " | |
| 1256 (interactive) | |
| 1257 (set-syntax-table text-mode-syntax-table) | |
| 1258 (use-local-map vc-log-entry-mode) | |
| 1259 (setq local-abbrev-table text-mode-abbrev-table) | |
| 1260 (setq major-mode 'vc-log-mode) | |
| 1261 (setq mode-name "VC-Log") | |
| 1262 (make-local-variable 'vc-log-file) | |
| 1263 (make-local-variable 'vc-log-version) | |
| 1264 (set-buffer-modified-p nil) | |
| 1265 (setq buffer-file-name nil) | |
| 1266 (run-hooks 'text-mode-hook 'vc-log-mode-hook) | |
| 1267 ) | |
| 1268 | |
| 1269 ;; Initialization code, to be done just once at load-time | |
| 1270 (if vc-log-entry-mode | |
| 1271 nil | |
| 1272 (setq vc-log-entry-mode (make-sparse-keymap)) | |
| 1273 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment) | |
| 1274 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment) | |
| 1275 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-backward) | |
| 1276 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward) | |
| 1277 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry) | |
| 1278 ) | |
| 1279 | |
| 1280 ;;; These things should probably be generally available | |
| 1281 | |
| 1282 (defun vc-shrink-to-fit () | |
| 1283 "Shrink a window vertically until it's just large enough to contain its text" | |
| 1284 (let ((minsize (1+ (count-lines (point-min) (point-max))))) | |
| 1285 (if (< minsize (window-height)) | |
| 1286 (let ((window-min-height 2)) | |
| 1287 (shrink-window (- (window-height) minsize)))))) | |
| 1288 | |
| 1289 (defun vc-file-tree-walk (func dir &rest args) | |
| 1290 "Apply a given function to dir and all files underneath it, recursively." | |
| 1291 (apply 'funcall func dir args) | |
| 1292 (and (file-directory-p dir) | |
| 1293 (mapcar | |
| 1294 (function (lambda (f) (or | |
| 1295 (string-equal f ".") | |
| 1296 (string-equal f "..") | |
| 1297 (file-symlink-p f) ;; Avoid possible loops | |
| 1298 (apply 'vc-file-tree-walk | |
| 1299 func | |
| 1300 (if (= (aref dir (1- (length dir))) ?/) | |
| 1301 (concat dir f) | |
| 1302 (concat dir "/" f)) | |
| 1303 args)))) | |
| 1304 (directory-files dir)))) | |
| 1305 | |
| 1306 (provide 'vc) | |
| 1307 | |
| 1308 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE | |
| 1309 ;;; | |
| 1310 ;;; These may be useful to anyone who has to debug or extend the package. | |
| 1311 ;;; | |
| 1312 ;;; A fundamental problem in VC is that there are time windows between | |
| 1313 ;;; vc-next-action's computations of the file's version-control state and | |
| 1314 ;;; the actions that change it. This is a window open to lossage in a | |
| 1315 ;;; multi-user environment; someone else could nip in and change the state | |
| 1316 ;;; of the master during it. | |
| 1317 ;;; | |
| 1318 ;;; The performance problem is that rlog/prs calls are very expensive; we want | |
| 1319 ;;; to avoid them as much as possible. | |
| 1320 ;;; | |
| 1321 ;;; ANALYSIS: | |
| 1322 ;;; | |
| 1323 ;;; The performance problem, it turns out, simplifies in practice to the | |
| 1324 ;;; problem of making vc-locking-user fast. The two other functions that call | |
| 1325 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one | |
| 1326 ;;; makes snapshots, the other deletes the calling user's last change in the | |
| 1327 ;;; master. | |
| 1328 ;;; | |
| 1329 ;;; The race condition implies that we have to either (a) lock the master | |
| 1330 ;;; during the entire execution of vc-next-action, or (b) detect and | |
| 1331 ;;; recover from errors resulting from dispatch on an out-of-date state. | |
| 1332 ;;; | |
| 1333 ;;; Alternative (a) appears to be unfeasible. The problem is that we can't | |
| 1334 ;;; guarantee that the lock will ever be removed. Suppose a user starts a | |
| 1335 ;;; checkin, the change message buffer pops up, and the user, having wandered | |
| 1336 ;;; off to do something else, simply forgets about it? | |
| 1337 ;;; | |
| 1338 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up | |
| 1339 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/ | |
| 1340 ;;; unlocked state and its current owner from its permissions. | |
| 1341 ;;; | |
| 1342 ;;; This shortcut will fail if someone has manually changed the workfile's | |
| 1343 ;;; permissions; also if developers are munging the workfile in several | |
| 1344 ;;; directories, with symlinks to a master (in this latter case, the | |
| 1345 ;;; permissions shortcut will fail to detect a lock asserted from another | |
| 1346 ;;; directory). | |
| 1347 ;;; | |
| 1348 ;;; Note that these cases correspond exactly to the errors which could happen | |
| 1349 ;;; because of a competing checkin/checkout race in between two instances of | |
| 1350 ;;; vc-next-action. | |
| 1351 ;;; | |
| 1352 ;;; For VC's purposes, a workfile/master pair may have the following states: | |
| 1353 ;;; | |
| 1354 ;;; A. Unregistered. There is a workfile, there is no master. | |
| 1355 ;;; | |
| 1356 ;;; B. Registered and not locked by anyone. | |
| 1357 ;;; | |
| 1358 ;;; C. Locked by calling user and unchanged. | |
| 1359 ;;; | |
| 1360 ;;; D. Locked by the calling user and changed. | |
| 1361 ;;; | |
| 1362 ;;; E. Locked by someone other than the calling user. | |
| 1363 ;;; | |
| 1364 ;;; This makes for 25 states and 20 error conditions. Here's the matrix: | |
| 1365 ;;; | |
| 1366 ;;; VC's idea of state | |
| 1367 ;;; | | |
| 1368 ;;; V Actual state RCS action SCCS action Effect | |
| 1369 ;;; A B C D E | |
| 1370 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin | |
| 1371 ;;; B 5 . 6 7 8 co -l get -e checkout | |
| 1372 ;;; C 9 10 . 11 12 co -u unget; get revert | |
| 1373 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin | |
| 1374 ;;; E 17 18 19 20 . rcs -u -M ; rcs -l unget -n ; get -g steal lock | |
| 1375 ;;; | |
| 1376 ;;; All commands take the master file name as a last argument (not shown). | |
| 1377 ;;; | |
| 1378 ;;; In the discussion below, a "self-race" is a pathological situation in | |
| 1379 ;;; which VC operations are being attempted simultaneously by two or more | |
| 1380 ;;; Emacsen running under the same username. | |
| 1381 ;;; | |
| 1382 ;;; The vc-next-action code has the following windows: | |
| 1383 ;;; | |
| 1384 ;;; Window P: | |
| 1385 ;;; Between the check for existence of a master file and the call to | |
| 1386 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may | |
| 1387 ;;; never close if the initial-comment feature is on. | |
| 1388 ;;; | |
| 1389 ;;; Window Q: | |
| 1390 ;;; Between the call to vc-workfile-unchanged-p in and the immediately | |
| 1391 ;;; following revert (apparent state C). | |
| 1392 ;;; | |
| 1393 ;;; Window R: | |
| 1394 ;;; Between the call to vc-workfile-unchanged-p in and the following | |
| 1395 ;;; checkin (apparent state D). This window may never close. | |
| 1396 ;;; | |
| 1397 ;;; Window S: | |
| 1398 ;;; Between the unlock and the immediately following checkout during a | |
| 1399 ;;; revert operation (apparent state C). Included in window Q. | |
| 1400 ;;; | |
| 1401 ;;; Window T: | |
| 1402 ;;; Between vc-locking-user and the following checkout (apparent state B). | |
| 1403 ;;; | |
| 1404 ;;; Window U: | |
| 1405 ;;; Between vc-locking-user and the following revert (apparent state C). | |
| 1406 ;;; Includes windows Q and S. | |
| 1407 ;;; | |
| 1408 ;;; Window V: | |
| 1409 ;;; Between vc-locking-user and the following checkin (apparent state | |
| 1410 ;;; D). This window may never be closed if the user fails to complete the | |
| 1411 ;;; checkin message. Includes window R. | |
| 1412 ;;; | |
| 1413 ;;; Window W: | |
| 1414 ;;; Between vc-locking-user and the following steal-lock (apparent | |
| 1415 ;;; state E). This window may never cloce if the user fails to complete | |
| 1416 ;;; the steal-lock message. Includes window X. | |
| 1417 ;;; | |
| 1418 ;;; Window X: | |
| 1419 ;;; Between the unlock and the immediately following re-lock during a | |
| 1420 ;;; steal-lock operation (apparent state E). This window may never cloce | |
| 1421 ;;; if the user fails to complete the steal-lock message. | |
| 1422 ;;; | |
| 1423 ;;; Errors: | |
| 1424 ;;; | |
| 1425 ;;; Apparent state A --- | |
| 1426 ;;; | |
| 1427 ;;; 1. File looked unregistered but is actually registered and not locked. | |
| 1428 ;;; | |
| 1429 ;;; Potential cause: someone else's admin during window P, with | |
| 1430 ;;; caller's admin happening before their checkout. | |
| 1431 ;;; | |
| 1432 ;;; RCS: ci will fail with a "no lock set by <user>" message. | |
| 1433 ;;; SCCS: admin will fail with error (ad19). | |
| 1434 ;;; | |
| 1435 ;;; We can let these errors be passed up to the user. | |
| 1436 ;;; | |
| 1437 ;;; 2. File looked unregistered but is actually locked by caller, unchanged. | |
| 1438 ;;; | |
| 1439 ;;; Potential cause: self-race during window P. | |
| 1440 ;;; | |
| 1441 ;;; RCS: will revert the file to the last saved version and unlock it. | |
| 1442 ;;; SCCS: will fail with error (ad19). | |
| 1443 ;;; | |
| 1444 ;;; Either of these consequences is acceptable. | |
| 1445 ;;; | |
| 1446 ;;; 3. File looked unregistered but is actually locked by caller, changed. | |
| 1447 ;;; | |
| 1448 ;;; Potential cause: self-race during window P. | |
| 1449 ;;; | |
| 1450 ;;; RCS: will register the caller's workfile as a delta with a | |
| 1451 ;;; null change comment (the -t- switch will be ignored). | |
| 1452 ;;; SCCS: will fail with error (ad19). | |
| 1453 ;;; | |
| 1454 ;;; 4. File looked unregistered but is locked by someone else. | |
| 1455 ;;; | |
| 1456 ;;; Potential cause: someone else's admin during window P, with | |
| 1457 ;;; caller's admin happening *after* their checkout. | |
| 1458 ;;; | |
| 1459 ;;; RCS: will fail with a "no lock set by <user>" message. | |
| 1460 ;;; SCCS: will fail with error (ad19). | |
| 1461 ;;; | |
| 1462 ;;; We can let these errors be passed up to the user. | |
| 1463 ;;; | |
| 1464 ;;; Apparent state B --- | |
| 1465 ;;; | |
| 1466 ;;; 5. File looked registered and not locked, but is actually unregistered. | |
| 1467 ;;; | |
| 1468 ;;; Potential cause: master file got nuked during window P. | |
| 1469 ;;; | |
| 1470 ;;; RCS: will fail with "RCS/<file>: No such file or directory" | |
| 1471 ;;; SCCS: will fail with error ut4. | |
| 1472 ;;; | |
| 1473 ;;; We can let these errors be passed up to the user. | |
| 1474 ;;; | |
| 1475 ;;; 6. File looked registered and not locked, but is actually locked by the | |
| 1476 ;;; calling user and unchanged. | |
| 1477 ;;; | |
| 1478 ;;; Potential cause: self-race during window T. | |
| 1479 ;;; | |
| 1480 ;;; RCS: in the same directory as the previous workfile, co -l will fail | |
| 1481 ;;; with "co error: writable foo exists; checkout aborted". In any other | |
| 1482 ;;; directory, checkout will succeed. | |
| 1483 ;;; SCCS: will fail with ge17. | |
| 1484 ;;; | |
| 1485 ;;; Either of these consequences is acceptable. | |
| 1486 ;;; | |
| 1487 ;;; 7. File looked registered and not locked, but is actually locked by the | |
| 1488 ;;; calling user and changed. | |
| 1489 ;;; | |
| 1490 ;;; As case 6. | |
| 1491 ;;; | |
| 1492 ;;; 8. File looked registered and not locked, but is actually locked by another | |
| 1493 ;;; user. | |
| 1494 ;;; | |
| 1495 ;;; Potential cause: someone else checks it out during window T. | |
| 1496 ;;; | |
| 1497 ;;; RCS: co error: revision 1.3 already locked by <user> | |
| 1498 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it). | |
| 1499 ;;; | |
| 1500 ;;; We can let these errors be passed up to the user. | |
| 1501 ;;; | |
| 1502 ;;; Apparent state C --- | |
| 1503 ;;; | |
| 1504 ;;; 9. File looks locked by calling user and unchanged, but is unregistered. | |
| 1505 ;;; | |
| 1506 ;;; As case 5. | |
| 1507 ;;; | |
| 1508 ;;; 10. File looks locked by calling user and unchanged, but is actually not | |
| 1509 ;;; locked. | |
| 1510 ;;; | |
| 1511 ;;; Potential cause: a self-race in window U, or by the revert's | |
| 1512 ;;; landing during window X of some other user's steal-lock or window S | |
| 1513 ;;; of another user's revert. | |
| 1514 ;;; | |
| 1515 ;;; RCS: succeeds, refreshing the file from the identical version in | |
| 1516 ;;; the master. | |
| 1517 ;;; SCCS: fails with error ut4 (p file nonexistent). | |
| 1518 ;;; | |
| 1519 ;;; Either of these consequences is acceptable. | |
| 1520 ;;; | |
| 1521 ;;; 11. File is locked by calling user. It looks unchanged, but is actually | |
| 1522 ;;; changed. | |
| 1523 ;;; | |
| 1524 ;;; Potential cause: the file would have to be touched by a self-race | |
| 1525 ;;; during window Q. | |
| 1526 ;;; | |
| 1527 ;;; The revert will succeed, removing whatever changes came with | |
| 1528 ;;; the touch. It is theoretically possible that work could be lost. | |
| 1529 ;;; | |
| 1530 ;;; 12. File looks like it's locked by the calling user and unchanged, but | |
| 1531 ;;; it's actually locked by someone else. | |
| 1532 ;;; | |
| 1533 ;;; Potential cause: a steal-lock in window V. | |
| 1534 ;;; | |
| 1535 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u | |
| 1536 ;;; SCCS: fails with error un2 | |
| 1537 ;;; | |
| 1538 ;;; We can pass these errors up to the user. | |
| 1539 ;;; | |
| 1540 ;;; Apparent state D --- | |
| 1541 ;;; | |
| 1542 ;;; 13. File looks like it's locked by the calling user and changed, but it's | |
| 1543 ;;; actually unregistered. | |
| 1544 ;;; | |
| 1545 ;;; Potential cause: master file got nuked during window P. | |
| 1546 ;;; | |
| 1547 ;;; RCS: Checks in the user's version as an initial delta. | |
| 1548 ;;; SCCS: will fail with error ut4. | |
| 1549 ;;; | |
| 1550 ;;; This case is kind of nasty. It means VC may fail to detect the | |
| 1551 ;;; loss of previous version information. | |
| 1552 ;;; | |
| 1553 ;;; 14. File looks like it's locked by the calling user and changed, but it's | |
| 1554 ;;; actually unlocked. | |
| 1555 ;;; | |
| 1556 ;;; Potential cause: self-race in window V, or the checkin happening | |
| 1557 ;;; during the window X of someone else's steal-lock or window S of | |
| 1558 ;;; someone else's revert. | |
| 1559 ;;; | |
| 1560 ;;; RCS: ci will fail with "no lock set by <user>". | |
| 1561 ;;; SCCS: delta will fail with error ut4. | |
| 1562 ;;; | |
| 1563 ;;; 15. File looks like it's locked by the calling user and changed, but it's | |
| 1564 ;;; actually locked by the calling user and unchanged. | |
| 1565 ;;; | |
| 1566 ;;; Potential cause: another self-race --- a whole checkin/checkout | |
| 1567 ;;; sequence by the calling user would have to land in window R. | |
| 1568 ;;; | |
| 1569 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual. | |
| 1570 ;;; RCS: reverts to the file state as of the second user's checkin, leaving | |
| 1571 ;;; the file unlocked. | |
| 1572 ;;; | |
| 1573 ;;; It is theoretically possible that work could be lost under RCS. | |
| 1574 ;;; | |
| 1575 ;;; 16. File looks like it's locked by the calling user and changed, but it's | |
| 1576 ;;; actually locked by a different user. | |
| 1577 ;;; | |
| 1578 ;;; RCS: ci error: no lock set by <user> | |
| 1579 ;;; SCCS: unget will fail with error un2 | |
| 1580 ;;; | |
| 1581 ;;; We can pass these errors up to the user. | |
| 1582 ;;; | |
| 1583 ;;; Apparent state E --- | |
| 1584 ;;; | |
| 1585 ;;; 17. File looks like it's locked by some other user, but it's actually | |
| 1586 ;;; unregistered. | |
| 1587 ;;; | |
| 1588 ;;; As case 13. | |
| 1589 ;;; | |
| 1590 ;;; 18. File looks like it's locked by some other user, but it's actually | |
| 1591 ;;; unlocked. | |
| 1592 ;;; | |
| 1593 ;;; Potential cause: someone released a lock during window W. | |
| 1594 ;;; | |
| 1595 ;;; RCS: The calling user will get the lock on the file. | |
| 1596 ;;; SCCS: unget -n will fail with cm4. | |
| 1597 ;;; | |
| 1598 ;;; Either of these consequences will be OK. | |
| 1599 ;;; | |
| 1600 ;;; 19. File looks like it's locked by some other user, but it's actually | |
| 1601 ;;; locked by the calling user and unchanged. | |
| 1602 ;;; | |
| 1603 ;;; Potential cause: the other user relinquishing a lock followed by | |
| 1604 ;;; a self-race, both in window W. | |
| 1605 ;;; | |
| 1606 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making | |
| 1607 ;;; the sequence a no-op. | |
| 1608 ;;; | |
| 1609 ;;; 20. File looks like it's locked by some other user, but it's actually | |
| 1610 ;;; locked by the calling user and changed. | |
| 1611 ;;; | |
| 1612 ;;; As case 19. | |
| 1613 ;;; | |
| 1614 ;;; PROBLEM CASES: | |
| 1615 ;;; | |
| 1616 ;;; In order of decreasing severity: | |
| 1617 ;;; | |
| 1618 ;;; Cases 11 and 15 under RCS are the only one that potentially lose work. | |
| 1619 ;;; They would require a self-race for this to happen. | |
| 1620 ;;; | |
| 1621 ;;; Case 13 in RCS loses information about previous deltas, retaining | |
| 1622 ;;; only the information in the current workfile. This can only happen | |
| 1623 ;;; if the master file gets nuked in window P. | |
| 1624 ;;; | |
| 1625 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with | |
| 1626 ;;; no change comment in the master. This would require a self-race in | |
| 1627 ;;; window P or R respectively. | |
| 1628 ;;; | |
| 1629 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes. | |
| 1630 ;;; | |
| 1631 ;;; Unfortunately, it appears to me that no recovery is possible in these | |
| 1632 ;;; cases. They don't yield error messages, so there's no way to tell that | |
| 1633 ;;; a race condition has occurred. | |
| 1634 ;;; | |
| 1635 ;;; All other cases don't change either the workfile or the master, and | |
| 1636 ;;; trigger command errors which the user will see. | |
| 1637 ;;; | |
| 1638 ;;; Thus, there is no explicit recovery code. | |
| 1639 | |
| 1640 ;;; vc.el ends here |
