diff options
| author | Stefan Monnier | 2003-05-05 15:42:27 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-05-05 15:42:27 +0000 |
| commit | 1fd3454a347c5d55b996f5ae1a334e2ca4769e0f (patch) | |
| tree | d9f58259837d27d9bf48ac3a45267d127d44259e | |
| parent | adec392eb2463bd7f44417b7617776b8af1cc7ab (diff) | |
| download | emacs-1fd3454a347c5d55b996f5ae1a334e2ca4769e0f.tar.gz emacs-1fd3454a347c5d55b996f5ae1a334e2ca4769e0f.zip | |
First cut at vc-svn.el.
| -rw-r--r-- | lisp/ChangeLog | 48 | ||||
| -rw-r--r-- | lisp/vc-svn.el | 644 |
2 files changed, 690 insertions, 2 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2b1f04dbd84..dc91744f090 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,7 +1,30 @@ | |||
| 1 | 2003-05-05 Stefan Monnier <monnier@cs.yale.edu> | ||
| 2 | |||
| 3 | * vc-svn.el: New file. | ||
| 4 | |||
| 1 | 2003-05-05 John Paul Wallington <jpw@gnu.org> | 5 | 2003-05-05 John Paul Wallington <jpw@gnu.org> |
| 2 | 6 | ||
| 3 | * emacs-lisp/autoload.el (batch-update-autoloads): Call | 7 | * emacs-lisp/autoload.el (batch-update-autoloads): |
| 4 | `update-directory-autoloads'. | 8 | Call `update-directory-autoloads'. |
| 9 | |||
| 10 | 2003-05-04 Stefan Monnier <monnier@cs.yale.edu> | ||
| 11 | |||
| 12 | * uniquify.el: Move provide to end of file. | ||
| 13 | (uniquify-ref-base, uniquify-ref-filename, uniquify-ref-buffer) | ||
| 14 | (uniquify-ref-proposed, uniquify-set-proposed): Remove. | ||
| 15 | (uniquify-item): New struct. Update users of uniquify-ref-*. | ||
| 16 | (uniquify-get-proposed-name, uniquify-rationalize-a-list): | ||
| 17 | Make `depth' optional. | ||
| 18 | (uniquify-non-file-buffer-names): Remove. | ||
| 19 | (uniquify-rationalize-file-buffer-names): Don't set it up. | ||
| 20 | Use uniquify-make-item and don't pass the now-optional depth. | ||
| 21 | (uniquify-rationalize-conflicting-sublist): Check the new buffer | ||
| 22 | name directly instead of relying on uniquify-non-file-buffer-names. | ||
| 23 | (uniquify-rename-buffer): Use with-current-buffer and pass | ||
| 24 | the `unique' arg to rename-buffer. | ||
| 25 | |||
| 26 | * vc-mcvs.el (vc-mcvs-mode-line-string): Fix thinko. | ||
| 27 | (vc-mcvs-rename-file): New function. | ||
| 5 | 28 | ||
| 6 | 2003-05-04 Emmanuel Briot <briot@gnat.com> | 29 | 2003-05-04 Emmanuel Briot <briot@gnat.com> |
| 7 | 30 | ||
| @@ -21,6 +44,20 @@ | |||
| 21 | toolbar/gud-run.pbm, toolbar/gud-step.pbm, toolbar/gud-up.pbm: | 44 | toolbar/gud-run.pbm, toolbar/gud-step.pbm, toolbar/gud-up.pbm: |
| 22 | Correct size for cleaner bitmaps. | 45 | Correct size for cleaner bitmaps. |
| 23 | 46 | ||
| 47 | 2003-05-03 Stefan Monnier <monnier@cs.yale.edu> | ||
| 48 | |||
| 49 | * emacs-lisp/cl-extra.el (cl-map-keymap): Redefine as alias. | ||
| 50 | (cl-map-keymap-recursively): Use map-keymap. | ||
| 51 | (cl-macroexpand-all): Don't quote functions. | ||
| 52 | |||
| 53 | * emacs-lisp/lucid.el (cl-map-keymap): Be careful with aliases. | ||
| 54 | |||
| 55 | * emacs-lisp/advice.el (ad-get-enabled-advices, ad-special-forms) | ||
| 56 | (ad-arglist, ad-subr-arglist): Use push and match-string. | ||
| 57 | (ad-make-advised-docstring): Extract & reinsert the usage info. | ||
| 58 | |||
| 59 | * help-fns.el (help-add-fundoc-usage): Allow arglist to be a string. | ||
| 60 | |||
| 24 | 2003-05-03 Nick Roberts <nick@nick.uklinux.net> | 61 | 2003-05-03 Nick Roberts <nick@nick.uklinux.net> |
| 25 | 62 | ||
| 26 | * gdb-ui.el (breakpoint-enabled-icon, breakpoint-disabled-icon): | 63 | * gdb-ui.el (breakpoint-enabled-icon, breakpoint-disabled-icon): |
| @@ -62,6 +99,13 @@ | |||
| 62 | 99 | ||
| 63 | 2003-04-30 Stefan Monnier <monnier@cs.yale.edu> | 100 | 2003-04-30 Stefan Monnier <monnier@cs.yale.edu> |
| 64 | 101 | ||
| 102 | * pcvs.el (cvs-vc-command-advice): Don't parse "cvs update -p" output. | ||
| 103 | (cvs-mode-find-file): Don't complain if bound to a non-mouse event. | ||
| 104 | |||
| 105 | * textmodes/fill.el (text-property-default-nonsticky): Add fill-space. | ||
| 106 | (fill-delete-newlines): Respect the new property. | ||
| 107 | (fill-newline): Use the property instead of leaving "spurious" spaces. | ||
| 108 | |||
| 65 | * emacs-lisp/easymenu.el (easy-menu-get-map): Correctly handle | 109 | * emacs-lisp/easymenu.el (easy-menu-get-map): Correctly handle |
| 66 | non-submap bindings. | 110 | non-submap bindings. |
| 67 | 111 | ||
diff --git a/lisp/vc-svn.el b/lisp/vc-svn.el new file mode 100644 index 00000000000..780b71746ce --- /dev/null +++ b/lisp/vc-svn.el | |||
| @@ -0,0 +1,644 @@ | |||
| 1 | ;;; vc-svn.el --- non-resident support for Subversion version-control | ||
| 2 | |||
| 3 | ;; Copyright (C) 1995,98,99,2000,2001,2002 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: FSF (see vc.el for full credits) | ||
| 6 | ;; Maintainer: Stefan Monnier <monnier@gnu.org> | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation; either version 2, or (at your option) | ||
| 13 | ;; any later version. | ||
| 14 | |||
| 15 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | ||
| 22 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
| 23 | ;; Boston, MA 02111-1307, USA. | ||
| 24 | |||
| 25 | ;;; Commentary: | ||
| 26 | |||
| 27 | ;; This is preliminary support for Subversion (http://subversion.tigris.org/). | ||
| 28 | ;; It started as `sed s/cvs/svn/ vc.cvs.el' (from version 1.56) | ||
| 29 | ;; and hasn't been completely fixed since. | ||
| 30 | |||
| 31 | ;; Sync'd with Subversion's vc-svn.el as of revision 5801. | ||
| 32 | |||
| 33 | ;;; Bugs: | ||
| 34 | |||
| 35 | ;; - VC-dired is either not working or (really) dog slow. | ||
| 36 | ;; - vc-print-log does not always jump to the proper log entry because | ||
| 37 | ;; it tries to jump to version 1234 even if there's only an entry | ||
| 38 | ;; for 1232 (because the file hasn't changed since). | ||
| 39 | |||
| 40 | ;;; Code: | ||
| 41 | |||
| 42 | (eval-when-compile | ||
| 43 | (require 'vc)) | ||
| 44 | |||
| 45 | ;;; | ||
| 46 | ;;; Customization options | ||
| 47 | ;;; | ||
| 48 | |||
| 49 | (defcustom vc-svn-global-switches nil | ||
| 50 | "*Global switches to pass to any SVN command." | ||
| 51 | :type '(choice (const :tag "None" nil) | ||
| 52 | (string :tag "Argument String") | ||
| 53 | (repeat :tag "Argument List" | ||
| 54 | :value ("") | ||
| 55 | string)) | ||
| 56 | :version "21.4" | ||
| 57 | :group 'vc) | ||
| 58 | |||
| 59 | (defcustom vc-svn-register-switches nil | ||
| 60 | "*Extra switches for registering a file into SVN. | ||
| 61 | A string or list of strings passed to the checkin program by | ||
| 62 | \\[vc-register]." | ||
| 63 | :type '(choice (const :tag "None" nil) | ||
| 64 | (string :tag "Argument String") | ||
| 65 | (repeat :tag "Argument List" | ||
| 66 | :value ("") | ||
| 67 | string)) | ||
| 68 | :version "21.1" | ||
| 69 | :group 'vc) | ||
| 70 | |||
| 71 | (defcustom vc-svn-diff-switches nil | ||
| 72 | "*A string or list of strings specifying extra switches for svn diff under VC." | ||
| 73 | :type '(choice (const :tag "None" nil) | ||
| 74 | (string :tag "Argument String") | ||
| 75 | (repeat :tag "Argument List" | ||
| 76 | :value ("") | ||
| 77 | string)) | ||
| 78 | :version "21.1" | ||
| 79 | :group 'vc) | ||
| 80 | |||
| 81 | (defcustom vc-svn-header (or (cdr (assoc 'SVN vc-header-alist)) '("\$Id\$")) | ||
| 82 | "*Header keywords to be inserted by `vc-insert-headers'." | ||
| 83 | :version "21.1" | ||
| 84 | :type '(repeat string) | ||
| 85 | :group 'vc) | ||
| 86 | |||
| 87 | (defcustom vc-svn-use-edit nil | ||
| 88 | "*Non-nil means to use `svn edit' to \"check out\" a file. | ||
| 89 | This is only meaningful if you don't use the implicit checkout model | ||
| 90 | \(i.e. if you have $SVNREAD set)." | ||
| 91 | :type 'boolean | ||
| 92 | :version "21.1" | ||
| 93 | :group 'vc) | ||
| 94 | |||
| 95 | (defcustom vc-svn-stay-local t | ||
| 96 | "*Non-nil means use local operations when possible for remote repositories. | ||
| 97 | This avoids slow queries over the network and instead uses heuristics | ||
| 98 | and past information to determine the current status of a file. | ||
| 99 | |||
| 100 | The value can also be a regular expression or list of regular | ||
| 101 | expressions to match against the host name of a repository; then VC | ||
| 102 | only stays local for hosts that match it. Alternatively, the value | ||
| 103 | can be a list of regular expressions where the first element is the | ||
| 104 | symbol `except'; then VC always stays local except for hosts matched | ||
| 105 | by these regular expressions." | ||
| 106 | :type '(choice (const :tag "Always stay local" t) | ||
| 107 | (const :tag "Don't stay local" nil) | ||
| 108 | (list :format "\nExamine hostname and %v" :tag "Examine hostname ..." | ||
| 109 | (set :format "%v" :inline t (const :format "%t" :tag "don't" except)) | ||
| 110 | (regexp :format " stay local,\n%t: %v" :tag "if it matches") | ||
| 111 | (repeat :format "%v%i\n" :inline t (regexp :tag "or")))) | ||
| 112 | :version "21.1" | ||
| 113 | :group 'vc) | ||
| 114 | |||
| 115 | ;;; | ||
| 116 | ;;; State-querying functions | ||
| 117 | ;;; | ||
| 118 | |||
| 119 | ;;;###autoload (defun vc-svn-registered (f) | ||
| 120 | ;;;###autoload (when (file-readable-p (expand-file-name | ||
| 121 | ;;;###autoload ".svn/entries" (file-name-directory f))) | ||
| 122 | ;;;###autoload (load "vc-svn") | ||
| 123 | ;;;###autoload (vc-svn-registered f))) | ||
| 124 | |||
| 125 | (defun vc-svn-registered (file) | ||
| 126 | "Check if FILE is SVN registered." | ||
| 127 | (when (file-readable-p (expand-file-name ".svn/entries" | ||
| 128 | (file-name-directory file))) | ||
| 129 | (with-temp-buffer | ||
| 130 | (cd (file-name-directory file)) | ||
| 131 | (condition-case nil | ||
| 132 | (vc-svn-command t 0 file "status" "-v") | ||
| 133 | ;; We can't find an `svn' executable. We could also deregister SVN. | ||
| 134 | (file-error nil) | ||
| 135 | (vc-svn-parse-status t) | ||
| 136 | (eq 'SVN (vc-file-getprop file 'vc-backend))))) | ||
| 137 | |||
| 138 | (defun vc-svn-state (file &optional localp) | ||
| 139 | "SVN-specific version of `vc-state'." | ||
| 140 | (setq localp (or localp (vc-svn-stay-local-p file))) | ||
| 141 | (with-temp-buffer | ||
| 142 | (cd (file-name-directory file)) | ||
| 143 | (vc-svn-command t 0 file "status" (if localp "-v" "-u")) | ||
| 144 | (vc-svn-parse-status localp) | ||
| 145 | (vc-file-getprop file 'vc-state))) | ||
| 146 | |||
| 147 | (defun vc-svn-state-heuristic (file) | ||
| 148 | "SVN-specific state heuristic." | ||
| 149 | (vc-svn-state file 'local)) | ||
| 150 | |||
| 151 | (defun vc-svn-dir-state (dir &optional localp) | ||
| 152 | "Find the SVN state of all files in DIR." | ||
| 153 | (setq localp (or localp (vc-svn-stay-local-p dir))) | ||
| 154 | (let ((default-directory dir)) | ||
| 155 | ;; Don't specify DIR in this command, the default-directory is | ||
| 156 | ;; enough. Otherwise it might fail with remote repositories. | ||
| 157 | (with-temp-buffer | ||
| 158 | (vc-svn-command t 0 nil "status" (if localp "-v" "-u")) | ||
| 159 | (vc-svn-parse-status localp)))) | ||
| 160 | |||
| 161 | (defun vc-svn-workfile-version (file) | ||
| 162 | "SVN-specific version of `vc-workfile-version'." | ||
| 163 | ;; There is no need to consult RCS headers under SVN, because we | ||
| 164 | ;; get the workfile version for free when we recognize that a file | ||
| 165 | ;; is registered in SVN. | ||
| 166 | (vc-svn-registered file) | ||
| 167 | (vc-file-getprop file 'vc-workfile-version)) | ||
| 168 | |||
| 169 | (defun vc-svn-checkout-model (file) | ||
| 170 | "SVN-specific version of `vc-checkout-model'." | ||
| 171 | ;; It looks like Subversion has no equivalent of CVSREAD. | ||
| 172 | 'implicit) | ||
| 173 | |||
| 174 | (defun vc-svn-mode-line-string (file) | ||
| 175 | "Return string for placement into the modeline for FILE. | ||
| 176 | Compared to the default implementation, this function does two things: | ||
| 177 | Handle the special case of a SVN file that is added but not yet | ||
| 178 | committed and support display of sticky tags." | ||
| 179 | (let* ((state (vc-state file)) | ||
| 180 | (rev (vc-workfile-version file)) | ||
| 181 | (sticky-tag (vc-file-getprop file 'vc-svn-sticky-tag)) | ||
| 182 | (sticky-tag-printable (and sticky-tag | ||
| 183 | (not (string= sticky-tag "")) | ||
| 184 | (concat "[" sticky-tag "]")))) | ||
| 185 | (cond ((string= rev "0") | ||
| 186 | ;; A file that is added but not yet committed. | ||
| 187 | "SVN @@") | ||
| 188 | ((or (eq state 'up-to-date) | ||
| 189 | (eq state 'needs-patch)) | ||
| 190 | (concat "SVN-" rev sticky-tag-printable)) | ||
| 191 | ((stringp state) | ||
| 192 | (concat "SVN:" state ":" rev sticky-tag-printable)) | ||
| 193 | (t | ||
| 194 | ;; Not just for the 'edited state, but also a fallback | ||
| 195 | ;; for all other states. Think about different symbols | ||
| 196 | ;; for 'needs-patch and 'needs-merge. | ||
| 197 | (concat "SVN:" rev sticky-tag-printable))))) | ||
| 198 | |||
| 199 | (defun vc-svn-dired-state-info (file) | ||
| 200 | "SVN-specific version of `vc-dired-state-info'." | ||
| 201 | (let* ((svn-state (vc-state file)) | ||
| 202 | (state (cond ((eq svn-state 'edited) "modified") | ||
| 203 | ((eq svn-state 'needs-patch) "patch") | ||
| 204 | ((eq svn-state 'needs-merge) "merge") | ||
| 205 | ;; FIXME: those two states cannot occur right now | ||
| 206 | ((eq svn-state 'unlocked-changes) "conflict") | ||
| 207 | ((eq svn-state 'locally-added) "added") | ||
| 208 | ))) | ||
| 209 | (if state (concat "(" state ")")))) | ||
| 210 | |||
| 211 | |||
| 212 | ;;; | ||
| 213 | ;;; State-changing functions | ||
| 214 | ;;; | ||
| 215 | |||
| 216 | (defun vc-svn-register (file &optional rev comment) | ||
| 217 | "Register FILE into the SVN version-control system. | ||
| 218 | COMMENT can be used to provide an initial description of FILE. | ||
| 219 | |||
| 220 | `vc-register-switches' and `vc-svn-register-switches' are passed to | ||
| 221 | the SVN command (in that order)." | ||
| 222 | (let ((switches (append | ||
| 223 | (if (stringp vc-register-switches) | ||
| 224 | (list vc-register-switches) | ||
| 225 | vc-register-switches) | ||
| 226 | (if (stringp vc-svn-register-switches) | ||
| 227 | (list vc-svn-register-switches) | ||
| 228 | vc-svn-register-switches)))) | ||
| 229 | |||
| 230 | (apply 'vc-svn-command nil 0 file | ||
| 231 | "add" | ||
| 232 | ;; (and comment (string-match "[^\t\n ]" comment) | ||
| 233 | ;; (concat "-m" comment)) | ||
| 234 | switches))) | ||
| 235 | |||
| 236 | (defun vc-svn-responsible-p (file) | ||
| 237 | "Return non-nil if SVN thinks it is responsible for FILE." | ||
| 238 | (file-directory-p (expand-file-name ".svn" | ||
| 239 | (if (file-directory-p file) | ||
| 240 | file | ||
| 241 | (file-name-directory file))))) | ||
| 242 | |||
| 243 | (defalias 'vc-svn-could-register 'vc-svn-responsible-p | ||
| 244 | "Return non-nil if FILE could be registered in SVN. | ||
| 245 | This is only possible if SVN is responsible for FILE's directory.") | ||
| 246 | |||
| 247 | (defun vc-svn-checkin (file rev comment) | ||
| 248 | "SVN-specific version of `vc-backend-checkin'." | ||
| 249 | (let ((switches (if (stringp vc-checkin-switches) | ||
| 250 | (list vc-checkin-switches) | ||
| 251 | vc-checkin-switches)) | ||
| 252 | status) | ||
| 253 | (setq status (apply 'vc-svn-command nil 1 file | ||
| 254 | "ci" (list* "-m" comment switches))) | ||
| 255 | (set-buffer "*vc*") | ||
| 256 | (goto-char (point-min)) | ||
| 257 | (unless (equal status 0) | ||
| 258 | ;; Check checkin problem. | ||
| 259 | (cond | ||
| 260 | ((re-search-forward "Up-to-date check failed" nil t) | ||
| 261 | (vc-file-setprop file 'vc-state 'needs-merge) | ||
| 262 | (error (substitute-command-keys | ||
| 263 | (concat "Up-to-date check failed: " | ||
| 264 | "type \\[vc-next-action] to merge in changes")))) | ||
| 265 | (t | ||
| 266 | (pop-to-buffer (current-buffer)) | ||
| 267 | (goto-char (point-min)) | ||
| 268 | (shrink-window-if-larger-than-buffer) | ||
| 269 | (error "Check-in failed")))) | ||
| 270 | ;; Update file properties | ||
| 271 | ;; (vc-file-setprop | ||
| 272 | ;; file 'vc-workfile-version | ||
| 273 | ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2)) | ||
| 274 | )) | ||
| 275 | |||
| 276 | (defun vc-svn-find-version (file rev buffer) | ||
| 277 | (apply 'vc-svn-command | ||
| 278 | buffer 0 file | ||
| 279 | "cat" | ||
| 280 | (and rev (not (string= rev "")) | ||
| 281 | (concat "-r" rev)) | ||
| 282 | (if (stringp vc-checkout-switches) | ||
| 283 | (list vc-checkout-switches) | ||
| 284 | vc-checkout-switches))) | ||
| 285 | |||
| 286 | (defun vc-svn-checkout (file &optional editable rev) | ||
| 287 | (message "Checking out %s..." file) | ||
| 288 | (with-current-buffer (or (get-file-buffer file) (current-buffer)) | ||
| 289 | (let ((switches (if (stringp vc-checkout-switches) | ||
| 290 | (list vc-checkout-switches) | ||
| 291 | vc-checkout-switches))) | ||
| 292 | (vc-call update file editable rev switches))) | ||
| 293 | (vc-mode-line file) | ||
| 294 | (message "Checking out %s...done" file)) | ||
| 295 | |||
| 296 | (defun vc-svn-update (file editable rev switches) | ||
| 297 | (if (and (file-exists-p file) (not rev)) | ||
| 298 | ;; If no revision was specified, just make the file writable | ||
| 299 | ;; if necessary (using `svn-edit' if requested). | ||
| 300 | (and editable (not (eq (vc-svn-checkout-model file) 'implicit)) | ||
| 301 | (if vc-svn-use-edit | ||
| 302 | (vc-svn-command nil 0 file "edit") | ||
| 303 | (set-file-modes file (logior (file-modes file) 128)) | ||
| 304 | (if (equal file buffer-file-name) (toggle-read-only -1)))) | ||
| 305 | ;; Check out a particular version (or recreate the file). | ||
| 306 | (vc-file-setprop file 'vc-workfile-version nil) | ||
| 307 | (apply 'vc-svn-command nil 0 file | ||
| 308 | "-w" | ||
| 309 | "update" | ||
| 310 | ;; default for verbose checkout: clear the sticky tag so | ||
| 311 | ;; that the actual update will get the head of the trunk | ||
| 312 | (if (or (not rev) (string= rev "")) | ||
| 313 | "-A" | ||
| 314 | (concat "-r" rev)) | ||
| 315 | switches))) | ||
| 316 | |||
| 317 | (defun vc-svn-revert (file &optional contents-done) | ||
| 318 | "Revert FILE to the version it was based on." | ||
| 319 | (unless contents-done | ||
| 320 | (vc-svn-command nil 0 file "revert")) | ||
| 321 | (unless (eq (vc-checkout-model file) 'implicit) | ||
| 322 | (if vc-svn-use-edit | ||
| 323 | (vc-svn-command nil 0 file "unedit") | ||
| 324 | ;; Make the file read-only by switching off all w-bits | ||
| 325 | (set-file-modes file (logand (file-modes file) 3950))))) | ||
| 326 | |||
| 327 | (defun vc-svn-merge (file first-version &optional second-version) | ||
| 328 | "Merge changes into current working copy of FILE. | ||
| 329 | The changes are between FIRST-VERSION and SECOND-VERSION." | ||
| 330 | (vc-svn-command nil 0 file | ||
| 331 | "update" "-kk" | ||
| 332 | (concat "-j" first-version) | ||
| 333 | (concat "-j" second-version)) | ||
| 334 | (vc-file-setprop file 'vc-state 'edited) | ||
| 335 | (with-current-buffer (get-buffer "*vc*") | ||
| 336 | (goto-char (point-min)) | ||
| 337 | (if (re-search-forward "conflicts during merge" nil t) | ||
| 338 | 1 ; signal error | ||
| 339 | 0))) ; signal success | ||
| 340 | |||
| 341 | (defun vc-svn-merge-news (file) | ||
| 342 | "Merge in any new changes made to FILE." | ||
| 343 | (message "Merging changes into %s..." file) | ||
| 344 | ;; (vc-file-setprop file 'vc-workfile-version nil) | ||
| 345 | (vc-file-setprop file 'vc-checkout-time 0) | ||
| 346 | (vc-svn-command nil 0 file "update") | ||
| 347 | ;; Analyze the merge result reported by SVN, and set | ||
| 348 | ;; file properties accordingly. | ||
| 349 | (with-current-buffer (get-buffer "*vc*") | ||
| 350 | (goto-char (point-min)) | ||
| 351 | ;; get new workfile version | ||
| 352 | (if (re-search-forward | ||
| 353 | "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t) | ||
| 354 | (vc-file-setprop file 'vc-workfile-version (match-string 1)) | ||
| 355 | (vc-file-setprop file 'vc-workfile-version nil)) | ||
| 356 | ;; get file status | ||
| 357 | (prog1 | ||
| 358 | (if (eq (buffer-size) 0) | ||
| 359 | 0 ;; there were no news; indicate success | ||
| 360 | (if (re-search-forward | ||
| 361 | (concat "^\\([CMUP] \\)?" | ||
| 362 | (regexp-quote (file-name-nondirectory file)) | ||
| 363 | "\\( already contains the differences between \\)?") | ||
| 364 | nil t) | ||
| 365 | (cond | ||
| 366 | ;; Merge successful, we are in sync with repository now | ||
| 367 | ((or (match-string 2) | ||
| 368 | (string= (match-string 1) "U ") | ||
| 369 | (string= (match-string 1) "P ")) | ||
| 370 | (vc-file-setprop file 'vc-state 'up-to-date) | ||
| 371 | (vc-file-setprop file 'vc-checkout-time | ||
| 372 | (nth 5 (file-attributes file))) | ||
| 373 | 0);; indicate success to the caller | ||
| 374 | ;; Merge successful, but our own changes are still in the file | ||
| 375 | ((string= (match-string 1) "M ") | ||
| 376 | (vc-file-setprop file 'vc-state 'edited) | ||
| 377 | 0);; indicate success to the caller | ||
| 378 | ;; Conflicts detected! | ||
| 379 | (t | ||
| 380 | (vc-file-setprop file 'vc-state 'edited) | ||
| 381 | 1);; signal the error to the caller | ||
| 382 | ) | ||
| 383 | (pop-to-buffer "*vc*") | ||
| 384 | (error "Couldn't analyze svn update result"))) | ||
| 385 | (message "Merging changes into %s...done" file)))) | ||
| 386 | |||
| 387 | |||
| 388 | ;;; | ||
| 389 | ;;; History functions | ||
| 390 | ;;; | ||
| 391 | |||
| 392 | (defun vc-svn-print-log (file) | ||
| 393 | "Get change log associated with FILE." | ||
| 394 | (save-current-buffer | ||
| 395 | (vc-setup-buffer nil) | ||
| 396 | (let ((inhibit-read-only t)) | ||
| 397 | (goto-char (point-min)) | ||
| 398 | ;; Add a line to tell log-view-mode what file this is. | ||
| 399 | (insert "Working file: " (file-relative-name file) "\n")) | ||
| 400 | (vc-svn-command | ||
| 401 | t | ||
| 402 | (if (and (vc-svn-stay-local-p file) (fboundp 'start-process)) 'async 0) | ||
| 403 | file "log"))) | ||
| 404 | |||
| 405 | (defun vc-svn-diff (file &optional oldvers newvers) | ||
| 406 | "Get a difference report using SVN between two versions of FILE." | ||
| 407 | (let (status (diff-switches-list (vc-diff-switches-list 'SVN))) | ||
| 408 | (if (string= (vc-workfile-version file) "0") | ||
| 409 | ;; This file is added but not yet committed; there is no master file. | ||
| 410 | (if (or oldvers newvers) | ||
| 411 | (error "No revisions of %s exist" file) | ||
| 412 | ;; We regard this as "changed". | ||
| 413 | ;; Diff it against /dev/null. | ||
| 414 | ;; Note: this is NOT a "svn diff". | ||
| 415 | (apply 'vc-do-command "*vc-diff*" | ||
| 416 | 1 "diff" file | ||
| 417 | (append diff-switches-list '("/dev/null")))) | ||
| 418 | (setq status | ||
| 419 | (apply 'vc-svn-command "*vc-diff*" | ||
| 420 | (if (and (vc-svn-stay-local-p file) | ||
| 421 | (or oldvers newvers) ; Svn diffs those locally. | ||
| 422 | (fboundp 'start-process)) | ||
| 423 | 'async | ||
| 424 | 1) | ||
| 425 | file "diff" | ||
| 426 | (append | ||
| 427 | (when oldvers | ||
| 428 | (list "-r" | ||
| 429 | (if newvers (concat oldvers ":" newvers) oldvers))) | ||
| 430 | (when diff-switches-list | ||
| 431 | (list "-x" (mapconcat 'identity diff-switches-list " ")))))) | ||
| 432 | (if (vc-svn-stay-local-p file) | ||
| 433 | 1 ;; async diff, pessimistic assumption | ||
| 434 | status)))) | ||
| 435 | |||
| 436 | (defun vc-svn-diff-tree (dir &optional rev1 rev2) | ||
| 437 | "Diff all files at and below DIR." | ||
| 438 | (with-current-buffer "*vc-diff*" | ||
| 439 | (setq default-directory dir) | ||
| 440 | (if (vc-svn-stay-local-p dir) | ||
| 441 | ;; local diff: do it filewise, and only for files that are modified | ||
| 442 | (vc-file-tree-walk | ||
| 443 | dir | ||
| 444 | (lambda (f) | ||
| 445 | (vc-exec-after | ||
| 446 | `(let ((coding-system-for-read (vc-coding-system-for-diff ',f))) | ||
| 447 | ;; possible optimization: fetch the state of all files | ||
| 448 | ;; in the tree via vc-svn-dir-state-heuristic | ||
| 449 | (unless (vc-up-to-date-p ',f) | ||
| 450 | (message "Looking at %s" ',f) | ||
| 451 | (vc-diff-internal ',f ',rev1 ',rev2)))))) | ||
| 452 | ;; svn diff: use a single call for the entire tree | ||
| 453 | (let ((coding-system-for-read (or coding-system-for-read 'undecided)) | ||
| 454 | (diff-switches-list (vc-diff-switches-list 'SVN))) | ||
| 455 | (apply 'vc-svn-command "*vc-diff*" 1 nil "diff" | ||
| 456 | (append | ||
| 457 | (when oldvers | ||
| 458 | (list "-r" | ||
| 459 | (if rev2 (concat rev1 ":" rev2) rev1))) | ||
| 460 | (when diff-switches-list | ||
| 461 | (list "-x" (mapconcat 'identity diff-switches-list " "))))))))) | ||
| 462 | |||
| 463 | ;;; | ||
| 464 | ;;; Snapshot system | ||
| 465 | ;;; | ||
| 466 | |||
| 467 | (defun vc-svn-create-snapshot (dir name branchp) | ||
| 468 | "Assign to DIR's current version a given NAME. | ||
| 469 | If BRANCHP is non-nil, the name is created as a branch (and the current | ||
| 470 | workspace is immediately moved to that new branch)." | ||
| 471 | (vc-svn-command nil 0 dir "tag" "-c" (if branchp "-b") name) | ||
| 472 | (when branchp (vc-svn-command nil 0 dir "update" "-r" name))) | ||
| 473 | |||
| 474 | (defun vc-svn-retrieve-snapshot (dir name update) | ||
| 475 | "Retrieve a snapshot at and below DIR. | ||
| 476 | NAME is the name of the snapshot; if it is empty, do a `svn update'. | ||
| 477 | If UPDATE is non-nil, then update (resynch) any affected buffers." | ||
| 478 | (with-current-buffer (get-buffer-create "*vc*") | ||
| 479 | (let ((default-directory dir) | ||
| 480 | (sticky-tag)) | ||
| 481 | (erase-buffer) | ||
| 482 | (if (or (not name) (string= name "")) | ||
| 483 | (vc-svn-command t 0 nil "update") | ||
| 484 | (vc-svn-command t 0 nil "update" "-r" name) | ||
| 485 | (setq sticky-tag name)) | ||
| 486 | (when update | ||
| 487 | (goto-char (point-min)) | ||
| 488 | (while (not (eobp)) | ||
| 489 | (if (looking-at "\\([CMUP]\\) \\(.*\\)") | ||
| 490 | (let* ((file (expand-file-name (match-string 2) dir)) | ||
| 491 | (state (match-string 1)) | ||
| 492 | (buffer (find-buffer-visiting file))) | ||
| 493 | (when buffer | ||
| 494 | (cond | ||
| 495 | ((or (string= state "U") | ||
| 496 | (string= state "P")) | ||
| 497 | (vc-file-setprop file 'vc-state 'up-to-date) | ||
| 498 | (vc-file-setprop file 'vc-workfile-version nil) | ||
| 499 | (vc-file-setprop file 'vc-checkout-time | ||
| 500 | (nth 5 (file-attributes file)))) | ||
| 501 | ((or (string= state "M") | ||
| 502 | (string= state "C")) | ||
| 503 | (vc-file-setprop file 'vc-state 'edited) | ||
| 504 | (vc-file-setprop file 'vc-workfile-version nil) | ||
| 505 | (vc-file-setprop file 'vc-checkout-time 0))) | ||
| 506 | (vc-file-setprop file 'vc-svn-sticky-tag sticky-tag) | ||
| 507 | (vc-resynch-buffer file t t)))) | ||
| 508 | (forward-line 1)))))) | ||
| 509 | |||
| 510 | |||
| 511 | ;;; | ||
| 512 | ;;; Miscellaneous | ||
| 513 | ;;; | ||
| 514 | |||
| 515 | ;; Subversion makes backups for us, so don't bother. | ||
| 516 | ;; (defalias 'vc-svn-make-version-backups-p 'vc-svn-stay-local-p | ||
| 517 | ;; "Return non-nil if version backups should be made for FILE.") | ||
| 518 | |||
| 519 | (defun vc-svn-check-headers () | ||
| 520 | "Check if the current file has any headers in it." | ||
| 521 | (save-excursion | ||
| 522 | (goto-char (point-min)) | ||
| 523 | (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\ | ||
| 524 | \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t))) | ||
| 525 | |||
| 526 | |||
| 527 | ;;; | ||
| 528 | ;;; Internal functions | ||
| 529 | ;;; | ||
| 530 | |||
| 531 | (defun vc-svn-command (buffer okstatus file &rest flags) | ||
| 532 | "A wrapper around `vc-do-command' for use in vc-svn.el. | ||
| 533 | The difference to vc-do-command is that this function always invokes `svn', | ||
| 534 | and that it passes `vc-svn-global-switches' to it before FLAGS." | ||
| 535 | (apply 'vc-do-command buffer okstatus "svn" file | ||
| 536 | (if (stringp vc-svn-global-switches) | ||
| 537 | (cons vc-svn-global-switches flags) | ||
| 538 | (append vc-svn-global-switches | ||
| 539 | flags)))) | ||
| 540 | |||
| 541 | (defun vc-svn-stay-local-p (file) | ||
| 542 | "Return non-nil if VC should stay local when handling FILE. | ||
| 543 | See `vc-svn-stay-local'." | ||
| 544 | (when vc-svn-stay-local | ||
| 545 | (let* ((dirname (if (file-directory-p file) | ||
| 546 | (directory-file-name file) | ||
| 547 | (file-name-directory file))) | ||
| 548 | (prop | ||
| 549 | (or (vc-file-getprop dirname 'vc-svn-stay-local-p) | ||
| 550 | (vc-file-setprop | ||
| 551 | dirname 'vc-svn-stay-local-p | ||
| 552 | (let ((rootname (expand-file-name ".svn/entries" dirname))) | ||
| 553 | (cond | ||
| 554 | ((not (file-readable-p rootname)) 'no) | ||
| 555 | ((stringp vc-svn-stay-local) | ||
| 556 | (with-temp-buffer | ||
| 557 | (let ((coding-system-for-read | ||
| 558 | (or file-name-coding-system | ||
| 559 | default-file-name-coding-system))) | ||
| 560 | (vc-insert-file rootname)) | ||
| 561 | (goto-char (point-min)) | ||
| 562 | (when (re-search-forward | ||
| 563 | (concat "name=\"svn:this_dir\"[\n\t ]*" | ||
| 564 | "url=\"\\([^\"]+\\)\"") nil t) | ||
| 565 | (let ((hostname (match-string 1))) | ||
| 566 | (if (not hostname) | ||
| 567 | 'no | ||
| 568 | (let* ((stay-local t) | ||
| 569 | (rx | ||
| 570 | (cond | ||
| 571 | ;; vc-svn-stay-local: rx | ||
| 572 | ((stringp vc-svn-stay-local) | ||
| 573 | vc-svn-stay-local) | ||
| 574 | ;; vc-svn-stay-local: '( [except] rx ... ) | ||
| 575 | ((consp vc-svn-stay-local) | ||
| 576 | (mapconcat | ||
| 577 | 'identity | ||
| 578 | (if (not (eq (car vc-svn-stay-local) | ||
| 579 | 'except)) | ||
| 580 | vc-svn-stay-local | ||
| 581 | (setq stay-local nil) | ||
| 582 | (cdr vc-svn-stay-local)) | ||
| 583 | "\\|"))))) | ||
| 584 | (if (not rx) | ||
| 585 | 'yes | ||
| 586 | (if (not (string-match rx hostname)) | ||
| 587 | (setq stay-local (not stay-local))) | ||
| 588 | (if stay-local | ||
| 589 | 'yes | ||
| 590 | 'no)))))))))))))) | ||
| 591 | (if (eq prop 'yes) t nil)))) | ||
| 592 | |||
| 593 | (defun vc-svn-parse-status (localp) | ||
| 594 | "Parse output of \"svn status\" command in the current buffer. | ||
| 595 | Set file properties accordingly. Unless FULL is t, parse only | ||
| 596 | essential information." | ||
| 597 | (let (file status) | ||
| 598 | (goto-char (point-min)) | ||
| 599 | (while (re-search-forward | ||
| 600 | "^[ ADMCI?!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\) +" nil t) | ||
| 601 | (setq file (expand-file-name | ||
| 602 | (buffer-substring (point) (line-end-position)))) | ||
| 603 | (setq status (char-after (line-beginning-position))) | ||
| 604 | (unless (eq status ??) | ||
| 605 | (vc-file-setprop file 'vc-backend 'SVN) | ||
| 606 | (vc-file-setprop file 'vc-workfile-version (match-string 2)) | ||
| 607 | (vc-file-setprop | ||
| 608 | file 'vc-state | ||
| 609 | (cond | ||
| 610 | ((eq status ?\ ) | ||
| 611 | (if (eq (char-after (match-beginning 1)) ?*) | ||
| 612 | 'needs-patch | ||
| 613 | (vc-file-setprop file 'vc-checkout-time | ||
| 614 | (nth 5 (file-attributes file))) | ||
| 615 | 'up-to-date)) | ||
| 616 | ((eq status ?A) | ||
| 617 | (vc-file-setprop file 'vc-checkout-time 0) | ||
| 618 | 'edited) | ||
| 619 | ((memq status '(?M ?C)) | ||
| 620 | (if (eq (char-after (match-beginning 1)) ?*) | ||
| 621 | 'needs-merge | ||
| 622 | 'edited)) | ||
| 623 | (t 'edited))))))) | ||
| 624 | |||
| 625 | (defun vc-svn-dir-state-heuristic (dir) | ||
| 626 | "Find the SVN state of all files in DIR, using only local information." | ||
| 627 | (vc-svn-dir-state dir 'local)) | ||
| 628 | |||
| 629 | (defun vc-svn-valid-symbolic-tag-name-p (tag) | ||
| 630 | "Return non-nil if TAG is a valid symbolic tag name." | ||
| 631 | ;; According to the SVN manual, a valid symbolic tag must start with | ||
| 632 | ;; an uppercase or lowercase letter and can contain uppercase and | ||
| 633 | ;; lowercase letters, digits, `-', and `_'. | ||
| 634 | (and (string-match "^[a-zA-Z]" tag) | ||
| 635 | (not (string-match "[^a-z0-9A-Z-_]" tag)))) | ||
| 636 | |||
| 637 | (defun vc-svn-valid-version-number-p (tag) | ||
| 638 | "Return non-nil if TAG is a valid version number." | ||
| 639 | (and (string-match "^[0-9]" tag) | ||
| 640 | (not (string-match "[^0-9]" tag)))) | ||
| 641 | |||
| 642 | (provide 'vc-svn) | ||
| 643 | |||
| 644 | ;;; vc-svn.el ends here | ||