aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond2008-05-03 09:45:20 +0000
committerEric S. Raymond2008-05-03 09:45:20 +0000
commit83affd963e63d0e177e34f542064f2402cc97b39 (patch)
tree97b9dccb2b1dab9a3840b220d2a4590da9b6f083
parent58bb7d50aea817b851360891adaacde55355eb2b (diff)
downloademacs-83affd963e63d0e177e34f542064f2402cc97b39.tar.gz
emacs-83affd963e63d0e177e34f542064f2402cc97b39.zip
Move the command-closure machinery to vc-dispatcher.el.
-rw-r--r--lisp/vc-dispatcher.el121
-rw-r--r--lisp/vc.el73
2 files changed, 125 insertions, 69 deletions
diff --git a/lisp/vc-dispatcher.el b/lisp/vc-dispatcher.el
index 6afe2eeb8e5..16fd17a1467 100644
--- a/lisp/vc-dispatcher.el
+++ b/lisp/vc-dispatcher.el
@@ -76,6 +76,29 @@
76 76
77(provide 'vc-dispatcher) 77(provide 'vc-dispatcher)
78 78
79;; General customization
80
81(defcustom vc-logentry-check-hook nil
82 "Normal hook run by `vc-finish-logentry'.
83Use this to impose your own rules on the entry in addition to any the
84version control backend imposes itself."
85 :type 'hook
86 :group 'vc)
87
88;; Variables the user doesn't need to know about.
89(defvar vc-log-operation nil)
90(defvar vc-log-after-operation-hook nil)
91(defvar vc-log-fileset)
92(defvar vc-log-extra)
93
94;; In a log entry buffer, this is a local variable
95;; that points to the buffer for which it was made
96;; (either a file, or a VC dired buffer).
97(defvar vc-parent-buffer nil)
98(put 'vc-parent-buffer 'permanent-local t)
99(defvar vc-parent-buffer-name nil)
100(put 'vc-parent-buffer-name 'permanent-local t)
101
79;; Common command execution logic 102;; Common command execution logic
80 103
81(defun vc-process-filter (p s) 104(defun vc-process-filter (p s)
@@ -287,4 +310,102 @@ that is inserted into the command line before the filename."
287 ',command ',file-or-list ',flags)) 310 ',command ',file-or-list ',flags))
288 status)))) 311 status))))
289 312
313;; Command closures
314
315(defun vc-start-logentry (files extra comment initial-contents msg action &optional after-hook)
316 "Accept a comment for an operation on FILES with extra data EXTRA.
317If COMMENT is nil, pop up a VC-log buffer, emit MSG, and set the
318action on close to ACTION. If COMMENT is a string and
319INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial
320contents of the log entry buffer. If COMMENT is a string and
321INITIAL-CONTENTS is nil, do action immediately as if the user had
322entered COMMENT. If COMMENT is t, also do action immediately with an
323empty comment. Remember the file's buffer in `vc-parent-buffer'
324\(current one if no file). AFTER-HOOK specifies the local value
325for `vc-log-after-operation-hook'."
326 (let ((parent
327 (if (or (eq major-mode 'vc-dired-mode) (eq major-mode 'vc-dir-mode))
328 ;; If we are called from VC dired, the parent buffer is
329 ;; the current buffer.
330 (current-buffer)
331 (if (and files (equal (length files) 1))
332 (get-file-buffer (car files))
333 (current-buffer)))))
334 (when vc-before-checkin-hook
335 (if files
336 (with-current-buffer parent
337 (run-hooks 'vc-before-checkin-hook))
338 (run-hooks 'vc-before-checkin-hook)))
339 (if (and comment (not initial-contents))
340 (set-buffer (get-buffer-create "*VC-log*"))
341 (pop-to-buffer (get-buffer-create "*VC-log*")))
342 (set (make-local-variable 'vc-parent-buffer) parent)
343 (set (make-local-variable 'vc-parent-buffer-name)
344 (concat " from " (buffer-name vc-parent-buffer)))
345 ;;(if file (vc-mode-line file))
346 (vc-log-edit files)
347 (make-local-variable 'vc-log-after-operation-hook)
348 (when after-hook
349 (setq vc-log-after-operation-hook after-hook))
350 (setq vc-log-operation action)
351 (setq vc-log-extra extra)
352 (when comment
353 (erase-buffer)
354 (when (stringp comment) (insert comment)))
355 (if (or (not comment) initial-contents)
356 (message "%s Type C-c C-c when done" msg)
357 (vc-finish-logentry (eq comment t)))))
358
359(defun vc-finish-logentry (&optional nocomment)
360 "Complete the operation implied by the current log entry.
361Use the contents of the current buffer as a check-in or registration
362comment. If the optional arg NOCOMMENT is non-nil, then don't check
363the buffer contents as a comment."
364 (interactive)
365 ;; Check and record the comment, if any.
366 (unless nocomment
367 (run-hooks 'vc-logentry-check-hook))
368 ;; Sync parent buffer in case the user modified it while editing the comment.
369 ;; But not if it is a vc-dired buffer.
370 (with-current-buffer vc-parent-buffer
371 (or vc-dired-mode (eq major-mode 'vc-dir-mode) (vc-buffer-sync)))
372 (unless vc-log-operation
373 (error "No log operation is pending"))
374 ;; save the parameters held in buffer-local variables
375 (let ((log-operation vc-log-operation)
376 (log-fileset vc-log-fileset)
377 (log-extra vc-log-extra)
378 (log-entry (buffer-string))
379 (after-hook vc-log-after-operation-hook)
380 (tmp-vc-parent-buffer vc-parent-buffer))
381 (pop-to-buffer vc-parent-buffer)
382 ;; OK, do it to it
383 (save-excursion
384 (funcall log-operation
385 log-fileset
386 log-extra
387 log-entry))
388 ;; Remove checkin window (after the checkin so that if that fails
389 ;; we don't zap the *VC-log* buffer and the typing therein).
390 ;; -- IMO this should be replaced with quit-window
391 (let ((logbuf (get-buffer "*VC-log*")))
392 (cond ((and logbuf vc-delete-logbuf-window)
393 (delete-windows-on logbuf (selected-frame))
394 ;; Kill buffer and delete any other dedicated windows/frames.
395 (kill-buffer logbuf))
396 (logbuf (pop-to-buffer "*VC-log*")
397 (bury-buffer)
398 (pop-to-buffer tmp-vc-parent-buffer))))
399 ;; Now make sure we see the expanded headers
400 (when log-fileset
401 (mapc
402 (lambda (file) (vc-resynch-buffer file vc-keep-workfiles t))
403 log-fileset))
404 (when vc-dired-mode
405 (dired-move-to-filename))
406 (when (eq major-mode 'vc-dir-mode)
407 (vc-dir-move-to-goal-column))
408 (run-hooks after-hook 'vc-finish-logentry-hook)))
409
410
290;;; vc-dispatcher.el ends here 411;;; vc-dispatcher.el ends here
diff --git a/lisp/vc.el b/lisp/vc.el
index e12af0cec90..f4bc6cb25df 100644
--- a/lisp/vc.el
+++ b/lisp/vc.el
@@ -851,13 +851,6 @@ See `run-hooks'."
851 :type 'hook 851 :type 'hook
852 :group 'vc) 852 :group 'vc)
853 853
854(defcustom vc-logentry-check-hook nil
855 "Normal hook run by `vc-finish-logentry'.
856Use this to impose your own rules on the entry in addition to any the
857version control backend imposes itself."
858 :type 'hook
859 :group 'vc)
860
861(defcustom vc-dir-mode-hook nil 854(defcustom vc-dir-mode-hook nil
862 "Normal hook run by `vc-dir-mode'. 855 "Normal hook run by `vc-dir-mode'.
863See `run-hooks'." 856See `run-hooks'."
@@ -990,26 +983,13 @@ and that its contents match what the master file says."
990 "21.1") 983 "21.1")
991 984
992 985
993;; Variables the user doesn't need to know about. 986;; Variables users don't need to see
994(defvar vc-log-operation nil)
995(defvar vc-log-after-operation-hook nil)
996
997;; In a log entry buffer, this is a local variable
998;; that points to the buffer for which it was made
999;; (either a file, or a VC dired buffer).
1000(defvar vc-parent-buffer nil)
1001(put 'vc-parent-buffer 'permanent-local t)
1002(defvar vc-parent-buffer-name nil)
1003(put 'vc-parent-buffer-name 'permanent-local t)
1004 987
1005(defvar vc-disable-async-diff nil 988(defvar vc-disable-async-diff nil
1006 "VC sets this to t locally to disable some async diff operations. 989 "VC sets this to t locally to disable some async diff operations.
1007Backends that offer asynchronous diffs should respect this variable 990Backends that offer asynchronous diffs should respect this variable
1008in their implementation of vc-BACKEND-diff.") 991in their implementation of vc-BACKEND-diff.")
1009 992
1010(defvar vc-log-fileset)
1011(defvar vc-log-revision)
1012
1013(defvar vc-dired-mode nil) 993(defvar vc-dired-mode nil)
1014(make-variable-buffer-local 'vc-dired-mode) 994(make-variable-buffer-local 'vc-dired-mode)
1015 995
@@ -1630,7 +1610,7 @@ first backend that could register the file is used."
1630 (not (file-exists-p buffer-file-name))) 1610 (not (file-exists-p buffer-file-name)))
1631 (set-buffer-modified-p t)) 1611 (set-buffer-modified-p t))
1632 (vc-buffer-sync))) 1612 (vc-buffer-sync)))
1633 (vc-start-entry (list fname) 1613 (vc-start-logentry (list fname)
1634 (if set-revision 1614 (if set-revision
1635 (read-string (format "Initial revision level for %s: " 1615 (read-string (format "Initial revision level for %s: "
1636 fname)) 1616 fname))
@@ -1699,51 +1679,6 @@ rather than user editing!"
1699 (let ((buffer (get-file-buffer file))) 1679 (let ((buffer (get-file-buffer file)))
1700 (vc-dir-mark-buffer-changed file)))) 1680 (vc-dir-mark-buffer-changed file))))
1701 1681
1702
1703(defun vc-start-entry (files rev comment initial-contents msg action &optional after-hook)
1704 "Accept a comment for an operation on FILES revision REV.
1705If COMMENT is nil, pop up a VC-log buffer, emit MSG, and set the
1706action on close to ACTION. If COMMENT is a string and
1707INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial
1708contents of the log entry buffer. If COMMENT is a string and
1709INITIAL-CONTENTS is nil, do action immediately as if the user had
1710entered COMMENT. If COMMENT is t, also do action immediately with an
1711empty comment. Remember the file's buffer in `vc-parent-buffer'
1712\(current one if no file). AFTER-HOOK specifies the local value
1713for `vc-log-after-operation-hook'."
1714 (let ((parent
1715 (if (or (eq major-mode 'vc-dired-mode) (eq major-mode 'vc-dir-mode))
1716 ;; If we are called from VC dired, the parent buffer is
1717 ;; the current buffer.
1718 (current-buffer)
1719 (if (and files (equal (length files) 1))
1720 (get-file-buffer (car files))
1721 (current-buffer)))))
1722 (when vc-before-checkin-hook
1723 (if files
1724 (with-current-buffer parent
1725 (run-hooks 'vc-before-checkin-hook))
1726 (run-hooks 'vc-before-checkin-hook)))
1727 (if (and comment (not initial-contents))
1728 (set-buffer (get-buffer-create "*VC-log*"))
1729 (pop-to-buffer (get-buffer-create "*VC-log*")))
1730 (set (make-local-variable 'vc-parent-buffer) parent)
1731 (set (make-local-variable 'vc-parent-buffer-name)
1732 (concat " from " (buffer-name vc-parent-buffer)))
1733 ;;(if file (vc-mode-line file))
1734 (vc-log-edit files)
1735 (make-local-variable 'vc-log-after-operation-hook)
1736 (when after-hook
1737 (setq vc-log-after-operation-hook after-hook))
1738 (setq vc-log-operation action)
1739 (setq vc-log-revision rev)
1740 (when comment
1741 (erase-buffer)
1742 (when (stringp comment) (insert comment)))
1743 (if (or (not comment) initial-contents)
1744 (message "%s Type C-c C-c when done" msg)
1745 (vc-finish-logentry (eq comment t)))))
1746
1747(defun vc-checkout (file &optional writable rev) 1682(defun vc-checkout (file &optional writable rev)
1748 "Retrieve a copy of the revision REV of FILE. 1683 "Retrieve a copy of the revision REV of FILE.
1749If WRITABLE is non-nil, make sure the retrieved file is writable. 1684If WRITABLE is non-nil, make sure the retrieved file is writable.
@@ -1821,7 +1756,7 @@ If `vc-keep-workfiles' is nil, FILE is deleted afterwards, provided
1821that the version control system supports this mode of operation. 1756that the version control system supports this mode of operation.
1822 1757
1823Runs the normal hook `vc-checkin-hook'." 1758Runs the normal hook `vc-checkin-hook'."
1824 (vc-start-entry 1759 (vc-start-logentry
1825 files rev comment initial-contents 1760 files rev comment initial-contents
1826 "Enter a change comment." 1761 "Enter a change comment."
1827 (lambda (files rev comment) 1762 (lambda (files rev comment)
@@ -2214,7 +2149,7 @@ The headers are reset to their non-expanded form."
2214 2149
2215(defun vc-modify-change-comment (files rev oldcomment) 2150(defun vc-modify-change-comment (files rev oldcomment)
2216 "Edit the comment associated with the given files and revision." 2151 "Edit the comment associated with the given files and revision."
2217 (vc-start-entry 2152 (vc-start-logentry
2218 files rev oldcomment t 2153 files rev oldcomment t
2219 "Enter a replacement change comment." 2154 "Enter a replacement change comment."
2220 (lambda (files rev comment) 2155 (lambda (files rev comment)