Mercurial > emacs
comparison lisp/vc.el @ 32126:3aab429d3c8a
(vc-revert-buffer): Handle empty diff properly.
(vc-version-backup-file): New function.
(vc-checkout): Create a version backup if necessary.
(vc-checkin): If a version backup file exists, delete it.
(vc-version-diff): Diff locally using version backups, if available.
(vc-revert-file): If there's a version backup, revert locally.
(vc-transfer-file): Use version backup for base version, if
available. If not, ask for confirmation whether to get it from the
server. Update mode line before check-in.
author | André Spiegel <spiegel@gnu.org> |
---|---|
date | Wed, 04 Oct 2000 09:48:37 +0000 |
parents | adf341c172af |
children | 921a2e8fa97e |
comparison
equal
deleted
inserted
replaced
32125:7f987164a4c3 | 32126:3aab429d3c8a |
---|---|
3 ;; Copyright (C) 1992,93,94,95,96,97,98,2000 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1992,93,94,95,96,97,98,2000 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: FSF (see below for full credits) | 5 ;; Author: FSF (see below for full credits) |
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org> | 6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org> |
7 | 7 |
8 ;; $Id: vc.el,v 1.275 2000/10/03 11:22:13 spiegel Exp $ | 8 ;; $Id: vc.el,v 1.276 2000/10/03 12:24:15 spiegel Exp $ |
9 | 9 |
10 ;; This file is part of GNU Emacs. | 10 ;; This file is part of GNU Emacs. |
11 | 11 |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | 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 | 13 ;; it under the terms of the GNU General Public License as published by |
136 ;; If UPDATE is non-nil, then update buffers of any files in the snapshot | 136 ;; If UPDATE is non-nil, then update buffers of any files in the snapshot |
137 ;; that are currently visited. | 137 ;; that are currently visited. |
138 ;; * print-log (file) | 138 ;; * print-log (file) |
139 ;; Insert the revision log of FILE into the current buffer. | 139 ;; Insert the revision log of FILE into the current buffer. |
140 ;; - show-log-entry (version) | 140 ;; - show-log-entry (version) |
141 ;; - wash-log (file) | |
142 ;; Remove all non-comment information from the output of print-log | |
141 ;; - comment-history (file) | 143 ;; - comment-history (file) |
142 ;; - update-changelog (files) | 144 ;; - update-changelog (files) |
143 ;; Find changelog entries for FILES, or for all files at or below | 145 ;; Find changelog entries for FILES, or for all files at or below |
144 ;; the default-directory if FILES is nil. | 146 ;; the default-directory if FILES is nil. |
145 ;; * latest-on-branch-p (file) | 147 ;; * latest-on-branch-p (file) |
1204 | 1206 |
1205 (defun vc-checkout (file &optional writable rev) | 1207 (defun vc-checkout (file &optional writable rev) |
1206 "Retrieve a copy of the revision REV of FILE. | 1208 "Retrieve a copy of the revision REV of FILE. |
1207 If WRITABLE is non-nil, make sure the retrieved file is writable. | 1209 If WRITABLE is non-nil, make sure the retrieved file is writable. |
1208 REV defaults to the latest revision." | 1210 REV defaults to the latest revision." |
1211 (and writable | |
1212 (not rev) | |
1213 (vc-call make-version-backups file) | |
1214 (vc-up-to-date-p file) | |
1215 (copy-file file (vc-version-backup-file-name file) | |
1216 'ok-if-already-exists 'keep-date)) | |
1209 (with-vc-properties | 1217 (with-vc-properties |
1210 file | 1218 file |
1211 (condition-case err | 1219 (condition-case err |
1212 (vc-call checkout file writable rev) | 1220 (vc-call checkout file writable rev) |
1213 (file-error | 1221 (file-error |
1278 (setq comment "*** empty log message ***")) | 1286 (setq comment "*** empty log message ***")) |
1279 (with-vc-properties | 1287 (with-vc-properties |
1280 file | 1288 file |
1281 ;; Change buffers to get local value of vc-checkin-switches. | 1289 ;; Change buffers to get local value of vc-checkin-switches. |
1282 (with-current-buffer (or (get-file-buffer file) (current-buffer)) | 1290 (with-current-buffer (or (get-file-buffer file) (current-buffer)) |
1283 (vc-call checkin file rev comment)) | 1291 (let ((backup-file (vc-version-backup-file file))) |
1292 (vc-call checkin file rev comment) | |
1293 (if backup-file (delete-file backup-file)))) | |
1284 `((vc-state up-to-date) | 1294 `((vc-state up-to-date) |
1285 (vc-checkout-time ,(nth 5 (file-attributes file))) | 1295 (vc-checkout-time ,(nth 5 (file-attributes file))) |
1286 (vc-workfile-version nil))) | 1296 (vc-workfile-version nil))) |
1287 (message "Checking in %s...done" file)) | 1297 (message "Checking in %s...done" file)) |
1288 'vc-checkin-hook)) | 1298 'vc-checkin-hook)) |
1491 (read-string (if rel2-default | 1501 (read-string (if rel2-default |
1492 (concat "Newer version: (default " | 1502 (concat "Newer version: (default " |
1493 rel2-default ") ") | 1503 rel2-default ") ") |
1494 "Newer version (default: current source): ") | 1504 "Newer version (default: current source): ") |
1495 nil nil rel2-default)))) | 1505 nil nil rel2-default)))) |
1496 (if (string-equal rel1 "") (setq rel1 nil)) | |
1497 (if (string-equal rel2 "") (setq rel2 nil)) | |
1498 (vc-setup-buffer "*vc-diff*") | 1506 (vc-setup-buffer "*vc-diff*") |
1499 (if (file-directory-p file) | 1507 (if (file-directory-p file) |
1508 ;; recursive directory diff | |
1500 (let ((inhibit-read-only t)) | 1509 (let ((inhibit-read-only t)) |
1510 (if (string-equal rel1 "") (setq rel1 nil)) | |
1511 (if (string-equal rel2 "") (setq rel2 nil)) | |
1501 (insert "Diffs between " | 1512 (insert "Diffs between " |
1502 (or rel1 "last version checked in") | 1513 (or rel1 "last version checked in") |
1503 " and " | 1514 " and " |
1504 (or rel2 "current workfile(s)") | 1515 (or rel2 "current workfile(s)") |
1505 ":\n\n") | 1516 ":\n\n") |
1512 `(progn | 1523 `(progn |
1513 (message "Looking at %s" ',f) | 1524 (message "Looking at %s" ',f) |
1514 (vc-call-backend ',(vc-backend file) 'diff ',f ',rel1 ',rel2))))) | 1525 (vc-call-backend ',(vc-backend file) 'diff ',f ',rel1 ',rel2))))) |
1515 (vc-exec-after `(let ((inhibit-read-only t)) | 1526 (vc-exec-after `(let ((inhibit-read-only t)) |
1516 (insert "\nEnd of diffs.\n")))) | 1527 (insert "\nEnd of diffs.\n")))) |
1517 | 1528 ;; single file diff |
1518 (cd (file-name-directory file)) | 1529 (if (or (not rel1) (string-equal rel1 "")) |
1519 (vc-call diff file rel1 rel2)) | 1530 (setq rel1 (vc-workfile-version file))) |
1531 (if (string-equal rel2 "") | |
1532 (setq rel2 nil)) | |
1533 (let ((file-rel1 (vc-version-backup-file file rel1)) | |
1534 (file-rel2 (if (not rel2) | |
1535 file | |
1536 (vc-version-backup-file file rel2)))) | |
1537 (if (and file-rel1 file-rel2) | |
1538 (vc-do-command t 1 "diff" nil diff-switches file-rel1 file-rel2) | |
1539 (cd (file-name-directory file)) | |
1540 (vc-call diff file rel1 rel2)))) | |
1520 (if (and (zerop (buffer-size)) | 1541 (if (and (zerop (buffer-size)) |
1521 (not (get-buffer-process (current-buffer)))) | 1542 (not (get-buffer-process (current-buffer)))) |
1522 (progn | 1543 (progn |
1523 (if rel1 | 1544 (if rel1 |
1524 (if rel2 | 1545 (if rel2 |
2154 (interactive) | 2175 (interactive) |
2155 (vc-ensure-vc-buffer) | 2176 (vc-ensure-vc-buffer) |
2156 (let ((file buffer-file-name) | 2177 (let ((file buffer-file-name) |
2157 ;; This operation should always ask for confirmation. | 2178 ;; This operation should always ask for confirmation. |
2158 (vc-suppress-confirm nil) | 2179 (vc-suppress-confirm nil) |
2159 (obuf (current-buffer))) | 2180 (obuf (current-buffer)) |
2181 status) | |
2160 (unless (vc-workfile-unchanged-p file) | 2182 (unless (vc-workfile-unchanged-p file) |
2161 (vc-diff nil t) | 2183 (setq status (vc-diff nil t)) |
2162 (vc-exec-after `(message nil)) | 2184 (vc-exec-after `(message nil)) |
2163 (unwind-protect | 2185 (when status |
2164 (if (not (yes-or-no-p "Discard changes? ")) | 2186 (unwind-protect |
2165 (error "Revert canceled")) | 2187 (if (not (yes-or-no-p "Discard changes? ")) |
2166 (if (and (window-dedicated-p (selected-window)) | 2188 (error "Revert canceled")) |
2167 (one-window-p t)) | 2189 (if (and (window-dedicated-p (selected-window)) |
2168 (make-frame-invisible) | 2190 (one-window-p t)) |
2169 (delete-window)))) | 2191 (make-frame-invisible) |
2192 (delete-window))))) | |
2170 (set-buffer obuf) | 2193 (set-buffer obuf) |
2171 ;; Do the reverting | 2194 ;; Do the reverting |
2172 (message "Reverting %s..." file) | 2195 (message "Reverting %s..." file) |
2173 (vc-revert-file file) | 2196 (vc-revert-file file) |
2174 (message "Reverting %s...done" file))) | 2197 (message "Reverting %s...done" file))) |
2175 | 2198 |
2199 (defun vc-version-backup-file (file &optional rev) | |
2200 "If version backups should be used for FILE, and there exists | |
2201 such a backup for REV or the current workfile version of file, | |
2202 return the name of it; otherwise return nil." | |
2203 (when (vc-call make-version-backups file) | |
2204 (let ((backup-file (vc-version-backup-file-name file rev))) | |
2205 (and (file-exists-p backup-file) | |
2206 backup-file)))) | |
2207 | |
2176 (defun vc-revert-file (file) | 2208 (defun vc-revert-file (file) |
2177 "Revert FILE back to the version it was based on." | 2209 "Revert FILE back to the version it was based on." |
2178 ;; TODO: With local version caching, this function will get the | |
2179 ;; base version locally and not from the server. | |
2180 (with-vc-properties | 2210 (with-vc-properties |
2181 file | 2211 file |
2182 (vc-call revert file) | 2212 (let ((backup-file (vc-version-backup-file file))) |
2213 (if (not backup-file) | |
2214 (vc-call revert file) | |
2215 (copy-file backup-file file 'ok-if-already-exists 'keep-date) | |
2216 (delete-file backup-file))) | |
2183 `((vc-state up-to-date) | 2217 `((vc-state up-to-date) |
2184 (vc-checkout-time ,(nth 5 (file-attributes file))))) | 2218 (vc-checkout-time ,(nth 5 (file-attributes file))))) |
2185 (vc-resynch-buffer file t t)) | 2219 (vc-resynch-buffer file t t)) |
2186 | 2220 |
2187 ;;;###autoload | 2221 ;;;###autoload |
2286 (registered (vc-call-backend new-backend 'registered file)) | 2320 (registered (vc-call-backend new-backend 'registered file)) |
2287 (move | 2321 (move |
2288 (and registered ; Never move if not registered in new-backend yet. | 2322 (and registered ; Never move if not registered in new-backend yet. |
2289 ;; move if new-backend comes later in vc-handled-backends | 2323 ;; move if new-backend comes later in vc-handled-backends |
2290 (or (memq new-backend (memq old-backend vc-handled-backends)) | 2324 (or (memq new-backend (memq old-backend vc-handled-backends)) |
2291 (y-or-n-p "Final transfer ? ")))) | 2325 (y-or-n-p "Final transfer? ")))) |
2292 (comment nil)) | 2326 (comment nil)) |
2293 (if (eq old-backend new-backend) | 2327 (if (eq old-backend new-backend) |
2294 (error "%s is the current backend of %s" new-backend file)) | 2328 (error "%s is the current backend of %s" new-backend file)) |
2295 (if registered | 2329 (if registered |
2296 (set-file-modes file (logior (file-modes file) 128)) | 2330 (set-file-modes file (logior (file-modes file) 128)) |
2297 ;; `registered' might have switched under us. | 2331 ;; `registered' might have switched under us. |
2298 (vc-switch-backend file old-backend) | 2332 (vc-switch-backend file old-backend) |
2299 (let ((copy (and edited (make-temp-name file))) | 2333 (let* ((rev (vc-workfile-version file)) |
2300 (rev (vc-workfile-version file))) | 2334 (modified-file (and edited (make-temp-name file))) |
2335 (unmodified-file (and modified-file (vc-version-backup-file file)))) | |
2301 ;; Go back to the base unmodified file. | 2336 ;; Go back to the base unmodified file. |
2302 (unwind-protect | 2337 (unwind-protect |
2303 (progn | 2338 (progn |
2304 (when copy (copy-file file copy)) ; (vc-revert-file file)) | 2339 (when modified-file |
2305 ; TODO: uncomment when we | 2340 (copy-file file modified-file) |
2306 ; have local version caching | 2341 ;; If we have a local copy of the unmodified file, handle that |
2342 ;; here and not in vc-revert-file because we don't want to | |
2343 ;; delete that copy -- it is still useful for OLD-BACKEND. | |
2344 (if unmodified-file | |
2345 (copy-file unmodified-file file 'ok-if-already-exists) | |
2346 (if (y-or-n-p "Get base version from master? ") | |
2347 (vc-revert-file file)))) | |
2307 (vc-call-backend new-backend 'receive-file file rev)) | 2348 (vc-call-backend new-backend 'receive-file file rev)) |
2308 (when copy | 2349 (when modified-file |
2309 (vc-switch-backend file new-backend) | 2350 (vc-switch-backend file new-backend) |
2310 (unless (eq (vc-checkout-model file) 'implicit) | 2351 (unless (eq (vc-checkout-model file) 'implicit) |
2311 (vc-checkout file t nil)) | 2352 (vc-checkout file t nil)) |
2312 (rename-file copy file 'ok-if-already-exists))))) | 2353 (rename-file modified-file file 'ok-if-already-exists) |
2354 (vc-file-setprop file 'vc-checkout-time nil))))) | |
2313 (when move | 2355 (when move |
2314 (vc-switch-backend file old-backend) | 2356 (vc-switch-backend file old-backend) |
2315 (setq comment (vc-call comment-history file)) | 2357 (setq comment (vc-call comment-history file)) |
2316 (vc-call unregister file)) | 2358 (vc-call unregister file)) |
2317 (vc-switch-backend file new-backend) | 2359 (vc-switch-backend file new-backend) |
2318 (when (or move edited) | 2360 (when (or move edited) |
2319 (vc-file-setprop file 'vc-state 'edited) | 2361 (vc-file-setprop file 'vc-state 'edited) |
2362 (vc-mode-line file) | |
2320 (vc-checkin file nil comment (stringp comment))))) | 2363 (vc-checkin file nil comment (stringp comment))))) |
2321 | 2364 |
2322 (defun vc-default-unregister (backend file) | 2365 (defun vc-default-unregister (backend file) |
2323 "Default implementation of `vc-unregister', signals an error." | 2366 "Default implementation of `vc-unregister', signals an error." |
2324 (error "Unregistering files is not supported for %s" backend)) | 2367 (error "Unregistering files is not supported for %s" backend)) |