| 1 | ;;; vc-cvs.el --- non-resident support for CVS version-control -*- lexical-binding: t -*- |
| 2 | |
| 3 | ;; Copyright (C) 1995, 1998-2012 Free Software Foundation, Inc. |
| 4 | |
| 5 | ;; Author: FSF (see vc.el for full credits) |
| 6 | ;; Maintainer: Andre Spiegel <spiegel@gnu.org> |
| 7 | ;; Package: vc |
| 8 | |
| 9 | ;; This file is part of GNU Emacs. |
| 10 | |
| 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
| 12 | ;; it under the terms of the GNU General Public License as published by |
| 13 | ;; the Free Software Foundation, either version 3 of the License, or |
| 14 | ;; (at your option) any later version. |
| 15 | |
| 16 | ;; GNU Emacs is distributed in the hope that it will be useful, |
| 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | ;; GNU General Public License for more details. |
| 20 | |
| 21 | ;; You should have received a copy of the GNU General Public License |
| 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
| 23 | |
| 24 | ;;; Commentary: |
| 25 | |
| 26 | ;;; Code: |
| 27 | |
| 28 | (eval-when-compile (require 'vc)) |
| 29 | |
| 30 | ;; Clear up the cache to force vc-call to check again and discover |
| 31 | ;; new functions when we reload this file. |
| 32 | (put 'CVS 'vc-functions nil) |
| 33 | |
| 34 | ;;; Properties of the backend. |
| 35 | |
| 36 | (defun vc-cvs-revision-granularity () 'file) |
| 37 | |
| 38 | (defun vc-cvs-checkout-model (files) |
| 39 | "CVS-specific version of `vc-checkout-model'." |
| 40 | (if (getenv "CVSREAD") |
| 41 | 'announce |
| 42 | (let* ((file (if (consp files) (car files) files)) |
| 43 | (attrib (file-attributes file))) |
| 44 | (or (vc-file-getprop file 'vc-checkout-model) |
| 45 | (vc-file-setprop |
| 46 | file 'vc-checkout-model |
| 47 | (if (and attrib ;; don't check further if FILE doesn't exist |
| 48 | ;; If the file is not writable (despite CVSREAD being |
| 49 | ;; undefined), this is probably because the file is being |
| 50 | ;; "watched" by other developers. |
| 51 | ;; (If vc-mistrust-permissions was t, we actually shouldn't |
| 52 | ;; trust this, but there is no other way to learn this from |
| 53 | ;; CVS at the moment (version 1.9).) |
| 54 | (string-match "r-..-..-." (nth 8 attrib))) |
| 55 | 'announce |
| 56 | 'implicit)))))) |
| 57 | |
| 58 | ;;; |
| 59 | ;;; Customization options |
| 60 | ;;; |
| 61 | |
| 62 | (defgroup vc-cvs nil |
| 63 | "VC CVS backend." |
| 64 | :version "24.1" |
| 65 | :group 'vc) |
| 66 | |
| 67 | (defcustom vc-cvs-global-switches nil |
| 68 | "Global switches to pass to any CVS command." |
| 69 | :type '(choice (const :tag "None" nil) |
| 70 | (string :tag "Argument String") |
| 71 | (repeat :tag "Argument List" |
| 72 | :value ("") |
| 73 | string)) |
| 74 | :version "22.1" |
| 75 | :group 'vc-cvs) |
| 76 | |
| 77 | (defcustom vc-cvs-register-switches nil |
| 78 | "Switches for registering a file into CVS. |
| 79 | A string or list of strings passed to the checkin program by |
| 80 | \\[vc-register]. If nil, use the value of `vc-register-switches'. |
| 81 | If t, use no switches." |
| 82 | :type '(choice (const :tag "Unspecified" nil) |
| 83 | (const :tag "None" t) |
| 84 | (string :tag "Argument String") |
| 85 | (repeat :tag "Argument List" :value ("") string)) |
| 86 | :version "21.1" |
| 87 | :group 'vc-cvs) |
| 88 | |
| 89 | (defcustom vc-cvs-diff-switches nil |
| 90 | "String or list of strings specifying switches for CVS diff under VC. |
| 91 | If nil, use the value of `vc-diff-switches'. If t, use no switches." |
| 92 | :type '(choice (const :tag "Unspecified" nil) |
| 93 | (const :tag "None" t) |
| 94 | (string :tag "Argument String") |
| 95 | (repeat :tag "Argument List" :value ("") string)) |
| 96 | :version "21.1" |
| 97 | :group 'vc-cvs) |
| 98 | |
| 99 | (defcustom vc-cvs-header '("\$Id\$") |
| 100 | "Header keywords to be inserted by `vc-insert-headers'." |
| 101 | :version "24.1" ; no longer consult the obsolete vc-header-alist |
| 102 | :type '(repeat string) |
| 103 | :group 'vc-cvs) |
| 104 | |
| 105 | (defcustom vc-cvs-use-edit t |
| 106 | "Non-nil means to use `cvs edit' to \"check out\" a file. |
| 107 | This is only meaningful if you don't use the implicit checkout model |
| 108 | \(i.e. if you have $CVSREAD set)." |
| 109 | :type 'boolean |
| 110 | :version "21.1" |
| 111 | :group 'vc-cvs) |
| 112 | |
| 113 | (defcustom vc-cvs-stay-local 'only-file |
| 114 | "Non-nil means use local operations when possible for remote repositories. |
| 115 | This avoids slow queries over the network and instead uses heuristics |
| 116 | and past information to determine the current status of a file. |
| 117 | |
| 118 | If value is the symbol `only-file' `vc-dir' will connect to the |
| 119 | server, but heuristics will be used to determine the status for |
| 120 | all other VC operations. |
| 121 | |
| 122 | The value can also be a regular expression or list of regular |
| 123 | expressions to match against the host name of a repository; then VC |
| 124 | only stays local for hosts that match it. Alternatively, the value |
| 125 | can be a list of regular expressions where the first element is the |
| 126 | symbol `except'; then VC always stays local except for hosts matched |
| 127 | by these regular expressions." |
| 128 | :type '(choice (const :tag "Always stay local" t) |
| 129 | (const :tag "Only for file operations" only-file) |
| 130 | (const :tag "Don't stay local" nil) |
| 131 | (list :format "\nExamine hostname and %v" |
| 132 | :tag "Examine hostname ..." |
| 133 | (set :format "%v" :inline t |
| 134 | (const :format "%t" :tag "don't" except)) |
| 135 | (regexp :format " stay local,\n%t: %v" |
| 136 | :tag "if it matches") |
| 137 | (repeat :format "%v%i\n" :inline t (regexp :tag "or")))) |
| 138 | :version "23.1" |
| 139 | :group 'vc-cvs) |
| 140 | |
| 141 | (defcustom vc-cvs-sticky-date-format-string "%c" |
| 142 | "Format string for mode-line display of sticky date. |
| 143 | Format is according to `format-time-string'. Only used if |
| 144 | `vc-cvs-sticky-tag-display' is t." |
| 145 | :type '(string) |
| 146 | :version "22.1" |
| 147 | :group 'vc-cvs) |
| 148 | |
| 149 | (defcustom vc-cvs-sticky-tag-display t |
| 150 | "Specify the mode-line display of sticky tags. |
| 151 | Value t means default display, nil means no display at all. If the |
| 152 | value is a function or macro, it is called with the sticky tag and |
| 153 | its' type as parameters, in that order. TYPE can have three different |
| 154 | values: `symbolic-name' (TAG is a string), `revision-number' (TAG is a |
| 155 | string) and `date' (TAG is a date as returned by `encode-time'). The |
| 156 | return value of the function or macro will be displayed as a string. |
| 157 | |
| 158 | Here's an example that will display the formatted date for sticky |
| 159 | dates and the word \"Sticky\" for sticky tag names and revisions. |
| 160 | |
| 161 | (lambda (tag type) |
| 162 | (cond ((eq type 'date) (format-time-string |
| 163 | vc-cvs-sticky-date-format-string tag)) |
| 164 | ((eq type 'revision-number) \"Sticky\") |
| 165 | ((eq type 'symbolic-name) \"Sticky\"))) |
| 166 | |
| 167 | Here's an example that will abbreviate to the first character only, |
| 168 | any text before the first occurrence of `-' for sticky symbolic tags. |
| 169 | If the sticky tag is a revision number, the word \"Sticky\" is |
| 170 | displayed. Date and time is displayed for sticky dates. |
| 171 | |
| 172 | (lambda (tag type) |
| 173 | (cond ((eq type 'date) (format-time-string \"%Y%m%d %H:%M\" tag)) |
| 174 | ((eq type 'revision-number) \"Sticky\") |
| 175 | ((eq type 'symbolic-name) |
| 176 | (condition-case nil |
| 177 | (progn |
| 178 | (string-match \"\\\\([^-]*\\\\)\\\\(.*\\\\)\" tag) |
| 179 | (concat (substring (match-string 1 tag) 0 1) \":\" |
| 180 | (substring (match-string 2 tag) 1 nil))) |
| 181 | (error tag))))) ; Fall-back to given tag name. |
| 182 | |
| 183 | See also variable `vc-cvs-sticky-date-format-string'." |
| 184 | :type '(choice boolean function) |
| 185 | :version "22.1" |
| 186 | :group 'vc-cvs) |
| 187 | |
| 188 | ;;; |
| 189 | ;;; Internal variables |
| 190 | ;;; |
| 191 | |
| 192 | |
| 193 | ;;; |
| 194 | ;;; State-querying functions |
| 195 | ;;; |
| 196 | |
| 197 | ;;;###autoload(defun vc-cvs-registered (f) |
| 198 | ;;;###autoload "Return non-nil if file F is registered with CVS." |
| 199 | ;;;###autoload (when (file-readable-p (expand-file-name |
| 200 | ;;;###autoload "CVS/Entries" (file-name-directory f))) |
| 201 | ;;;###autoload (load "vc-cvs") |
| 202 | ;;;###autoload (vc-cvs-registered f))) |
| 203 | |
| 204 | (defun vc-cvs-registered (file) |
| 205 | "Check if FILE is CVS registered." |
| 206 | (let ((dirname (or (file-name-directory file) "")) |
| 207 | (basename (file-name-nondirectory file)) |
| 208 | ;; make sure that the file name is searched case-sensitively |
| 209 | (case-fold-search nil)) |
| 210 | (if (file-readable-p (expand-file-name "CVS/Entries" dirname)) |
| 211 | (or (string= basename "") |
| 212 | (with-temp-buffer |
| 213 | (vc-cvs-get-entries dirname) |
| 214 | (goto-char (point-min)) |
| 215 | (cond ((re-search-forward |
| 216 | (concat "^/" (regexp-quote basename) "/[^/]") nil t) |
| 217 | (beginning-of-line) |
| 218 | (vc-cvs-parse-entry file) |
| 219 | t) |
| 220 | (t nil)))) |
| 221 | nil))) |
| 222 | |
| 223 | (defun vc-cvs-state (file) |
| 224 | "CVS-specific version of `vc-state'." |
| 225 | (if (vc-stay-local-p file 'CVS) |
| 226 | (let ((state (vc-file-getprop file 'vc-state))) |
| 227 | ;; If we should stay local, use the heuristic but only if |
| 228 | ;; we don't have a more precise state already available. |
| 229 | (if (memq state '(up-to-date edited nil)) |
| 230 | (vc-cvs-state-heuristic file) |
| 231 | state)) |
| 232 | (with-temp-buffer |
| 233 | (cd (file-name-directory file)) |
| 234 | (let (process-file-side-effects) |
| 235 | (vc-cvs-command t 0 file "status")) |
| 236 | (vc-cvs-parse-status t)))) |
| 237 | |
| 238 | (defun vc-cvs-state-heuristic (file) |
| 239 | "CVS-specific state heuristic." |
| 240 | ;; If the file has not changed since checkout, consider it `up-to-date'. |
| 241 | ;; Otherwise consider it `edited'. |
| 242 | (let ((checkout-time (vc-file-getprop file 'vc-checkout-time)) |
| 243 | (lastmod (nth 5 (file-attributes file)))) |
| 244 | (cond |
| 245 | ((equal checkout-time lastmod) 'up-to-date) |
| 246 | ((string= (vc-working-revision file) "0") 'added) |
| 247 | ((null checkout-time) 'unregistered) |
| 248 | (t 'edited)))) |
| 249 | |
| 250 | (defun vc-cvs-working-revision (file) |
| 251 | "CVS-specific version of `vc-working-revision'." |
| 252 | ;; There is no need to consult RCS headers under CVS, because we |
| 253 | ;; get the workfile version for free when we recognize that a file |
| 254 | ;; is registered in CVS. |
| 255 | (vc-cvs-registered file) |
| 256 | (vc-file-getprop file 'vc-working-revision)) |
| 257 | |
| 258 | (defun vc-cvs-mode-line-string (file) |
| 259 | "Return a string for `vc-mode-line' to put in the mode line for FILE. |
| 260 | Compared to the default implementation, this function does two things: |
| 261 | Handle the special case of a CVS file that is added but not yet |
| 262 | committed and support display of sticky tags." |
| 263 | (let* ((sticky-tag (vc-file-getprop file 'vc-cvs-sticky-tag)) |
| 264 | help-echo |
| 265 | (string |
| 266 | (let ((def-ml (vc-default-mode-line-string 'CVS file))) |
| 267 | (setq help-echo |
| 268 | (get-text-property 0 'help-echo def-ml)) |
| 269 | def-ml))) |
| 270 | (propertize |
| 271 | (if (zerop (length sticky-tag)) |
| 272 | string |
| 273 | (setq help-echo (format "%s on the '%s' branch" |
| 274 | help-echo sticky-tag)) |
| 275 | (concat string "[" sticky-tag "]")) |
| 276 | 'help-echo help-echo))) |
| 277 | |
| 278 | |
| 279 | ;;; |
| 280 | ;;; State-changing functions |
| 281 | ;;; |
| 282 | |
| 283 | (defun vc-cvs-register (files &optional _rev comment) |
| 284 | "Register FILES into the CVS version-control system. |
| 285 | COMMENT can be used to provide an initial description of FILES. |
| 286 | Passes either `vc-cvs-register-switches' or `vc-register-switches' |
| 287 | to the CVS command." |
| 288 | ;; Register the directories if needed. |
| 289 | (let (dirs) |
| 290 | (dolist (file files) |
| 291 | (and (not (vc-cvs-responsible-p file)) |
| 292 | (vc-cvs-could-register file) |
| 293 | (push (directory-file-name (file-name-directory file)) dirs))) |
| 294 | (if dirs (vc-cvs-register dirs))) |
| 295 | (apply 'vc-cvs-command nil 0 files |
| 296 | "add" |
| 297 | (and comment (string-match "[^\t\n ]" comment) |
| 298 | (concat "-m" comment)) |
| 299 | (vc-switches 'CVS 'register))) |
| 300 | |
| 301 | (defun vc-cvs-responsible-p (file) |
| 302 | "Return non-nil if CVS thinks it is responsible for FILE." |
| 303 | (file-directory-p (expand-file-name "CVS" |
| 304 | (if (file-directory-p file) |
| 305 | file |
| 306 | (file-name-directory file))))) |
| 307 | |
| 308 | (defun vc-cvs-could-register (file) |
| 309 | "Return non-nil if FILE could be registered in CVS. |
| 310 | This is only possible if CVS is managing FILE's directory or one of |
| 311 | its parents." |
| 312 | (let ((dir file)) |
| 313 | (while (and (stringp dir) |
| 314 | (not (equal dir (setq dir (file-name-directory dir)))) |
| 315 | dir) |
| 316 | (setq dir (if (file-exists-p |
| 317 | (expand-file-name "CVS/Entries" dir)) |
| 318 | t |
| 319 | (directory-file-name dir)))) |
| 320 | (eq dir t))) |
| 321 | |
| 322 | (defun vc-cvs-checkin (files rev comment) |
| 323 | "CVS-specific version of `vc-backend-checkin'." |
| 324 | (unless (or (not rev) (vc-cvs-valid-revision-number-p rev)) |
| 325 | (if (not (vc-cvs-valid-symbolic-tag-name-p rev)) |
| 326 | (error "%s is not a valid symbolic tag name" rev) |
| 327 | ;; If the input revision is a valid symbolic tag name, we create it |
| 328 | ;; as a branch, commit and switch to it. |
| 329 | (apply 'vc-cvs-command nil 0 files "tag" "-b" (list rev)) |
| 330 | (apply 'vc-cvs-command nil 0 files "update" "-r" (list rev)) |
| 331 | (mapc (lambda (file) (vc-file-setprop file 'vc-cvs-sticky-tag rev)) |
| 332 | files))) |
| 333 | (let ((status (apply 'vc-cvs-command nil 1 files |
| 334 | "ci" (if rev (concat "-r" rev)) |
| 335 | (concat "-m" comment) |
| 336 | (vc-switches 'CVS 'checkin)))) |
| 337 | (set-buffer "*vc*") |
| 338 | (goto-char (point-min)) |
| 339 | (when (not (zerop status)) |
| 340 | ;; Check checkin problem. |
| 341 | (cond |
| 342 | ((re-search-forward "Up-to-date check failed" nil t) |
| 343 | (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge)) |
| 344 | files) |
| 345 | (error "%s" (substitute-command-keys |
| 346 | (concat "Up-to-date check failed: " |
| 347 | "type \\[vc-next-action] to merge in changes")))) |
| 348 | (t |
| 349 | (pop-to-buffer (current-buffer)) |
| 350 | (goto-char (point-min)) |
| 351 | (shrink-window-if-larger-than-buffer) |
| 352 | (error "Check-in failed")))) |
| 353 | ;; Single-file commit? Then update the revision by parsing the buffer. |
| 354 | ;; Otherwise we can't necessarily tell what goes with what; clear |
| 355 | ;; its properties so they have to be refetched. |
| 356 | (if (= (length files) 1) |
| 357 | (vc-file-setprop |
| 358 | (car files) 'vc-working-revision |
| 359 | (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2)) |
| 360 | (mapc 'vc-file-clearprops files)) |
| 361 | ;; Anyway, forget the checkout model of the file, because we might have |
| 362 | ;; guessed wrong when we found the file. After commit, we can |
| 363 | ;; tell it from the permissions of the file (see |
| 364 | ;; vc-cvs-checkout-model). |
| 365 | (mapc (lambda (file) (vc-file-setprop file 'vc-checkout-model nil)) |
| 366 | files) |
| 367 | |
| 368 | ;; if this was an explicit check-in (does not include creation of |
| 369 | ;; a branch), remove the sticky tag. |
| 370 | (if (and rev (not (vc-cvs-valid-symbolic-tag-name-p rev))) |
| 371 | (vc-cvs-command nil 0 files "update" "-A")))) |
| 372 | |
| 373 | (defun vc-cvs-find-revision (file rev buffer) |
| 374 | (apply 'vc-cvs-command |
| 375 | buffer 0 file |
| 376 | "-Q" ; suppress diagnostic output |
| 377 | "update" |
| 378 | (and rev (not (string= rev "")) |
| 379 | (concat "-r" rev)) |
| 380 | "-p" |
| 381 | (vc-switches 'CVS 'checkout))) |
| 382 | |
| 383 | (defun vc-cvs-checkout (file &optional editable rev) |
| 384 | "Checkout a revision of FILE into the working area. |
| 385 | EDITABLE non-nil means that the file should be writable. |
| 386 | REV is the revision to check out." |
| 387 | (message "Checking out %s..." file) |
| 388 | ;; Change buffers to get local value of vc-checkout-switches. |
| 389 | (with-current-buffer (or (get-file-buffer file) (current-buffer)) |
| 390 | (if (and (file-exists-p file) (not rev)) |
| 391 | ;; If no revision was specified, just make the file writable |
| 392 | ;; if necessary (using `cvs-edit' if requested). |
| 393 | (and editable (not (eq (vc-cvs-checkout-model (list file)) 'implicit)) |
| 394 | (if vc-cvs-use-edit |
| 395 | (vc-cvs-command nil 0 file "edit") |
| 396 | (set-file-modes file (logior (file-modes file) 128)) |
| 397 | (if (equal file buffer-file-name) (toggle-read-only -1)))) |
| 398 | ;; Check out a particular revision (or recreate the file). |
| 399 | (vc-file-setprop file 'vc-working-revision nil) |
| 400 | (apply 'vc-cvs-command nil 0 file |
| 401 | (and editable "-w") |
| 402 | "update" |
| 403 | (when rev |
| 404 | (unless (eq rev t) |
| 405 | ;; default for verbose checkout: clear the |
| 406 | ;; sticky tag so that the actual update will |
| 407 | ;; get the head of the trunk |
| 408 | (if (string= rev "") |
| 409 | "-A" |
| 410 | (concat "-r" rev)))) |
| 411 | (vc-switches 'CVS 'checkout))) |
| 412 | (vc-mode-line file 'CVS)) |
| 413 | (message "Checking out %s...done" file)) |
| 414 | |
| 415 | (defun vc-cvs-delete-file (file) |
| 416 | (vc-cvs-command nil 0 file "remove" "-f")) |
| 417 | |
| 418 | (defun vc-cvs-revert (file &optional contents-done) |
| 419 | "Revert FILE to the working revision on which it was based." |
| 420 | (vc-default-revert 'CVS file contents-done) |
| 421 | (unless (eq (vc-cvs-checkout-model (list file)) 'implicit) |
| 422 | (if vc-cvs-use-edit |
| 423 | (vc-cvs-command nil 0 file "unedit") |
| 424 | ;; Make the file read-only by switching off all w-bits |
| 425 | (set-file-modes file (logand (file-modes file) 3950))))) |
| 426 | |
| 427 | (defun vc-cvs-merge (file first-revision &optional second-revision) |
| 428 | "Merge changes into current working copy of FILE. |
| 429 | The changes are between FIRST-REVISION and SECOND-REVISION." |
| 430 | (vc-cvs-command nil 0 file |
| 431 | "update" "-kk" |
| 432 | (concat "-j" first-revision) |
| 433 | (concat "-j" second-revision)) |
| 434 | (vc-file-setprop file 'vc-state 'edited) |
| 435 | (with-current-buffer (get-buffer "*vc*") |
| 436 | (goto-char (point-min)) |
| 437 | (if (re-search-forward "conflicts during merge" nil t) |
| 438 | (progn |
| 439 | (vc-file-setprop file 'vc-state 'conflict) |
| 440 | ;; signal error |
| 441 | 1) |
| 442 | (vc-file-setprop file 'vc-state 'edited) |
| 443 | ;; signal success |
| 444 | 0))) |
| 445 | |
| 446 | (defun vc-cvs-merge-news (file) |
| 447 | "Merge in any new changes made to FILE." |
| 448 | (message "Merging changes into %s..." file) |
| 449 | ;; (vc-file-setprop file 'vc-working-revision nil) |
| 450 | (vc-file-setprop file 'vc-checkout-time 0) |
| 451 | (vc-cvs-command nil nil file "update") |
| 452 | ;; Analyze the merge result reported by CVS, and set |
| 453 | ;; file properties accordingly. |
| 454 | (with-current-buffer (get-buffer "*vc*") |
| 455 | (goto-char (point-min)) |
| 456 | ;; get new working revision |
| 457 | (if (re-search-forward |
| 458 | "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t) |
| 459 | (vc-file-setprop file 'vc-working-revision (match-string 1)) |
| 460 | (vc-file-setprop file 'vc-working-revision nil)) |
| 461 | ;; get file status |
| 462 | (prog1 |
| 463 | (if (eq (buffer-size) 0) |
| 464 | 0 ;; there were no news; indicate success |
| 465 | (if (re-search-forward |
| 466 | (concat "^\\([CMUP] \\)?" |
| 467 | (regexp-quote |
| 468 | (substring file (1+ (length (expand-file-name |
| 469 | "." default-directory))))) |
| 470 | "\\( already contains the differences between \\)?") |
| 471 | nil t) |
| 472 | (cond |
| 473 | ;; Merge successful, we are in sync with repository now |
| 474 | ((or (match-string 2) |
| 475 | (string= (match-string 1) "U ") |
| 476 | (string= (match-string 1) "P ")) |
| 477 | (vc-file-setprop file 'vc-state 'up-to-date) |
| 478 | (vc-file-setprop file 'vc-checkout-time |
| 479 | (nth 5 (file-attributes file))) |
| 480 | 0);; indicate success to the caller |
| 481 | ;; Merge successful, but our own changes are still in the file |
| 482 | ((string= (match-string 1) "M ") |
| 483 | (vc-file-setprop file 'vc-state 'edited) |
| 484 | 0);; indicate success to the caller |
| 485 | ;; Conflicts detected! |
| 486 | (t |
| 487 | (vc-file-setprop file 'vc-state 'conflict) |
| 488 | 1);; signal the error to the caller |
| 489 | ) |
| 490 | (pop-to-buffer "*vc*") |
| 491 | (error "Couldn't analyze cvs update result"))) |
| 492 | (message "Merging changes into %s...done" file)))) |
| 493 | |
| 494 | (defun vc-cvs-modify-change-comment (files rev comment) |
| 495 | "Modify the change comments for FILES on a specified REV. |
| 496 | Will fail unless you have administrative privileges on the repo." |
| 497 | (vc-cvs-command nil 0 files "admin" (concat "-m" rev ":" comment))) |
| 498 | |
| 499 | ;;; |
| 500 | ;;; History functions |
| 501 | ;;; |
| 502 | |
| 503 | (declare-function vc-rcs-print-log-cleanup "vc-rcs" ()) |
| 504 | |
| 505 | (defun vc-cvs-print-log (files buffer &optional _shortlog _start-revision limit) |
| 506 | "Get change logs associated with FILES." |
| 507 | (require 'vc-rcs) |
| 508 | ;; It's just the catenation of the individual logs. |
| 509 | (vc-cvs-command |
| 510 | buffer |
| 511 | (if (vc-stay-local-p files 'CVS) 'async 0) |
| 512 | files "log") |
| 513 | (with-current-buffer buffer |
| 514 | (vc-exec-after (vc-rcs-print-log-cleanup))) |
| 515 | (when limit 'limit-unsupported)) |
| 516 | |
| 517 | (defun vc-cvs-comment-history (file) |
| 518 | "Get comment history of a file." |
| 519 | (vc-call-backend 'RCS 'comment-history file)) |
| 520 | |
| 521 | (defun vc-cvs-diff (files &optional oldvers newvers buffer) |
| 522 | "Get a difference report using CVS between two revisions of FILE." |
| 523 | (let* (process-file-side-effects |
| 524 | (async (and (not vc-disable-async-diff) |
| 525 | (vc-stay-local-p files 'CVS))) |
| 526 | (invoke-cvs-diff-list nil) |
| 527 | status) |
| 528 | ;; Look through the file list and see if any files have backups |
| 529 | ;; that can be used to do a plain "diff" instead of "cvs diff". |
| 530 | (dolist (file files) |
| 531 | (let ((ov oldvers) |
| 532 | (nv newvers)) |
| 533 | (when (or (not ov) (string-equal ov "")) |
| 534 | (setq ov (vc-working-revision file))) |
| 535 | (when (string-equal nv "") |
| 536 | (setq nv nil)) |
| 537 | (let ((file-oldvers (vc-version-backup-file file ov)) |
| 538 | (file-newvers (if (not nv) |
| 539 | file |
| 540 | (vc-version-backup-file file nv))) |
| 541 | (coding-system-for-read (vc-coding-system-for-diff file))) |
| 542 | (if (and file-oldvers file-newvers) |
| 543 | (progn |
| 544 | ;; This used to append diff-switches and vc-diff-switches, |
| 545 | ;; which was consistent with the vc-diff-switches doc at that |
| 546 | ;; time, but not with the actual behavior of any other VC diff. |
| 547 | (apply 'vc-do-command (or buffer "*vc-diff*") 1 "diff" nil |
| 548 | ;; Not a CVS diff, does not use vc-cvs-diff-switches. |
| 549 | (append (vc-switches nil 'diff) |
| 550 | (list (file-relative-name file-oldvers) |
| 551 | (file-relative-name file-newvers)))) |
| 552 | (setq status 0)) |
| 553 | (push file invoke-cvs-diff-list))))) |
| 554 | (when invoke-cvs-diff-list |
| 555 | (setq status (apply 'vc-cvs-command (or buffer "*vc-diff*") |
| 556 | (if async 'async 1) |
| 557 | invoke-cvs-diff-list "diff" |
| 558 | (and oldvers (concat "-r" oldvers)) |
| 559 | (and newvers (concat "-r" newvers)) |
| 560 | (vc-switches 'CVS 'diff)))) |
| 561 | (if async 1 status))) ; async diff, pessimistic assumption |
| 562 | |
| 563 | (defconst vc-cvs-annotate-first-line-re "^[0-9]") |
| 564 | |
| 565 | (defun vc-cvs-annotate-process-filter (process string) |
| 566 | (setq string (concat (process-get process 'output) string)) |
| 567 | (if (not (string-match vc-cvs-annotate-first-line-re string)) |
| 568 | ;; Still waiting for the first real line. |
| 569 | (process-put process 'output string) |
| 570 | (let ((vc-filter (process-get process 'vc-filter))) |
| 571 | (set-process-filter process vc-filter) |
| 572 | (funcall vc-filter process (substring string (match-beginning 0)))))) |
| 573 | |
| 574 | (defun vc-cvs-annotate-command (file buffer &optional revision) |
| 575 | "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER. |
| 576 | Optional arg REVISION is a revision to annotate from." |
| 577 | (vc-cvs-command buffer |
| 578 | (if (vc-stay-local-p file 'CVS) |
| 579 | 'async 0) |
| 580 | file "annotate" |
| 581 | (if revision (concat "-r" revision))) |
| 582 | ;; Strip the leading few lines. |
| 583 | (let ((proc (get-buffer-process buffer))) |
| 584 | (if proc |
| 585 | ;; If running asynchronously, use a process filter. |
| 586 | (progn |
| 587 | (process-put proc 'vc-filter (process-filter proc)) |
| 588 | (set-process-filter proc 'vc-cvs-annotate-process-filter)) |
| 589 | (with-current-buffer buffer |
| 590 | (goto-char (point-min)) |
| 591 | (re-search-forward vc-cvs-annotate-first-line-re) |
| 592 | (delete-region (point-min) (1- (point))))))) |
| 593 | |
| 594 | (declare-function vc-annotate-convert-time "vc-annotate" (time)) |
| 595 | |
| 596 | (defun vc-cvs-annotate-current-time () |
| 597 | "Return the current time, based at midnight of the current day, and |
| 598 | encoded as fractional days." |
| 599 | (vc-annotate-convert-time |
| 600 | (apply 'encode-time 0 0 0 (nthcdr 3 (decode-time (current-time)))))) |
| 601 | |
| 602 | (defun vc-cvs-annotate-time () |
| 603 | "Return the time of the next annotation (as fraction of days) |
| 604 | systime, or nil if there is none." |
| 605 | (let* ((bol (point)) |
| 606 | (cache (get-text-property bol 'vc-cvs-annotate-time)) |
| 607 | (inhibit-read-only t) |
| 608 | (inhibit-modification-hooks t)) |
| 609 | (cond |
| 610 | (cache) |
| 611 | ((looking-at |
| 612 | "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ") |
| 613 | (let ((day (string-to-number (match-string 1))) |
| 614 | (month (cdr (assq (intern (match-string 2)) |
| 615 | '((Jan . 1) (Feb . 2) (Mar . 3) |
| 616 | (Apr . 4) (May . 5) (Jun . 6) |
| 617 | (Jul . 7) (Aug . 8) (Sep . 9) |
| 618 | (Oct . 10) (Nov . 11) (Dec . 12))))) |
| 619 | (year (let ((tmp (string-to-number (match-string 3)))) |
| 620 | ;; Years 0..68 are 2000..2068. |
| 621 | ;; Years 69..99 are 1969..1999. |
| 622 | (+ (cond ((> 69 tmp) 2000) |
| 623 | ((> 100 tmp) 1900) |
| 624 | (t 0)) |
| 625 | tmp)))) |
| 626 | (put-text-property |
| 627 | bol (1+ bol) 'vc-cvs-annotate-time |
| 628 | (setq cache (cons |
| 629 | ;; Position at end makes for nicer overlay result. |
| 630 | ;; Don't put actual buffer pos here, but only relative |
| 631 | ;; distance, so we don't ever move backward in the |
| 632 | ;; goto-char below, even if the text is moved. |
| 633 | (- (match-end 0) (match-beginning 0)) |
| 634 | (vc-annotate-convert-time |
| 635 | (encode-time 0 0 0 day month year)))))))) |
| 636 | (when cache |
| 637 | (goto-char (+ bol (car cache))) ; Fontify from here to eol. |
| 638 | (cdr cache)))) ; days (float) |
| 639 | |
| 640 | (defun vc-cvs-annotate-extract-revision-at-line () |
| 641 | (save-excursion |
| 642 | (beginning-of-line) |
| 643 | (if (re-search-forward "^\\([0-9]+\\.[0-9]+\\(\\.[0-9]+\\)*\\) +(" |
| 644 | (line-end-position) t) |
| 645 | (match-string-no-properties 1) |
| 646 | nil))) |
| 647 | |
| 648 | (defun vc-cvs-previous-revision (file rev) |
| 649 | (vc-call-backend 'RCS 'previous-revision file rev)) |
| 650 | |
| 651 | (defun vc-cvs-next-revision (file rev) |
| 652 | (vc-call-backend 'RCS 'next-revision file rev)) |
| 653 | |
| 654 | ;; FIXME: This should probably be replaced by code using cvs2cl. |
| 655 | (defun vc-cvs-update-changelog (files) |
| 656 | (vc-call-backend 'RCS 'update-changelog files)) |
| 657 | |
| 658 | ;;; |
| 659 | ;;; Tag system |
| 660 | ;;; |
| 661 | |
| 662 | (defun vc-cvs-create-tag (dir name branchp) |
| 663 | "Assign to DIR's current revision a given NAME. |
| 664 | If BRANCHP is non-nil, the name is created as a branch (and the current |
| 665 | workspace is immediately moved to that new branch)." |
| 666 | (vc-cvs-command nil 0 dir "tag" "-c" (if branchp "-b") name) |
| 667 | (when branchp (vc-cvs-command nil 0 dir "update" "-r" name))) |
| 668 | |
| 669 | (defun vc-cvs-retrieve-tag (dir name update) |
| 670 | "Retrieve a tag at and below DIR. |
| 671 | NAME is the name of the tag; if it is empty, do a `cvs update'. |
| 672 | If UPDATE is non-nil, then update (resynch) any affected buffers." |
| 673 | (with-current-buffer (get-buffer-create "*vc*") |
| 674 | (let ((default-directory dir) |
| 675 | (sticky-tag)) |
| 676 | (erase-buffer) |
| 677 | (if (or (not name) (string= name "")) |
| 678 | (vc-cvs-command t 0 nil "update") |
| 679 | (vc-cvs-command t 0 nil "update" "-r" name) |
| 680 | (setq sticky-tag name)) |
| 681 | (when update |
| 682 | (goto-char (point-min)) |
| 683 | (while (not (eobp)) |
| 684 | (if (looking-at "\\([CMUP]\\) \\(.*\\)") |
| 685 | (let* ((file (expand-file-name (match-string 2) dir)) |
| 686 | (state (match-string 1)) |
| 687 | (buffer (find-buffer-visiting file))) |
| 688 | (when buffer |
| 689 | (cond |
| 690 | ((or (string= state "U") |
| 691 | (string= state "P")) |
| 692 | (vc-file-setprop file 'vc-state 'up-to-date) |
| 693 | (vc-file-setprop file 'vc-working-revision nil) |
| 694 | (vc-file-setprop file 'vc-checkout-time |
| 695 | (nth 5 (file-attributes file)))) |
| 696 | ((or (string= state "M") |
| 697 | (string= state "C")) |
| 698 | (vc-file-setprop file 'vc-state 'edited) |
| 699 | (vc-file-setprop file 'vc-working-revision nil) |
| 700 | (vc-file-setprop file 'vc-checkout-time 0))) |
| 701 | (vc-file-setprop file 'vc-cvs-sticky-tag sticky-tag) |
| 702 | (vc-resynch-buffer file t t)))) |
| 703 | (forward-line 1)))))) |
| 704 | |
| 705 | |
| 706 | ;;; |
| 707 | ;;; Miscellaneous |
| 708 | ;;; |
| 709 | |
| 710 | (defun vc-cvs-make-version-backups-p (file) |
| 711 | "Return non-nil if version backups should be made for FILE." |
| 712 | (vc-stay-local-p file 'CVS)) |
| 713 | |
| 714 | (defun vc-cvs-check-headers () |
| 715 | "Check if the current file has any headers in it." |
| 716 | (save-excursion |
| 717 | (goto-char (point-min)) |
| 718 | (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\ |
| 719 | \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t))) |
| 720 | |
| 721 | |
| 722 | ;;; |
| 723 | ;;; Internal functions |
| 724 | ;;; |
| 725 | |
| 726 | (defun vc-cvs-command (buffer okstatus files &rest flags) |
| 727 | "A wrapper around `vc-do-command' for use in vc-cvs.el. |
| 728 | The difference to vc-do-command is that this function always invokes `cvs', |
| 729 | and that it passes `vc-cvs-global-switches' to it before FLAGS." |
| 730 | (apply 'vc-do-command (or buffer "*vc*") okstatus "cvs" files |
| 731 | (if (stringp vc-cvs-global-switches) |
| 732 | (cons vc-cvs-global-switches flags) |
| 733 | (append vc-cvs-global-switches |
| 734 | flags)))) |
| 735 | |
| 736 | (defun vc-cvs-stay-local-p (file) ;Back-compatibility. |
| 737 | (vc-stay-local-p file 'CVS)) |
| 738 | |
| 739 | (defun vc-cvs-repository-hostname (dirname) |
| 740 | "Hostname of the CVS server associated to workarea DIRNAME." |
| 741 | (let ((rootname (expand-file-name "CVS/Root" dirname))) |
| 742 | (when (file-readable-p rootname) |
| 743 | (with-temp-buffer |
| 744 | (let ((coding-system-for-read |
| 745 | (or file-name-coding-system |
| 746 | default-file-name-coding-system))) |
| 747 | (vc-insert-file rootname)) |
| 748 | (goto-char (point-min)) |
| 749 | (nth 2 (vc-cvs-parse-root |
| 750 | (buffer-substring (point) |
| 751 | (line-end-position)))))))) |
| 752 | |
| 753 | (defun vc-cvs-parse-uhp (path) |
| 754 | "parse user@host/path into (user@host /path)" |
| 755 | (if (string-match "\\([^/]+\\)\\(/.*\\)" path) |
| 756 | (list (match-string 1 path) (match-string 2 path)) |
| 757 | (list nil path))) |
| 758 | |
| 759 | (defun vc-cvs-parse-root (root) |
| 760 | "Split CVS ROOT specification string into a list of fields. |
| 761 | A CVS root specification of the form |
| 762 | [:METHOD:][[USER@]HOSTNAME]:?/path/to/repository |
| 763 | is converted to a normalized record with the following structure: |
| 764 | \(METHOD USER HOSTNAME CVS-ROOT). |
| 765 | The default METHOD for a CVS root of the form |
| 766 | /path/to/repository |
| 767 | is `local'. |
| 768 | The default METHOD for a CVS root of the form |
| 769 | [USER@]HOSTNAME:/path/to/repository |
| 770 | is `ext'. |
| 771 | For an empty string, nil is returned (invalid CVS root)." |
| 772 | ;; Split CVS root into colon separated fields (0-4). |
| 773 | ;; The `x:' makes sure, that leading colons are not lost; |
| 774 | ;; `HOST:/PATH' is then different from `:METHOD:/PATH'. |
| 775 | (let* ((root-list (cdr (split-string (concat "x:" root) ":"))) |
| 776 | (len (length root-list)) |
| 777 | ;; All syntactic varieties will get a proper METHOD. |
| 778 | (root-list |
| 779 | (cond |
| 780 | ((= len 0) |
| 781 | ;; Invalid CVS root |
| 782 | nil) |
| 783 | ((= len 1) |
| 784 | (let ((uhp (vc-cvs-parse-uhp (car root-list)))) |
| 785 | (cons (if (car uhp) "ext" "local") uhp))) |
| 786 | ((= len 2) |
| 787 | ;; [USER@]HOST:PATH => method `ext' |
| 788 | (and (not (equal (car root-list) "")) |
| 789 | (cons "ext" root-list))) |
| 790 | ((= len 3) |
| 791 | ;; :METHOD:PATH or :METHOD:USER@HOSTNAME/PATH |
| 792 | (cons (cadr root-list) |
| 793 | (vc-cvs-parse-uhp (nth 2 root-list)))) |
| 794 | (t |
| 795 | ;; :METHOD:[USER@]HOST:PATH |
| 796 | (cdr root-list))))) |
| 797 | (if root-list |
| 798 | (let ((method (car root-list)) |
| 799 | (uhost (or (cadr root-list) "")) |
| 800 | (root (nth 2 root-list)) |
| 801 | user host) |
| 802 | ;; Split USER@HOST |
| 803 | (if (string-match "\\(.*\\)@\\(.*\\)" uhost) |
| 804 | (setq user (match-string 1 uhost) |
| 805 | host (match-string 2 uhost)) |
| 806 | (setq host uhost)) |
| 807 | ;; Remove empty HOST |
| 808 | (and (equal host "") |
| 809 | (setq host)) |
| 810 | ;; Fix windows style CVS root `:local:C:\\project\\cvs\\some\\dir' |
| 811 | (and host |
| 812 | (equal method "local") |
| 813 | (setq root (concat host ":" root) host)) |
| 814 | ;; Normalize CVS root record |
| 815 | (list method user host root))))) |
| 816 | |
| 817 | ;; XXX: This does not work correctly for subdirectories. "cvs status" |
| 818 | ;; information is context sensitive, it contains lines like: |
| 819 | ;; cvs status: Examining DIRNAME |
| 820 | ;; and the file entries after that don't show the full path. |
| 821 | ;; Because of this VC directory listings only show changed files |
| 822 | ;; at the top level for CVS. |
| 823 | (defun vc-cvs-parse-status (&optional full) |
| 824 | "Parse output of \"cvs status\" command in the current buffer. |
| 825 | Set file properties accordingly. Unless FULL is t, parse only |
| 826 | essential information. Note that this can never set the 'ignored |
| 827 | state." |
| 828 | (let (file status missing) |
| 829 | (goto-char (point-min)) |
| 830 | (while (looking-at "? \\(.*\\)") |
| 831 | (setq file (expand-file-name (match-string 1))) |
| 832 | (vc-file-setprop file 'vc-state 'unregistered) |
| 833 | (forward-line 1)) |
| 834 | (when (re-search-forward "^File: " nil t) |
| 835 | (when (setq missing (looking-at "no file ")) |
| 836 | (goto-char (match-end 0))) |
| 837 | (cond |
| 838 | ((re-search-forward "\\=\\([^ \t]+\\)" nil t) |
| 839 | (setq file (expand-file-name (match-string 1))) |
| 840 | (setq status(if (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t) |
| 841 | (match-string 1) "Unknown")) |
| 842 | (when (and full |
| 843 | (re-search-forward |
| 844 | "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\ |
| 845 | \[\t ]+\\([0-9.]+\\)" |
| 846 | nil t)) |
| 847 | (vc-file-setprop file 'vc-latest-revision (match-string 2))) |
| 848 | (vc-file-setprop |
| 849 | file 'vc-state |
| 850 | (cond |
| 851 | ((string-match "Up-to-date" status) |
| 852 | (vc-file-setprop file 'vc-checkout-time |
| 853 | (nth 5 (file-attributes file))) |
| 854 | 'up-to-date) |
| 855 | ((string-match "Locally Modified" status) 'edited) |
| 856 | ((string-match "Needs Merge" status) 'needs-merge) |
| 857 | ((string-match "Needs \\(Checkout\\|Patch\\)" status) |
| 858 | (if missing 'missing 'needs-update)) |
| 859 | ((string-match "Locally Added" status) 'added) |
| 860 | ((string-match "Locally Removed" status) 'removed) |
| 861 | ((string-match "File had conflicts " status) 'conflict) |
| 862 | ((string-match "Unknown" status) 'unregistered) |
| 863 | (t 'edited)))))))) |
| 864 | |
| 865 | (defun vc-cvs-after-dir-status (update-function) |
| 866 | ;; Heavily inspired by vc-cvs-parse-status. AKA a quick hack. |
| 867 | ;; This needs a lot of testing. |
| 868 | (let ((status nil) |
| 869 | (status-str nil) |
| 870 | (file nil) |
| 871 | (result nil) |
| 872 | (missing nil) |
| 873 | (ignore-next nil) |
| 874 | (subdir default-directory)) |
| 875 | (goto-char (point-min)) |
| 876 | (while |
| 877 | ;; Look for either a file entry, an unregistered file, or a |
| 878 | ;; directory change. |
| 879 | (re-search-forward |
| 880 | "\\(^=+\n\\([^=c?\n].*\n\\|\n\\)+\\)\\|\\(\\(^?? .*\n\\)+\\)\\|\\(^cvs status: \\(Examining\\|nothing\\) .*\n\\)" |
| 881 | nil t) |
| 882 | ;; FIXME: get rid of narrowing here. |
| 883 | (narrow-to-region (match-beginning 0) (match-end 0)) |
| 884 | (goto-char (point-min)) |
| 885 | ;; The subdir |
| 886 | (when (looking-at "cvs status: Examining \\(.+\\)") |
| 887 | (setq subdir (expand-file-name (match-string 1)))) |
| 888 | ;; Unregistered files |
| 889 | (while (looking-at "? \\(.*\\)") |
| 890 | (setq file (file-relative-name |
| 891 | (expand-file-name (match-string 1) subdir))) |
| 892 | (push (list file 'unregistered) result) |
| 893 | (forward-line 1)) |
| 894 | (when (looking-at "cvs status: nothing known about") |
| 895 | ;; We asked about a non existent file. The output looks like this: |
| 896 | |
| 897 | ;; cvs status: nothing known about `lisp/v.diff' |
| 898 | ;; =================================================================== |
| 899 | ;; File: no file v.diff Status: Unknown |
| 900 | ;; |
| 901 | ;; Working revision: No entry for v.diff |
| 902 | ;; Repository revision: No revision control file |
| 903 | ;; |
| 904 | |
| 905 | ;; Due to narrowing in this iteration we only see the "cvs |
| 906 | ;; status:" line, so just set a flag so that we can ignore the |
| 907 | ;; file in the next iteration. |
| 908 | (setq ignore-next t)) |
| 909 | ;; A file entry. |
| 910 | (when (re-search-forward "^File: \\(no file \\)?\\(.*[^ \t]\\)[ \t]+Status: \\(.*\\)" nil t) |
| 911 | (setq missing (match-string 1)) |
| 912 | (setq file (file-relative-name |
| 913 | (expand-file-name (match-string 2) subdir))) |
| 914 | (setq status-str (match-string 3)) |
| 915 | (setq status |
| 916 | (cond |
| 917 | ((string-match "Up-to-date" status-str) 'up-to-date) |
| 918 | ((string-match "Locally Modified" status-str) 'edited) |
| 919 | ((string-match "Needs Merge" status-str) 'needs-merge) |
| 920 | ((string-match "Needs \\(Checkout\\|Patch\\)" status-str) |
| 921 | (if missing 'missing 'needs-update)) |
| 922 | ((string-match "Locally Added" status-str) 'added) |
| 923 | ((string-match "Locally Removed" status-str) 'removed) |
| 924 | ((string-match "File had conflicts " status-str) 'conflict) |
| 925 | ((string-match "Unknown" status-str) 'unregistered) |
| 926 | (t 'edited))) |
| 927 | (if ignore-next |
| 928 | (setq ignore-next nil) |
| 929 | (unless (eq status 'up-to-date) |
| 930 | (push (list file status) result)))) |
| 931 | (goto-char (point-max)) |
| 932 | (widen)) |
| 933 | (funcall update-function result)) |
| 934 | ;; Alternative implementation: use the "update" command instead of |
| 935 | ;; the "status" command. |
| 936 | ;; (let ((result nil) |
| 937 | ;; (translation '((?? . unregistered) |
| 938 | ;; (?A . added) |
| 939 | ;; (?C . conflict) |
| 940 | ;; (?M . edited) |
| 941 | ;; (?P . needs-merge) |
| 942 | ;; (?R . removed) |
| 943 | ;; (?U . needs-update)))) |
| 944 | ;; (goto-char (point-min)) |
| 945 | ;; (while (not (eobp)) |
| 946 | ;; (if (looking-at "^[ACMPRU?] \\(.*\\)$") |
| 947 | ;; (push (list (match-string 1) |
| 948 | ;; (cdr (assoc (char-after) translation))) |
| 949 | ;; result) |
| 950 | ;; (cond |
| 951 | ;; ((looking-at "cvs update: warning: \\(.*\\) was lost") |
| 952 | ;; ;; Format is: |
| 953 | ;; ;; cvs update: warning: FILENAME was lost |
| 954 | ;; ;; U FILENAME |
| 955 | ;; (push (list (match-string 1) 'missing) result) |
| 956 | ;; ;; Skip the "U" line |
| 957 | ;; (forward-line 1)) |
| 958 | ;; ((looking-at "cvs update: New directory `\\(.*\\)' -- ignored") |
| 959 | ;; (push (list (match-string 1) 'unregistered) result)))) |
| 960 | ;; (forward-line 1)) |
| 961 | ;; (funcall update-function result))) |
| 962 | ) |
| 963 | |
| 964 | ;; Based on vc-cvs-dir-state-heuristic from Emacs 22. |
| 965 | ;; FIXME does not mention unregistered files. |
| 966 | (defun vc-cvs-dir-status-heuristic (dir update-function &optional basedir) |
| 967 | "Find the CVS state of all files in DIR, using only local information." |
| 968 | (let (file basename status result dirlist) |
| 969 | (with-temp-buffer |
| 970 | (vc-cvs-get-entries dir) |
| 971 | (goto-char (point-min)) |
| 972 | (while (not (eobp)) |
| 973 | (if (looking-at "D/\\([^/]*\\)////") |
| 974 | (push (expand-file-name (match-string 1) dir) dirlist) |
| 975 | ;; CVS-removed files are not taken under VC control. |
| 976 | (when (looking-at "/\\([^/]*\\)/[^/-]") |
| 977 | (setq basename (match-string 1) |
| 978 | file (expand-file-name basename dir) |
| 979 | status (or (vc-file-getprop file 'vc-state) |
| 980 | (vc-cvs-parse-entry file t))) |
| 981 | (unless (eq status 'up-to-date) |
| 982 | (push (list (if basedir |
| 983 | (file-relative-name file basedir) |
| 984 | basename) |
| 985 | status) result)))) |
| 986 | (forward-line 1))) |
| 987 | (dolist (subdir dirlist) |
| 988 | (setq result (append result |
| 989 | (vc-cvs-dir-status-heuristic subdir nil |
| 990 | (or basedir dir))))) |
| 991 | (if basedir result |
| 992 | (funcall update-function result)))) |
| 993 | |
| 994 | (defun vc-cvs-dir-status (dir update-function) |
| 995 | "Create a list of conses (file . state) for DIR." |
| 996 | ;; FIXME check all files in DIR instead? |
| 997 | (let ((local (vc-stay-local-p dir 'CVS))) |
| 998 | (if (and local (not (eq local 'only-file))) |
| 999 | (vc-cvs-dir-status-heuristic dir update-function) |
| 1000 | (vc-cvs-command (current-buffer) 'async dir "-f" "status") |
| 1001 | ;; Alternative implementation: use the "update" command instead of |
| 1002 | ;; the "status" command. |
| 1003 | ;; (vc-cvs-command (current-buffer) 'async |
| 1004 | ;; (file-relative-name dir) |
| 1005 | ;; "-f" "-n" "update" "-d" "-P") |
| 1006 | (vc-exec-after |
| 1007 | `(vc-cvs-after-dir-status (quote ,update-function)))))) |
| 1008 | |
| 1009 | (defun vc-cvs-dir-status-files (dir files _default-state update-function) |
| 1010 | "Create a list of conses (file . state) for DIR." |
| 1011 | (apply 'vc-cvs-command (current-buffer) 'async dir "-f" "status" files) |
| 1012 | (vc-exec-after |
| 1013 | `(vc-cvs-after-dir-status (quote ,update-function)))) |
| 1014 | |
| 1015 | (defun vc-cvs-file-to-string (file) |
| 1016 | "Read the content of FILE and return it as a string." |
| 1017 | (condition-case nil |
| 1018 | (with-temp-buffer |
| 1019 | (insert-file-contents file) |
| 1020 | (goto-char (point-min)) |
| 1021 | (buffer-substring (point) (point-max))) |
| 1022 | (file-error nil))) |
| 1023 | |
| 1024 | (defun vc-cvs-dir-extra-headers (_dir) |
| 1025 | "Extract and represent per-directory properties of a CVS working copy." |
| 1026 | (let ((repo |
| 1027 | (condition-case nil |
| 1028 | (with-temp-buffer |
| 1029 | (insert-file-contents "CVS/Root") |
| 1030 | (goto-char (point-min)) |
| 1031 | (and (looking-at ":ext:") (delete-char 5)) |
| 1032 | (concat (buffer-substring (point) (1- (point-max))) "\n")) |
| 1033 | (file-error nil))) |
| 1034 | (module |
| 1035 | (condition-case nil |
| 1036 | (with-temp-buffer |
| 1037 | (insert-file-contents "CVS/Repository") |
| 1038 | (goto-char (point-min)) |
| 1039 | (skip-chars-forward "^\n") |
| 1040 | (concat (buffer-substring (point-min) (point)) "\n")) |
| 1041 | (file-error nil)))) |
| 1042 | (concat |
| 1043 | (cond (repo |
| 1044 | (concat (propertize "Repository : " 'face 'font-lock-type-face) |
| 1045 | (propertize repo 'face 'font-lock-variable-name-face))) |
| 1046 | (t "")) |
| 1047 | (cond (module |
| 1048 | (concat (propertize "Module : " 'face 'font-lock-type-face) |
| 1049 | (propertize module 'face 'font-lock-variable-name-face))) |
| 1050 | (t "")) |
| 1051 | (if (file-readable-p "CVS/Tag") |
| 1052 | (let ((tag (vc-cvs-file-to-string "CVS/Tag"))) |
| 1053 | (cond |
| 1054 | ((string-match "\\`T" tag) |
| 1055 | (concat (propertize "Tag : " 'face 'font-lock-type-face) |
| 1056 | (propertize (substring tag 1) |
| 1057 | 'face 'font-lock-variable-name-face))) |
| 1058 | ((string-match "\\`D" tag) |
| 1059 | (concat (propertize "Date : " 'face 'font-lock-type-face) |
| 1060 | (propertize (substring tag 1) |
| 1061 | 'face 'font-lock-variable-name-face))) |
| 1062 | (t "")))) |
| 1063 | |
| 1064 | ;; In CVS, branch is a per-file property, not a per-directory property. |
| 1065 | ;; We can't really do this here without making dangerous assumptions. |
| 1066 | ;;(propertize "Branch: " 'face 'font-lock-type-face) |
| 1067 | ;;(propertize "ADD CODE TO PRINT THE BRANCH NAME\n" |
| 1068 | ;; 'face 'font-lock-warning-face) |
| 1069 | ))) |
| 1070 | |
| 1071 | (defun vc-cvs-get-entries (dir) |
| 1072 | "Insert the CVS/Entries file from below DIR into the current buffer. |
| 1073 | This function ensures that the correct coding system is used for that, |
| 1074 | which may not be the one that is used for the files' contents. |
| 1075 | CVS/Entries should only be accessed through this function." |
| 1076 | (let ((coding-system-for-read (or file-name-coding-system |
| 1077 | default-file-name-coding-system))) |
| 1078 | (vc-insert-file (expand-file-name "CVS/Entries" dir)))) |
| 1079 | |
| 1080 | (defun vc-cvs-valid-symbolic-tag-name-p (tag) |
| 1081 | "Return non-nil if TAG is a valid symbolic tag name." |
| 1082 | ;; According to the CVS manual, a valid symbolic tag must start with |
| 1083 | ;; an uppercase or lowercase letter and can contain uppercase and |
| 1084 | ;; lowercase letters, digits, `-', and `_'. |
| 1085 | (and (string-match "^[a-zA-Z]" tag) |
| 1086 | (not (string-match "[^a-z0-9A-Z-_]" tag)))) |
| 1087 | |
| 1088 | (defun vc-cvs-valid-revision-number-p (tag) |
| 1089 | "Return non-nil if TAG is a valid revision number." |
| 1090 | (and (string-match "^[0-9]" tag) |
| 1091 | (not (string-match "[^0-9.]" tag)))) |
| 1092 | |
| 1093 | (defun vc-cvs-parse-sticky-tag (match-type match-tag) |
| 1094 | "Parse and return the sticky tag as a string. |
| 1095 | `match-data' is protected." |
| 1096 | (let ((data (match-data)) |
| 1097 | (tag) |
| 1098 | (type (cond ((string= match-type "D") 'date) |
| 1099 | ((string= match-type "T") |
| 1100 | (if (vc-cvs-valid-symbolic-tag-name-p match-tag) |
| 1101 | 'symbolic-name |
| 1102 | 'revision-number)) |
| 1103 | (t nil)))) |
| 1104 | (unwind-protect |
| 1105 | (progn |
| 1106 | (cond |
| 1107 | ;; Sticky Date tag. Convert to a proper date value (`encode-time') |
| 1108 | ((eq type 'date) |
| 1109 | (string-match |
| 1110 | "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)" |
| 1111 | match-tag) |
| 1112 | (let* ((year-tmp (string-to-number (match-string 1 match-tag))) |
| 1113 | (month (string-to-number (match-string 2 match-tag))) |
| 1114 | (day (string-to-number (match-string 3 match-tag))) |
| 1115 | (hour (string-to-number (match-string 4 match-tag))) |
| 1116 | (min (string-to-number (match-string 5 match-tag))) |
| 1117 | (sec (string-to-number (match-string 6 match-tag))) |
| 1118 | ;; Years 0..68 are 2000..2068. |
| 1119 | ;; Years 69..99 are 1969..1999. |
| 1120 | (year (+ (cond ((> 69 year-tmp) 2000) |
| 1121 | ((> 100 year-tmp) 1900) |
| 1122 | (t 0)) |
| 1123 | year-tmp))) |
| 1124 | (setq tag (encode-time sec min hour day month year)))) |
| 1125 | ;; Sticky Tag name or revision number |
| 1126 | ((eq type 'symbolic-name) (setq tag match-tag)) |
| 1127 | ((eq type 'revision-number) (setq tag match-tag)) |
| 1128 | ;; Default is no sticky tag at all |
| 1129 | (t nil)) |
| 1130 | (cond ((eq vc-cvs-sticky-tag-display nil) nil) |
| 1131 | ((eq vc-cvs-sticky-tag-display t) |
| 1132 | (cond ((eq type 'date) (format-time-string |
| 1133 | vc-cvs-sticky-date-format-string |
| 1134 | tag)) |
| 1135 | ((eq type 'symbolic-name) tag) |
| 1136 | ((eq type 'revision-number) tag) |
| 1137 | (t nil))) |
| 1138 | ((functionp vc-cvs-sticky-tag-display) |
| 1139 | (funcall vc-cvs-sticky-tag-display tag type)) |
| 1140 | (t nil))) |
| 1141 | |
| 1142 | (set-match-data data)))) |
| 1143 | |
| 1144 | (defun vc-cvs-parse-entry (file &optional set-state) |
| 1145 | "Parse a line from CVS/Entries. |
| 1146 | Compare modification time to that of the FILE, set file properties |
| 1147 | accordingly. However, `vc-state' is set only if optional arg SET-STATE |
| 1148 | is non-nil." |
| 1149 | (cond |
| 1150 | ;; entry for a "locally added" file (not yet committed) |
| 1151 | ((looking-at "/[^/]+/0/") |
| 1152 | (vc-file-setprop file 'vc-checkout-time 0) |
| 1153 | (vc-file-setprop file 'vc-working-revision "0") |
| 1154 | (if set-state (vc-file-setprop file 'vc-state 'added))) |
| 1155 | ;; normal entry |
| 1156 | ((looking-at |
| 1157 | (concat "/[^/]+" |
| 1158 | ;; revision |
| 1159 | "/\\([^/]*\\)" |
| 1160 | ;; timestamp and optional conflict field |
| 1161 | "/\\([^/]*\\)/" |
| 1162 | ;; options |
| 1163 | "\\([^/]*\\)/" |
| 1164 | ;; sticky tag |
| 1165 | "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty) |
| 1166 | "\\(.*\\)")) ;Sticky tag |
| 1167 | (vc-file-setprop file 'vc-working-revision (match-string 1)) |
| 1168 | (vc-file-setprop file 'vc-cvs-sticky-tag |
| 1169 | (vc-cvs-parse-sticky-tag (match-string 4) |
| 1170 | (match-string 5))) |
| 1171 | ;; Compare checkout time and modification time. |
| 1172 | ;; This is intentionally different from the algorithm that CVS uses |
| 1173 | ;; (which is based on textual comparison), because there can be problems |
| 1174 | ;; generating a time string that looks exactly like the one from CVS. |
| 1175 | (let* ((time (match-string 2)) |
| 1176 | (mtime (nth 5 (file-attributes file))) |
| 1177 | (parsed-time (progn (require 'parse-time) |
| 1178 | (parse-time-string (concat time " +0000"))))) |
| 1179 | (cond ((and (not (string-match "\\+" time)) |
| 1180 | (car parsed-time) |
| 1181 | (equal mtime (apply 'encode-time parsed-time))) |
| 1182 | (vc-file-setprop file 'vc-checkout-time mtime) |
| 1183 | (if set-state (vc-file-setprop file 'vc-state 'up-to-date))) |
| 1184 | (t |
| 1185 | (vc-file-setprop file 'vc-checkout-time 0) |
| 1186 | (if set-state (vc-file-setprop file 'vc-state 'edited)))))))) |
| 1187 | |
| 1188 | ;; Completion of revision names. |
| 1189 | ;; Just so I don't feel like I'm duplicating code from pcl-cvs, I'll use |
| 1190 | ;; `cvs log' so I can list all the revision numbers rather than only |
| 1191 | ;; tag names. |
| 1192 | |
| 1193 | (defun vc-cvs-revision-table (file) |
| 1194 | (let (process-file-side-effects |
| 1195 | (default-directory (file-name-directory file)) |
| 1196 | (res nil)) |
| 1197 | (with-temp-buffer |
| 1198 | (vc-cvs-command t nil file "log") |
| 1199 | (goto-char (point-min)) |
| 1200 | (when (re-search-forward "^symbolic names:\n" nil t) |
| 1201 | (while (looking-at "^ \\(.*\\): \\(.*\\)") |
| 1202 | (push (cons (match-string 1) (match-string 2)) res) |
| 1203 | (forward-line 1))) |
| 1204 | (while (re-search-forward "^revision \\([0-9.]+\\)" nil t) |
| 1205 | (push (match-string 1) res)) |
| 1206 | res))) |
| 1207 | |
| 1208 | (defun vc-cvs-revision-completion-table (files) |
| 1209 | (letrec ((table (lazy-completion-table |
| 1210 | table (lambda () (vc-cvs-revision-table (car files)))))) |
| 1211 | table)) |
| 1212 | |
| 1213 | |
| 1214 | (provide 'vc-cvs) |
| 1215 | |
| 1216 | ;;; vc-cvs.el ends here |