aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond2008-05-09 01:57:21 +0000
committerEric S. Raymond2008-05-09 01:57:21 +0000
commit86048828d8df4a4972eff31ce484b10ad408c73a (patch)
tree0b7722cfc0c1011b2c6ee3aa1743b78819d4e71e
parent23b98b71bb8b60bc78c592758a667f338290b4f7 (diff)
downloademacs-86048828d8df4a4972eff31ce484b10ad408c73a.tar.gz
emacs-86048828d8df4a4972eff31ce484b10ad408c73a.zip
Large simplification in (vc-deduce-fileset) logic.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/vc-dispatcher.el57
-rw-r--r--lisp/vc.el98
3 files changed, 69 insertions, 95 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9c536a464fb..7ea50655461 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12008-05-09 Eric S. Raymond <esr@snark.thyrsus.com>
2
3 * vc.el (vc-deduce-fileset, vc-next-action, vc-version-diff)
4 (vc-diff, vc-rwevert, vc-rollback, vc-update),
5 vc-dispatcher.el (vc-dispatcher-selection-set):
6 Get rid of 4 special cases in fileset selection. This involved
7 changing the return value of (vc-deduce-fileset) so that it passes
8 back a deduced state as well as a deduced back end,
9
12008-05-08 Sam Steingold <sds@gnu.org> 102008-05-08 Sam Steingold <sds@gnu.org>
2 11
3 * progmodes/compile.el (compilation-minor-mode-map) 12 * progmodes/compile.el (compilation-minor-mode-map)
diff --git a/lisp/vc-dispatcher.el b/lisp/vc-dispatcher.el
index c590f409950..002ac5438e6 100644
--- a/lisp/vc-dispatcher.el
+++ b/lisp/vc-dispatcher.el
@@ -1328,64 +1328,31 @@ NOT-URGENT means it is ok to continue if the user says not to save."
1328 "Are we in a directory browser buffer?" 1328 "Are we in a directory browser buffer?"
1329 (eq major-mode 'vc-dir-mode)) 1329 (eq major-mode 'vc-dir-mode))
1330 1330
1331(defun vc-dispatcher-selection-set (eligible 1331(defun vc-dispatcher-selection-set ()
1332 &optional
1333 allow-directory-wildcard
1334 allow-ineligible
1335 include-files-not-directories)
1336 "Deduce a set of files to which to apply an operation. Return the fileset. 1332 "Deduce a set of files to which to apply an operation. Return the fileset.
1337If we're in a directory display, the fileset is the list of marked files. 1333If we're in a directory display, the fileset is the list of marked files (if
1338Otherwise, if we're looking at a buffer for which ELIGIBLE returns non-NIL, 1334there is one) else the file on the curreent line. If not in a directory
1339the fileset is a singleton containing this file. 1335display, but the current buffer visits a file, the fileset is a singleton
1340If neither of these things is true, but ALLOW-DIRECTORY-WILDCARD is on 1336containing that file. Otherwise, throw an error."
1341and we're in a directory buffer, select the current directory.
1342If none of these conditions is met, but ALLOW-INELIGIBLE is on and the
1343visited file is not registered, return a singleton fileset containing it.
1344If INCLUDE-FILES-NOT-DIRECTORIES then if directories are marked,
1345return the list of VC files in those directories instead of
1346the directories themselves.
1347Otherwise, throw an error."
1348 (let ((files 1337 (let ((files
1349 (cond 1338 (cond
1350 ;; Browsing with vc-dir 1339 ;; Browsing with vc-dir
1351 ((eq major-mode 'vc-dir-mode) 1340 ((vc-dispatcher-browsing)
1352 (or 1341 (or (vc-dir-marked-files) (list (vc-dir-current-file))))
1353 (if include-files-not-directories
1354 (vc-dir-marked-only-files)
1355 (vc-dir-marked-files))
1356 (list (vc-dir-current-file))))
1357 ;; Visiting an eligible file 1342 ;; Visiting an eligible file
1358 ((funcall eligible buffer-file-name) 1343 ((buffer-file-name)
1359 (list buffer-file-name)) 1344 (list buffer-file-name))
1360 ;; No eligible file -- if there's a parent buffer, deuce from there 1345 ;; No eligible file -- if there's a parent buffer, deduce from there
1361 ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer) 1346 ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer)
1362 (with-current-buffer vc-parent-buffer 1347 (with-current-buffer vc-parent-buffer
1363 (vc-dispatcher-browsing)))) 1348 (vc-dispatcher-browsing))))
1364 (progn 1349 (with-current-buffer vc-parent-buffer
1365 (set-buffer vc-parent-buffer) 1350 (vc-dispatcher-selection-set)))
1366 (vc-dispatcher-selection-set eligible)))
1367 ;; No parent buffer, we may want to select entire directory
1368 ;;
1369 ;; This is guarded by an enabling arg so users won't potentially
1370 ;; shoot themselves in the foot by modifying a fileset they can't
1371 ;; verify by eyeball. Allow it for nondestructive commands like
1372 ;; making diffs, or possibly for destructive ones that have
1373 ;; confirmation prompts.
1374 ((and allow-directory-wildcard
1375 (equal buffer-file-name nil)
1376 (equal list-buffers-directory default-directory))
1377 (progn
1378 (message "All eligible files below %s selected."
1379 default-directory)
1380 (list default-directory)))
1381 ;; Last, if we're allowing ineligible files and visiting one, select it.
1382 ((and allow-ineligible (not (eligible buffer-file-name)))
1383 (list buffer-file-name))
1384 ;; No good set here, throw error 1351 ;; No good set here, throw error
1385 (t (error "No fileset is available here."))))) 1352 (t (error "No fileset is available here.")))))
1386 ;; We assume, in order to avoid unpleasant surprises to the user, 1353 ;; We assume, in order to avoid unpleasant surprises to the user,
1387 ;; that a fileset is not in good shape to be handed to the user if the 1354 ;; that a fileset is not in good shape to be handed to the user if the
1388 ;; buffers visting the fileset don't match the on-disk contents. 1355 ;; buffers visiting the fileset don't match the on-disk contents.
1389 (dolist (file files) 1356 (dolist (file files)
1390 (let ((visited (get-file-buffer file))) 1357 (let ((visited (get-file-buffer file)))
1391 (when visited 1358 (when visited
diff --git a/lisp/vc.el b/lisp/vc.el
index 259def06765..7127225ad4c 100644
--- a/lisp/vc.el
+++ b/lisp/vc.el
@@ -1003,28 +1003,30 @@ be registered."
1003(defun vc-expand-dirs (file-or-dir-list) 1003(defun vc-expand-dirs (file-or-dir-list)
1004 "Expands directories in a file list specification. 1004 "Expands directories in a file list specification.
1005Only files already under version control are noticed." 1005Only files already under version control are noticed."
1006 ;; FIXME: Kill this function.
1007 (let ((flattened '())) 1006 (let ((flattened '()))
1008 (dolist (node file-or-dir-list) 1007 (dolist (node file-or-dir-list)
1009 (vc-file-tree-walk 1008 (vc-file-tree-walk
1010 node (lambda (f) (when (vc-backend f) (push f flattened))))) 1009 node (lambda (f) (when (vc-backend f) (push f flattened)))))
1011 (nreverse flattened))) 1010 (nreverse flattened)))
1012 1011
1013(defun vc-deduce-fileset (&optional allow-directory-wildcard allow-unregistered 1012(defun vc-deduce-fileset ()
1014 include-files-not-directories) 1013 "Deduce a set of files and a backend to which to apply an operation and
1015 "Deduce a set of files and a backend to which to apply an operation. 1014the common state of the fileset. Return (BACKEND . (STATE . FILESET))."
1016Return (BACKEND . FILESET)." 1015 (let* ((fileset (vc-dispatcher-selection-set))
1017 (let* ((fileset (vc-dispatcher-selection-set 1016 (fileset-only-files (vc-expand-dirs fileset))
1018 #'vc-registered 1017 (firstfile (car fileset-only-files))
1019 allow-directory-wildcard 1018 (firstbackend (vc-backend firstfile))
1020 allow-unregistered 1019 (firstmodel (vc-checkout-model firstbackend (list firstfile)))
1021 include-files-not-directories)) 1020 (firststate (vc-state firstfile)))
1022 (backend (vc-backend (car fileset)))) 1021 (dolist (file (cdr fileset-only-files))
1023 ;; All members of the fileset must have the same backend 1022 (unless (eq (vc-backend file) firstbackend)
1024 (dolist (f (cdr fileset)) 1023 (error "All members of a fileset must be under the same version-control system."))
1025 (unless (eq (vc-backend f) backend) 1024 (unless (vc-compatible-state (vc-state file) firststate)
1026 (error "All members of a fileset must be under the same version-control system."))) 1025 (error "%s:%s clashes with %s:%s"
1027 (cons backend fileset))) 1026 file (vc-state file) firstfile firststate))
1027 (unless (eq (vc-checkout-model firstbackend (list file)) firstmodel)
1028 (error "Fileset has mixed checkout models")))
1029 (cons firstbackend (cons firststate fileset))))
1028 1030
1029(defun vc-ensure-vc-buffer () 1031(defun vc-ensure-vc-buffer ()
1030 "Make sure that the current buffer visits a version-controlled file." 1032 "Make sure that the current buffer visits a version-controlled file."
@@ -1094,31 +1096,19 @@ with the logmessage as change commentary. A writable file is retained.
1094 If the repository file is changed, you are asked if you want to 1096 If the repository file is changed, you are asked if you want to
1095merge in the changes into your working copy." 1097merge in the changes into your working copy."
1096 (interactive "P") 1098 (interactive "P")
1097 (let* ((vc-fileset (vc-deduce-fileset nil t)) 1099 (let* ((vc-fileset (vc-deduce-fileset))
1098 (vc-fileset-only-files (vc-deduce-fileset nil t t))
1099 (only-files (cdr vc-fileset-only-files))
1100 (backend (car vc-fileset)) 1100 (backend (car vc-fileset))
1101 (files (cdr vc-fileset)) 1101 (state (cadr vc-fileset))
1102 (state (vc-state (car only-files))) 1102 (files (cddr vc-fileset))
1103 (model (vc-checkout-model backend files)) 1103 (model (vc-checkout-model backend files))
1104 revision) 1104 revision)
1105
1106 ;; Verify that the fileset is homogeneous
1107 (dolist (file (cdr only-files))
1108 ;; Ignore directories, they are compatible with anything.
1109 (unless (file-directory-p file)
1110 (unless (vc-compatible-state (vc-state file) state)
1111 (error "%s:%s clashes with %s:%s"
1112 file (vc-state file) (car files) state))
1113 (unless (eq (vc-checkout-model backend (list file)) model)
1114 (error "Fileset has mixed checkout models"))))
1115 ;; Do the right thing 1105 ;; Do the right thing
1116 (cond 1106 (cond
1117 ((eq state 'missing) 1107 ((eq state 'missing)
1118 (error "Fileset files are missing, so cannot be operated on.")) 1108 (error "Fileset files are missing, so cannot be operated on."))
1119 ;; Files aren't registered 1109 ((eq state 'ignored)
1120 ((or (eq state 'unregistered) 1110 (error "Fileset files are ignored by the version-control system."))
1121 (eq state 'ignored)) 1111 ((eq state 'unregistered)
1122 (mapc (lambda (arg) (vc-register nil arg)) files)) 1112 (mapc (lambda (arg) (vc-register nil arg)) files))
1123 ;; Files are up-to-date, or need a merge and user specified a revision 1113 ;; Files are up-to-date, or need a merge and user specified a revision
1124 ((or (eq state 'up-to-date) (and verbose (eq state 'needs-update))) 1114 ((or (eq state 'up-to-date) (and verbose (eq state 'needs-update)))
@@ -1224,7 +1214,8 @@ merge in the changes into your working copy."
1224 (when (not (equal buffer-file-name file)) 1214 (when (not (equal buffer-file-name file))
1225 (find-file-other-window file)) 1215 (find-file-other-window file))
1226 (if (save-window-excursion 1216 (if (save-window-excursion
1227 (vc-diff-internal nil (cons (car vc-fileset) (list file)) 1217 (vc-diff-internal nil
1218 (cons (car vc-fileset) (cons (cadr vc-fileset) (list file)))
1228 (vc-working-revision file) nil) 1219 (vc-working-revision file) nil)
1229 (goto-char (point-min)) 1220 (goto-char (point-min))
1230 (let ((inhibit-read-only t)) 1221 (let ((inhibit-read-only t))
@@ -1502,7 +1493,7 @@ Runs the normal hooks `vc-before-checkin-hook' and `vc-checkin-hook'."
1502 "Report diffs between two revisions of a fileset. 1493 "Report diffs between two revisions of a fileset.
1503Diff output goes to the *vc-diff* buffer. The function 1494Diff output goes to the *vc-diff* buffer. The function
1504returns t if the buffer had changes, nil otherwise." 1495returns t if the buffer had changes, nil otherwise."
1505 (let* ((files (cdr vc-fileset)) 1496 (let* ((files (cddr vc-fileset))
1506 (messages (cons (format "Finding changes in %s..." 1497 (messages (cons (format "Finding changes in %s..."
1507 (vc-delistify files)) 1498 (vc-delistify files))
1508 (format "No changes between %s and %s" 1499 (format "No changes between %s and %s"
@@ -1567,8 +1558,10 @@ returns t if the buffer had changes, nil otherwise."
1567(defun vc-version-diff (files rev1 rev2) 1558(defun vc-version-diff (files rev1 rev2)
1568 "Report diffs between revisions of the fileset in the repository history." 1559 "Report diffs between revisions of the fileset in the repository history."
1569 (interactive 1560 (interactive
1570 (let* ((vc-fileset (vc-deduce-fileset t)) 1561 (let* ((vc-fileset (vc-deduce-fileset))
1571 (files (cdr vc-fileset)) 1562 (backend (car files))
1563 (state (cadr vc-fileset))
1564 (files (cddr vc-fileset))
1572 (first (car files)) 1565 (first (car files))
1573 (completion-table 1566 (completion-table
1574 (vc-call revision-completion-table files)) 1567 (vc-call revision-completion-table files))
@@ -1609,10 +1602,12 @@ returns t if the buffer had changes, nil otherwise."
1609 (when (string= rev1 "") (setq rev1 nil)) 1602 (when (string= rev1 "") (setq rev1 nil))
1610 (when (string= rev2 "") (setq rev2 nil)) 1603 (when (string= rev2 "") (setq rev2 nil))
1611 (list files rev1 rev2)))) 1604 (list files rev1 rev2))))
1605 ;; All that was just so we could do argument completion!
1612 (when (and (not rev1) rev2) 1606 (when (and (not rev1) rev2)
1613 (error "Not a valid revision range.")) 1607 (error "Not a valid revision range."))
1614 (vc-diff-internal 1608 ;; Yes, it's painful to call (vc-deduce-fileset) again. Alas, the
1615 t (cons (car (vc-deduce-fileset t)) files) rev1 rev2 (interactive-p))) 1609 ;; placement rules for (interactive) don't actually leave us a choice.
1610 (vc-diff-internal t (vc-deduce-fileset) rev1 rev2 (interactive-p)))
1616 1611
1617;; (defun vc-contains-version-controlled-file (dir) 1612;; (defun vc-contains-version-controlled-file (dir)
1618;; "Return t if DIR contains a version-controlled file, nil otherwise." 1613;; "Return t if DIR contains a version-controlled file, nil otherwise."
@@ -1627,16 +1622,13 @@ Normally this compares the currently selected fileset with their
1627working revisions. With a prefix argument HISTORIC, it reads two revision 1622working revisions. With a prefix argument HISTORIC, it reads two revision
1628designators specifying which revisions to compare. 1623designators specifying which revisions to compare.
1629 1624
1630If no current fileset is available and we're in a directory buffer, use
1631the current directory.
1632The optional argument NOT-URGENT non-nil means it is ok to say no to 1625The optional argument NOT-URGENT non-nil means it is ok to say no to
1633saving the buffer." 1626saving the buffer."
1634 (interactive (list current-prefix-arg t)) 1627 (interactive (list current-prefix-arg t))
1635 (if historic 1628 (if historic
1636 (call-interactively 'vc-version-diff) 1629 (call-interactively 'vc-version-diff)
1637 (when buffer-file-name (vc-buffer-sync not-urgent)) 1630 (when buffer-file-name (vc-buffer-sync not-urgent))
1638 (vc-diff-internal t (vc-deduce-fileset t) nil nil (interactive-p)))) 1631 (vc-diff-internal t (vc-deduce-fileset) nil nil (interactive-p))))
1639
1640 1632
1641;;;###autoload 1633;;;###autoload
1642(defun vc-revision-other-window (rev) 1634(defun vc-revision-other-window (rev)
@@ -2128,8 +2120,9 @@ allowed and simply skipped)."
2128If WORKING-REVISION is non-nil, leave the point at that revision." 2120If WORKING-REVISION is non-nil, leave the point at that revision."
2129 (interactive) 2121 (interactive)
2130 (let* ((vc-fileset (vc-deduce-fileset)) 2122 (let* ((vc-fileset (vc-deduce-fileset))
2131 (files (cdr vc-fileset))
2132 (backend (car vc-fileset)) 2123 (backend (car vc-fileset))
2124 (state (cadr vc-fileset))
2125 (files (cddr vc-fileset))
2133 (working-revision (or working-revision (vc-working-revision (car files))))) 2126 (working-revision (or working-revision (vc-working-revision (car files)))))
2134 ;; Don't switch to the output buffer before running the command, 2127 ;; Don't switch to the output buffer before running the command,
2135 ;; so that any buffer-local settings in the vc-controlled 2128 ;; so that any buffer-local settings in the vc-controlled
@@ -2159,7 +2152,9 @@ This asks for confirmation if the buffer contents are not identical
2159to the working revision (except for keyword expansion)." 2152to the working revision (except for keyword expansion)."
2160 (interactive) 2153 (interactive)
2161 (let* ((vc-fileset (vc-deduce-fileset)) 2154 (let* ((vc-fileset (vc-deduce-fileset))
2162 (files (cdr vc-fileset))) 2155 (backend (car vc-fileset))
2156 (state (cadr vc-fileset))
2157 (files (cddr vc-fileset)))
2163 ;; If any of the files is visited by the current buffer, make 2158 ;; If any of the files is visited by the current buffer, make
2164 ;; sure buffer is saved. If the user says `no', abort since 2159 ;; sure buffer is saved. If the user says `no', abort since
2165 ;; we cannot show the changes and ask for confirmation to 2160 ;; we cannot show the changes and ask for confirmation to
@@ -2190,8 +2185,9 @@ This may be either a file-level or a repository-level operation,
2190depending on the underlying version-control system." 2185depending on the underlying version-control system."
2191 (interactive) 2186 (interactive)
2192 (let* ((vc-fileset (vc-deduce-fileset)) 2187 (let* ((vc-fileset (vc-deduce-fileset))
2193 (files (cdr vc-fileset))
2194 (backend (car vc-fileset)) 2188 (backend (car vc-fileset))
2189 (state (cadr vc-fileset))
2190 (files (cddr vc-fileset))
2195 (granularity (vc-call-backend backend 'revision-granularity))) 2191 (granularity (vc-call-backend backend 'revision-granularity)))
2196 (unless (vc-find-backend-function backend 'rollback) 2192 (unless (vc-find-backend-function backend 'rollback)
2197 (error "Rollback is not supported in %s" backend)) 2193 (error "Rollback is not supported in %s" backend))
@@ -2245,8 +2241,9 @@ contains changes, and the backend supports merging news, then any recent
2245changes from the current branch are merged into the working file." 2241changes from the current branch are merged into the working file."
2246 (interactive) 2242 (interactive)
2247 (let* ((vc-fileset (vc-deduce-fileset)) 2243 (let* ((vc-fileset (vc-deduce-fileset))
2248 (files (cdr vc-fileset)) 2244 (backend (car vc-fileset))
2249 (backend (car vc-fileset))) 2245 (state (cadr vc-fileset))
2246 (files (cddr vc-fileset)))
2250 (dolist (file files) 2247 (dolist (file files)
2251 (when (let ((buf (get-file-buffer file))) 2248 (when (let ((buf (get-file-buffer file)))
2252 (and buf (buffer-modified-p buf))) 2249 (and buf (buffer-modified-p buf)))
@@ -3138,7 +3135,8 @@ revisions after."
3138 (vc-diff-internal 3135 (vc-diff-internal
3139 nil 3136 nil
3140 (cons (vc-backend vc-annotate-parent-file) 3137 (cons (vc-backend vc-annotate-parent-file)
3141 (list vc-annotate-parent-file)) 3138 (cons nil
3139 (list vc-annotate-parent-file)))
3142 prev-rev rev-at-line)) 3140 prev-rev rev-at-line))
3143 (switch-to-buffer "*vc-diff*")))))) 3141 (switch-to-buffer "*vc-diff*"))))))
3144 3142