289 |
;; (no differences found), or 1 (either non-empty diff or the diff is |
;; (no differences found), or 1 (either non-empty diff or the diff is |
290 |
;; run asynchronously). |
;; run asynchronously). |
291 |
;; |
;; |
292 |
|
;; - diff-tree (dir &optional rev1 rev2) |
293 |
|
;; |
294 |
|
;; Insert the diff for all files at and below DIR into the *vc-diff* |
295 |
|
;; buffer. The meaning of REV1 and REV2 is the same as for |
296 |
|
;; vc-BACKEND-diff. The default implementation does an explicit tree |
297 |
|
;; walk, calling vc-BACKEND-diff for each individual file. |
298 |
|
;; |
299 |
;; - annotate-command (file buf rev) |
;; - annotate-command (file buf rev) |
300 |
;; |
;; |
301 |
;; If this function is provided, it should produce an annotated version |
;; If this function is provided, it should produce an annotated version |
1691 |
With a prefix argument, it reads the file name to use |
With a prefix argument, it reads the file name to use |
1692 |
and two version designators specifying which versions to compare." |
and two version designators specifying which versions to compare." |
1693 |
(interactive (list current-prefix-arg t)) |
(interactive (list current-prefix-arg t)) |
|
(vc-ensure-vc-buffer) |
|
1694 |
(if historic |
(if historic |
1695 |
(call-interactively 'vc-version-diff) |
(call-interactively 'vc-version-diff) |
1696 |
|
(vc-ensure-vc-buffer) |
1697 |
(let ((file buffer-file-name)) |
(let ((file buffer-file-name)) |
1698 |
(vc-buffer-sync not-urgent) |
(vc-buffer-sync not-urgent) |
1699 |
(if (vc-workfile-unchanged-p buffer-file-name) |
(if (vc-workfile-unchanged-p buffer-file-name) |
1748 |
" and " |
" and " |
1749 |
(or rel2 "current workfile(s)") |
(or rel2 "current workfile(s)") |
1750 |
":\n\n")) |
":\n\n")) |
1751 |
(setq default-directory (file-name-as-directory file)) |
(let ((dir (file-name-as-directory file))) |
1752 |
;; FIXME: this should do a single exec in CVS. |
(vc-call-backend (vc-responsible-backend dir) |
1753 |
(vc-file-tree-walk |
'diff-tree dir rel1 rel2)) |
|
default-directory |
|
|
(lambda (f) |
|
|
(vc-exec-after |
|
|
`(progn |
|
|
(message "Looking at %s" ',f) |
|
|
(vc-call-backend ',(vc-backend file) 'diff ',f ',rel1 ',rel2))))) |
|
1754 |
(vc-exec-after `(let ((inhibit-read-only t)) |
(vc-exec-after `(let ((inhibit-read-only t)) |
1755 |
(insert "\nEnd of diffs.\n")))) |
(insert "\nEnd of diffs.\n")))) |
1756 |
;; single file diff |
;; single file diff |
1757 |
(if (or (not rel1) (string-equal rel1 "")) |
(vc-diff-internal file rel1 rel2)) |
|
(setq rel1 (vc-workfile-version file))) |
|
|
(if (string-equal rel2 "") |
|
|
(setq rel2 nil)) |
|
|
(let ((file-rel1 (vc-version-backup-file file rel1)) |
|
|
(file-rel2 (if (not rel2) |
|
|
file |
|
|
(vc-version-backup-file file rel2)))) |
|
|
(if (and file-rel1 file-rel2) |
|
|
(apply 'vc-do-command "*vc-diff*" 1 "diff" nil |
|
|
(append (if (listp diff-switches) |
|
|
diff-switches |
|
|
(list diff-switches)) |
|
|
(if (listp vc-diff-switches) |
|
|
vc-diff-switches |
|
|
(list vc-diff-switches)) |
|
|
(list (file-relative-name file-rel1) |
|
|
(file-relative-name file-rel2)))) |
|
|
(vc-call diff file rel1 rel2)))) |
|
1758 |
(set-buffer "*vc-diff*") |
(set-buffer "*vc-diff*") |
1759 |
(if (and (zerop (buffer-size)) |
(if (and (zerop (buffer-size)) |
1760 |
(not (get-buffer-process (current-buffer)))) |
(not (get-buffer-process (current-buffer)))) |
1776 |
(shrink-window-if-larger-than-buffer))) |
(shrink-window-if-larger-than-buffer))) |
1777 |
t)) |
t)) |
1778 |
|
|
1779 |
|
(defun vc-diff-internal (file rel1 rel2) |
1780 |
|
"Run diff to compare FILE's revisions REL1 and REL2. |
1781 |
|
Output goes to the current buffer, which is assumed properly set up. |
1782 |
|
The exit status of the diff command is returned. |
1783 |
|
|
1784 |
|
This function takes care to set up a proper coding system for diff output. |
1785 |
|
If both revisions are available as local files, then it also does not |
1786 |
|
actually call the backend, but performs a local diff." |
1787 |
|
(if (or (not rel1) (string-equal rel1 "")) |
1788 |
|
(setq rel1 (vc-workfile-version file))) |
1789 |
|
(if (string-equal rel2 "") |
1790 |
|
(setq rel2 nil)) |
1791 |
|
(let ((file-rel1 (vc-version-backup-file file rel1)) |
1792 |
|
(file-rel2 (if (not rel2) |
1793 |
|
file |
1794 |
|
(vc-version-backup-file file rel2))) |
1795 |
|
(coding-system-for-read (vc-coding-system-for-diff file))) |
1796 |
|
(if (and file-rel1 file-rel2) |
1797 |
|
(apply 'vc-do-command "*vc-diff*" 1 "diff" nil |
1798 |
|
(append (if (listp diff-switches) |
1799 |
|
diff-switches |
1800 |
|
(list diff-switches)) |
1801 |
|
(if (listp vc-diff-switches) |
1802 |
|
vc-diff-switches |
1803 |
|
(list vc-diff-switches)) |
1804 |
|
(list (file-relative-name file-rel1) |
1805 |
|
(file-relative-name file-rel2)))) |
1806 |
|
(vc-call diff file rel1 rel2)))) |
1807 |
|
|
1808 |
(defmacro vc-diff-switches-list (backend) |
(defmacro vc-diff-switches-list (backend) |
1809 |
"Make a list of `diff-switches', `vc-diff-switches', |
"Make a list of `diff-switches', `vc-diff-switches', |
1810 |
and `vc-BACKEND-diff-switches'." |
and `vc-BACKEND-diff-switches'." |
1816 |
"-diff-switches"))))) |
"-diff-switches"))))) |
1817 |
(if (listp backend-switches) backend-switches (list backend-switches))))) |
(if (listp backend-switches) backend-switches (list backend-switches))))) |
1818 |
|
|
1819 |
|
(defun vc-default-diff-tree (backend dir rel1 rel2) |
1820 |
|
"Default implementation for diffing an entire tree at and below DIR. |
1821 |
|
The meaning of REL1 and REL2 is the same as for `vc-version-diff'." |
1822 |
|
;; This implementation does an explicit tree walk, and calls |
1823 |
|
;; vc-BACKEND-diff directly for each file. An optimization |
1824 |
|
;; would be to use `vc-diff-internal', so that diffs can be local, |
1825 |
|
;; and to call it only for files that are actually changed. |
1826 |
|
;; However, this is expensive for some backends, and so it is left |
1827 |
|
;; to backend-specific implementations. |
1828 |
|
(setq default-directory dir) |
1829 |
|
(vc-file-tree-walk |
1830 |
|
default-directory |
1831 |
|
(lambda (f) |
1832 |
|
(vc-exec-after |
1833 |
|
`(let ((coding-system-for-read (vc-coding-system-for-diff ',f))) |
1834 |
|
(message "Looking at %s" ',f) |
1835 |
|
(vc-call-backend ',(vc-backend f) |
1836 |
|
'diff ',f ',rel1 ',rel2)))))) |
1837 |
|
|
1838 |
|
(defun vc-coding-system-for-diff (file) |
1839 |
|
"Return the coding system for reading diff output for FILE." |
1840 |
|
(or coding-system-for-read |
1841 |
|
;; if we already have this file open, |
1842 |
|
;; use the buffer's coding system |
1843 |
|
(let ((buf (find-buffer-visiting file))) |
1844 |
|
(if buf (with-current-buffer buf |
1845 |
|
buffer-file-coding-system))) |
1846 |
|
;; otherwise, try to find one based on the file name |
1847 |
|
(car (find-operation-coding-system 'insert-file-contents |
1848 |
|
file)) |
1849 |
|
;; and a final fallback |
1850 |
|
'undecided)) |
1851 |
|
|
1852 |
;;;###autoload |
;;;###autoload |
1853 |
(defun vc-version-other-window (rev) |
(defun vc-version-other-window (rev) |
1854 |
"Visit version REV of the current buffer in another window. |
"Visit version REV of the current buffer in another window. |