Mercurial > emacs
annotate lisp/net/tramp-vc.el @ 57250:abcdda14b5d8
*** empty log message ***
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Mon, 27 Sep 2004 22:45:14 +0000 |
parents | 9459300bf43b |
children | b324ca4df07c b9eee0a7bef5 |
rev | line source |
---|---|
45861 | 1 ;;; tramp-vc.el --- Version control integration for TRAMP.el |
2 | |
55420
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004 by Free Software Foundation, Inc. |
45861 | 4 |
5 ;; Author: Daniel Pittman <daniel@danann.net> | |
6 ;; Keywords: comm, processes | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; See the main module, 'tramp.el' for discussion of the purpose of TRAMP. | |
28 ;; This module provides integration between remote files accessed by TRAMP and | |
29 ;; the Emacs version control system. | |
30 | |
31 ;;; Code: | |
32 | |
33 (eval-when-compile | |
34 (require 'cl)) | |
35 (require 'vc) | |
36 ;; Old VC defines vc-rcs-release in vc.el, new VC requires extra module. | |
37 (unless (boundp 'vc-rcs-release) | |
38 (require 'vc-rcs)) | |
39 (require 'tramp) | |
40 | |
55420
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
41 ;; Avoid byte-compiler warnings if the byte-compiler supports this. |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
42 ;; Currently, XEmacs supports this. |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
43 (eval-when-compile |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
44 (when (fboundp 'byte-compiler-options) |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
45 (let (unused-vars) ; Pacify Emacs byte-compiler |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
46 (defalias 'warnings 'identity) ; Pacify Emacs byte-compiler |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
47 (byte-compiler-options (warnings (- unused-vars)))))) |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
48 |
45861 | 49 ;; -- vc -- |
50 | |
51 ;; This used to blow away the file-name-handler-alist and reinstall | |
52 ;; TRAMP into it. This was intended to let VC work remotely. It didn't, | |
53 ;; at least not in my XEmacs 21.2 install. | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
54 ;; |
45861 | 55 ;; In any case, tramp-run-real-handler now deals correctly with disabling |
56 ;; the things that should be, making this a no-op. | |
57 ;; | |
58 ;; I have removed it from the tramp-file-name-handler-alist because the | |
59 ;; shortened version does nothing. This is for reference only now. | |
60 ;; | |
61 ;; Daniel Pittman <daniel@danann.net> | |
62 ;; | |
63 ;; (defun tramp-handle-vc-registered (file) | |
64 ;; "Like `vc-registered' for tramp files." | |
65 ;; (tramp-run-real-handler 'vc-registered (list file))) | |
66 | |
67 ;; `vc-do-command' | |
68 ;; This function does not deal well with remote files, so we define | |
69 ;; our own version and make a backup of the original function and | |
70 ;; call our version for tramp files and the original version for | |
71 ;; normal files. | |
72 | |
73 ;; The following function is pretty much copied from vc.el, but | |
74 ;; the part that actually executes a command is changed. | |
75 ;; CCC: this probably works for Emacs 21, too. | |
76 (defun tramp-vc-do-command (buffer okstatus command file last &rest flags) | |
77 "Like `vc-do-command' but invoked for tramp files. | |
78 See `vc-do-command' for more information." | |
79 (save-match-data | |
56460
9459300bf43b
Sync with Tramp 2.0.43.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
55420
diff
changeset
|
80 (and file (setq file (expand-file-name file))) |
45861 | 81 (if (not buffer) (setq buffer "*vc*")) |
82 (if vc-command-messages | |
83 (message "Running `%s' on `%s'..." command file)) | |
84 (let ((obuf (current-buffer)) (camefrom (current-buffer)) | |
85 (squeezed nil) | |
86 (olddir default-directory) | |
87 vc-file status) | |
56460
9459300bf43b
Sync with Tramp 2.0.43.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
55420
diff
changeset
|
88 (let* ((v (tramp-dissect-file-name (expand-file-name file))) |
45861 | 89 (multi-method (tramp-file-name-multi-method v)) |
90 (method (tramp-file-name-method v)) | |
91 (user (tramp-file-name-user v)) | |
92 (host (tramp-file-name-host v)) | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
93 (localname (tramp-file-name-localname v))) |
45861 | 94 (set-buffer (get-buffer-create buffer)) |
95 (set (make-local-variable 'vc-parent-buffer) camefrom) | |
96 (set (make-local-variable 'vc-parent-buffer-name) | |
97 (concat " from " (buffer-name camefrom))) | |
98 (setq default-directory olddir) | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
99 |
45861 | 100 (erase-buffer) |
101 | |
102 (mapcar | |
103 (function | |
104 (lambda (s) (and s (setq squeezed (append squeezed (list s)))))) | |
105 flags) | |
106 (if (and (eq last 'MASTER) file | |
107 (setq vc-file (vc-name file))) | |
108 (setq squeezed | |
109 (append squeezed | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
110 (list (tramp-file-name-localname |
45861 | 111 (tramp-dissect-file-name vc-file)))))) |
112 (if (and file (eq last 'WORKFILE)) | |
113 (progn | |
114 (let* ((pwd (expand-file-name default-directory)) | |
115 (preflen (length pwd))) | |
116 (if (string= (substring file 0 preflen) pwd) | |
117 (setq file (substring file preflen)))) | |
118 (setq squeezed (append squeezed (list file))))) | |
119 ;; Unless we (save-window-excursion) the layout of windows in | |
120 ;; the current frame changes. This is painful, at best. | |
121 ;; | |
122 ;; As a point of note, (save-excursion) is still here only because | |
123 ;; it preserves (point) in the current buffer. (save-window-excursion) | |
124 ;; does not, at least under XEmacs 21.2. | |
125 ;; | |
126 ;; I trust that the FSF support this as well. I can't find useful | |
127 ;; documentation to check :( | |
128 ;; | |
129 ;; Daniel Pittman <daniel@danann.net> | |
130 (save-excursion | |
131 (save-window-excursion | |
132 ;; Actually execute remote command | |
56460
9459300bf43b
Sync with Tramp 2.0.43.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
55420
diff
changeset
|
133 (shell-command |
45861 | 134 (mapconcat 'tramp-shell-quote-argument |
135 (cons command squeezed) " ") t) | |
136 ;;(tramp-wait-for-output) | |
137 ;; Get status from command | |
138 (tramp-send-command multi-method method user host "echo $?") | |
139 (tramp-wait-for-output) | |
140 ;; Make sure to get status from last line of output. | |
141 (goto-char (point-max)) (forward-line -1) | |
142 (setq status (read (current-buffer))) | |
143 (message "Command %s returned status %d." command status))) | |
144 (goto-char (point-max)) | |
145 (set-buffer-modified-p nil) | |
146 (forward-line -1) | |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
45861
diff
changeset
|
147 (if (or (not (integerp status)) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
45861
diff
changeset
|
148 (and (integerp okstatus) (< okstatus status))) |
45861 | 149 (progn |
150 (pop-to-buffer buffer) | |
151 (goto-char (point-min)) | |
152 (shrink-window-if-larger-than-buffer) | |
153 (error "Running `%s'...FAILED (%s)" command | |
154 (if (integerp status) | |
155 (format "status %d" status) | |
156 status)) | |
157 ) | |
158 (if vc-command-messages | |
159 (message "Running %s...OK" command)) | |
160 ) | |
161 (set-buffer obuf) | |
162 status)) | |
163 )) | |
164 | |
165 ;; Following code snarfed from Emacs 21 vc.el and slightly tweaked. | |
166 (defun tramp-vc-do-command-new (buffer okstatus command file &rest flags) | |
167 "Like `vc-do-command' but for TRAMP files. | |
168 This function is for the new VC which comes with Emacs 21. | |
169 Since TRAMP doesn't do async commands yet, this function doesn't, either." | |
170 (and file (setq file (expand-file-name file))) | |
171 (if vc-command-messages | |
172 (message "Running %s on %s..." command file)) | |
173 (save-current-buffer | |
55420
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
174 (unless (eq buffer t) |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
175 ; Pacify byte-compiler |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
176 (funcall (symbol-function 'vc-setup-buffer) buffer)) |
45861 | 177 (let ((squeezed nil) |
178 (inhibit-read-only t) | |
179 (status 0)) | |
180 (let* ((v (when file (tramp-dissect-file-name file))) | |
181 (multi-method (when file (tramp-file-name-multi-method v))) | |
182 (method (when file (tramp-file-name-method v))) | |
183 (user (when file (tramp-file-name-user v))) | |
184 (host (when file (tramp-file-name-host v))) | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
185 (localname (when file (tramp-file-name-localname v)))) |
45861 | 186 (setq squeezed (delq nil (copy-sequence flags))) |
187 (when file | |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
45861
diff
changeset
|
188 (setq squeezed (append squeezed (list (file-relative-name |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
45861
diff
changeset
|
189 file default-directory))))) |
45861 | 190 (let ((w32-quote-process-args t)) |
191 (when (eq okstatus 'async) | |
192 (message "Tramp doesn't do async commands, running synchronously.")) | |
56460
9459300bf43b
Sync with Tramp 2.0.43.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
55420
diff
changeset
|
193 (setq status (shell-command |
45861 | 194 (mapconcat 'tramp-shell-quote-argument |
195 (cons command squeezed) " ") t)) | |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
45861
diff
changeset
|
196 (when (or (not (integerp status)) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
45861
diff
changeset
|
197 (and (integerp okstatus) (< okstatus status))) |
45861 | 198 (pop-to-buffer (current-buffer)) |
199 (goto-char (point-min)) | |
200 (shrink-window-if-larger-than-buffer) | |
201 (error "Running %s...FAILED (%s)" command | |
202 (if (integerp status) (format "status %d" status) status)))) | |
203 (if vc-command-messages | |
204 (message "Running %s...OK" command)) | |
55420
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
205 ; Pacify byte-compiler |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
206 (funcall (symbol-function 'vc-exec-after) |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
207 `(run-hook-with-args |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
208 'vc-post-command-functions ',command ',localname ',flags)) |
45861 | 209 status)))) |
210 | |
211 | |
212 ;; The context for a VC command is the current buffer. | |
213 ;; That makes a test on the buffers file more reliable than a test on the | |
214 ;; arguments. | |
215 ;; This is needed to handle remote VC correctly - else we test against the | |
216 ;; local VC system and get things wrong... | |
217 ;; Daniel Pittman <daniel@danann.net> | |
218 ;;-(if (fboundp 'vc-call-backend) | |
219 ;;- () ;; This is the new VC for which we don't have an appropriate advice yet | |
220 (if (fboundp 'vc-call-backend) | |
221 (defadvice vc-do-command | |
222 (around tramp-advice-vc-do-command | |
223 (buffer okstatus command file &rest flags) | |
224 activate) | |
225 "Invoke tramp-vc-do-command for tramp files." | |
226 (let ((file (symbol-value 'file))) ;pacify byte-compiler | |
227 (if (or (and (stringp file) (tramp-tramp-file-p file)) | |
228 (and (buffer-file-name) (tramp-tramp-file-p (buffer-file-name)))) | |
229 (setq ad-return-value | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
230 (apply 'tramp-vc-do-command-new buffer okstatus command |
45861 | 231 file ;(or file (buffer-file-name)) |
232 flags)) | |
233 ad-do-it))) | |
234 (defadvice vc-do-command | |
235 (around tramp-advice-vc-do-command | |
236 (buffer okstatus command file last &rest flags) | |
237 activate) | |
238 "Invoke tramp-vc-do-command for tramp files." | |
239 (let ((file (symbol-value 'file))) ;pacify byte-compiler | |
240 (if (or (and (stringp file) (tramp-tramp-file-p file)) | |
241 (and (buffer-file-name) (tramp-tramp-file-p (buffer-file-name)))) | |
242 (setq ad-return-value | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
243 (apply 'tramp-vc-do-command buffer okstatus command |
45861 | 244 (or file (buffer-file-name)) last flags)) |
245 ad-do-it)))) | |
246 ;;-) | |
247 | |
248 | |
249 ;; XEmacs uses this to do some of its work. Like vc-do-command, we | |
250 ;; need to enhance it to make VC work via TRAMP-mode. | |
251 ;; | |
252 ;; Like the previous function, this is a cut-and-paste job from the VC | |
253 ;; file. It's based on the vc-do-command code. | |
254 ;; CCC: this isn't used in Emacs 21, so do as before. | |
255 (defun tramp-vc-simple-command (okstatus command file &rest args) | |
256 ;; Simple version of vc-do-command, for use in vc-hooks only. | |
257 ;; Don't switch to the *vc-info* buffer before running the | |
258 ;; command, because that would change its default directory | |
259 (save-match-data | |
56460
9459300bf43b
Sync with Tramp 2.0.43.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
55420
diff
changeset
|
260 (let* ((v (tramp-dissect-file-name (expand-file-name file))) |
45861 | 261 (multi-method (tramp-file-name-multi-method v)) |
262 (method (tramp-file-name-method v)) | |
263 (user (tramp-file-name-user v)) | |
264 (host (tramp-file-name-host v)) | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
265 (localname (tramp-file-name-localname v))) |
45861 | 266 (save-excursion (set-buffer (get-buffer-create "*vc-info*")) |
267 (erase-buffer)) | |
268 (let ((exec-path (append vc-path exec-path)) exec-status | |
269 ;; Add vc-path to PATH for the execution of this command. | |
270 (process-environment | |
271 (cons (concat "PATH=" (getenv "PATH") | |
272 path-separator | |
273 (mapconcat 'identity vc-path path-separator)) | |
274 process-environment))) | |
275 ;; Call the actual process. See tramp-vc-do-command for discussion of | |
276 ;; why this does both (save-window-excursion) and (save-excursion). | |
277 ;; | |
278 ;; As a note, I don't think that the process-environment stuff above | |
279 ;; has any effect on the remote system. This is a hard one though as | |
280 ;; there is no real reason to expect local and remote paths to be | |
281 ;; identical... | |
282 ;; | |
283 ;; Daniel Pittman <daniel@danann.net> | |
284 (save-excursion | |
285 (save-window-excursion | |
286 ;; Actually execute remote command | |
56460
9459300bf43b
Sync with Tramp 2.0.43.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
55420
diff
changeset
|
287 (shell-command |
45861 | 288 (mapconcat 'tramp-shell-quote-argument |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
289 (append (list command) args (list localname)) " ") |
45861 | 290 (get-buffer-create"*vc-info*")) |
291 ;(tramp-wait-for-output) | |
292 ;; Get status from command | |
293 (tramp-send-command multi-method method user host "echo $?") | |
294 (tramp-wait-for-output) | |
295 (setq exec-status (read (current-buffer))) | |
296 (message "Command %s returned status %d." command exec-status))) | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
297 |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
45861
diff
changeset
|
298 ;; Maybe okstatus can be `async' here. But then, maybe the |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
45861
diff
changeset
|
299 ;; async thing is new in Emacs 21, but this function is only |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
45861
diff
changeset
|
300 ;; used in Emacs 20. |
45861 | 301 (cond ((> exec-status okstatus) |
302 (switch-to-buffer (get-file-buffer file)) | |
303 (shrink-window-if-larger-than-buffer | |
304 (display-buffer "*vc-info*")) | |
305 (error "Couldn't find version control information"))) | |
306 exec-status)))) | |
307 | |
308 ;; This function does not exist any more in Emacs-21's VC | |
309 (defadvice vc-simple-command | |
310 (around tramp-advice-vc-simple-command | |
311 (okstatus command file &rest args) | |
312 activate) | |
313 "Invoke tramp-vc-simple-command for tramp files." | |
314 (let ((file (symbol-value 'file))) ;pacify byte-compiler | |
315 (if (or (and (stringp file) (tramp-tramp-file-p file)) | |
316 (and (buffer-file-name) (tramp-tramp-file-p (buffer-file-name)))) | |
317 (setq ad-return-value | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
318 (apply 'tramp-vc-simple-command okstatus command |
45861 | 319 (or file (buffer-file-name)) args)) |
320 ad-do-it))) | |
321 | |
322 | |
323 ;; `vc-workfile-unchanged-p' | |
324 ;; This function does not deal well with remote files, so we do the | |
325 ;; same as for `vc-do-command'. | |
326 | |
327 ;; `vc-workfile-unchanged-p' checks the modification time, we cannot | |
328 ;; do that for remote files, so here's a version which relies on diff. | |
329 ;; CCC: this one probably works for Emacs 21, too. | |
330 (defun tramp-vc-workfile-unchanged-p | |
331 (filename &optional want-differences-if-changed) | |
332 (if (fboundp 'vc-backend-diff) | |
333 ;; Old VC. Call `vc-backend-diff'. | |
334 (let ((status (funcall (symbol-function 'vc-backend-diff) | |
335 filename nil nil | |
336 (not want-differences-if-changed)))) | |
337 (zerop status)) | |
338 ;; New VC. Call `vc-default-workfile-unchanged-p'. | |
55420
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
339 (funcall (symbol-function 'vc-default-workfile-unchanged-p) |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
340 (vc-backend filename) filename))) |
45861 | 341 |
342 (defadvice vc-workfile-unchanged-p | |
343 (around tramp-advice-vc-workfile-unchanged-p | |
344 (filename &optional want-differences-if-changed) | |
345 activate) | |
346 "Invoke tramp-vc-workfile-unchanged-p for tramp files." | |
347 (if (and (stringp filename) | |
348 (tramp-tramp-file-p filename) | |
349 (not | |
350 (let ((v (tramp-dissect-file-name filename))) | |
51968
e4c4c45ea013
Tramp 2.0.36 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49995
diff
changeset
|
351 ;; The following check is probably to test whether |
e4c4c45ea013
Tramp 2.0.36 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49995
diff
changeset
|
352 ;; file-attributes returns correct last modification |
e4c4c45ea013
Tramp 2.0.36 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49995
diff
changeset
|
353 ;; times. This check needs to be changed. |
45861 | 354 (tramp-get-remote-perl (tramp-file-name-multi-method v) |
355 (tramp-file-name-method v) | |
356 (tramp-file-name-user v) | |
357 (tramp-file-name-host v))))) | |
358 (setq ad-return-value | |
359 (tramp-vc-workfile-unchanged-p filename want-differences-if-changed)) | |
360 ad-do-it)) | |
361 | |
362 | |
363 ;; Redefine a function from vc.el -- allow tramp files. | |
364 ;; `save-match-data' seems not to be required -- it isn't in | |
365 ;; the original version, either. | |
366 ;; CCC: this might need some work -- how does the Emacs 21 version | |
367 ;; work, anyway? Does it work over ange-ftp? Hm. | |
368 (if (not (fboundp 'vc-backend-checkout)) | |
369 () ;; our replacement won't work and is unnecessary anyway | |
370 (defun vc-checkout (filename &optional writable rev) | |
371 "Retrieve a copy of the latest version of the given file." | |
372 ;; If ftp is on this system and the name matches the ange-ftp format | |
373 ;; for a remote file, the user is trying something that won't work. | |
374 (funcall (symbol-function 'vc-backend-checkout) filename writable rev) | |
375 (vc-resynch-buffer filename t t)) | |
376 ) | |
377 | |
378 | |
379 ;; Do we need to advise the vc-user-login-name function anyway? | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
380 ;; This will return the correct login name for the owner of a |
45861 | 381 ;; file. It does not deal with the default remote user name... |
382 ;; | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
383 ;; That is, when vc calls (vc-user-login-name), we return the |
45861 | 384 ;; local login name, something that may be different to the remote |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
385 ;; default. |
45861 | 386 ;; |
387 ;; The remote VC operations will occur as the user that we logged | |
388 ;; in with however - not always the same as the local user. | |
389 ;; | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
390 ;; In the end, I did advise the function. This is because, well, |
45861 | 391 ;; the thing didn't work right otherwise ;) |
392 ;; | |
393 ;; Daniel Pittman <daniel@danann.net> | |
394 | |
395 (defun tramp-handle-vc-user-login-name (&optional uid) | |
396 "Return the default user name on the remote machine. | |
397 Whenever VC calls this function, `file' is bound to the file name | |
398 in question. If no uid is provided or the uid is equal to the uid | |
399 owning the file, then we return the user name given in the file name. | |
400 | |
401 This should only be called when `file' is bound to the | |
402 filename we are thinking about..." | |
403 ;; Pacify byte-compiler; this symbol is bound in the calling | |
404 ;; function. CCC: Maybe it would be better to move the | |
405 ;; boundness-checking into this function? | |
55420
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
406 (let* ((file (symbol-value 'file)) |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
407 (remote-uid |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
408 ;; With Emacs 21.4, `file-attributes' has got an optional parameter |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
409 ;; ID-FORMAT. Handle this case backwards compatible. |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
410 (if (and (functionp 'subr-arity) |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
411 (= 2 (cdr (funcall (symbol-function 'subr-arity) |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
412 (symbol-function 'file-attributes))))) |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
413 (nth 2 (file-attributes file 'integer)) |
c44f9de543e3
2004-05-07 Kai Grossjohann <kai@emptydomain.de>
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
53206
diff
changeset
|
414 (nth 2 (file-attributes file))))) |
53206
0c19f1a19b2b
(tramp-chunksize): Extend docstring. Suggested by
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
52401
diff
changeset
|
415 (if (and uid (/= uid remote-uid)) |
45861 | 416 (error "tramp-handle-vc-user-login-name cannot map a uid to a name") |
56460
9459300bf43b
Sync with Tramp 2.0.43.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
55420
diff
changeset
|
417 (let* ((v (tramp-dissect-file-name (expand-file-name file))) |
45861 | 418 (u (tramp-file-name-user v))) |
419 (cond ((stringp u) u) | |
420 ((vectorp u) (elt u (1- (length u)))) | |
421 ((null u) (user-login-name)) | |
422 (t (error "tramp-handle-vc-user-login-name cannot cope!"))))))) | |
423 | |
424 | |
425 (defadvice vc-user-login-name | |
426 (around tramp-vc-user-login-name activate) | |
427 "Support for files on remote machines accessed by TRAMP." | |
428 ;; We rely on the fact that `file' is bound when this is called. | |
429 ;; This appears to be the case everywhere in vc.el and vc-hooks.el | |
430 ;; as of Emacs 20.5. | |
431 ;; | |
432 ;; CCC TODO there should be a real solution! Talk to Andre Spiegel | |
433 ;; about this. | |
434 (let ((file (when (boundp 'file) | |
435 (symbol-value 'file)))) ;pacify byte-compiler | |
436 (or (and (stringp file) | |
437 (tramp-tramp-file-p file) ; tramp file | |
438 (setq ad-return-value | |
439 (save-match-data | |
440 (tramp-handle-vc-user-login-name uid)))) ; get the owner name | |
441 ad-do-it))) ; else call the original | |
442 | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
443 |
45861 | 444 ;; Determine the name of the user owning a file. |
445 (defun tramp-file-owner (filename) | |
446 "Return who owns FILE (user name, as a string)." | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
447 (let ((v (tramp-dissect-file-name |
56460
9459300bf43b
Sync with Tramp 2.0.43.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
55420
diff
changeset
|
448 (expand-file-name filename)))) |
9459300bf43b
Sync with Tramp 2.0.43.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
55420
diff
changeset
|
449 (if (not (file-exists-p filename)) |
45861 | 450 nil ; file cannot be opened |
451 ;; file exists, find out stuff | |
452 (save-excursion | |
453 (tramp-send-command | |
454 (tramp-file-name-multi-method v) (tramp-file-name-method v) | |
455 (tramp-file-name-user v) (tramp-file-name-host v) | |
456 (format "%s -Lld %s" | |
457 (tramp-get-ls-command (tramp-file-name-multi-method v) | |
458 (tramp-file-name-method v) | |
459 (tramp-file-name-user v) | |
460 (tramp-file-name-host v)) | |
49995
a0e8a85259ed
Version 2.0.30 released.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49598
diff
changeset
|
461 (tramp-shell-quote-argument (tramp-file-name-localname v)))) |
45861 | 462 (tramp-wait-for-output) |
463 ;; parse `ls -l' output ... | |
464 ;; ... file mode flags | |
465 (read (current-buffer)) | |
466 ;; ... number links | |
467 (read (current-buffer)) | |
468 ;; ... uid (as a string) | |
469 (symbol-name (read (current-buffer))))))) | |
470 | |
471 ;; Wire ourselves into the VC infrastructure... | |
472 ;; This function does not exist any more in Emacs-21's VC | |
473 ;; CCC: it appears that no substitute is needed for Emacs 21. | |
474 (defadvice vc-file-owner | |
475 (around tramp-vc-file-owner activate) | |
476 "Support for files on remote machines accessed by TRAMP." | |
477 (let ((filename (ad-get-arg 0))) | |
478 (or (and (tramp-file-name-p filename) ; tramp file | |
479 (setq ad-return-value | |
480 (save-match-data | |
481 (tramp-file-owner filename)))) ; get the owner name | |
482 ad-do-it))) ; else call the original | |
483 | |
484 | |
485 ;; We need to make the version control software backend version | |
486 ;; information local to the current buffer. This is because each TRAMP | |
487 ;; buffer can (theoretically) have a different VC version and I am | |
488 ;; *way* too lazy to try and push the correct value into each new | |
489 ;; buffer. | |
490 ;; | |
491 ;; Remote VC costs will just have to be paid, at least for the moment. | |
492 ;; Well, at least, they will right until I feel guilty about doing a | |
493 ;; botch job here and fix it. :/ | |
494 ;; | |
495 ;; Daniel Pittman <daniel@danann.net> | |
496 ;; CCC: this is probably still needed for Emacs 21. | |
497 (defun tramp-vc-setup-for-remote () | |
498 "Make the backend release variables buffer local. | |
499 This makes remote VC work correctly at the cost of some processing time." | |
500 (when (and (buffer-file-name) | |
501 (tramp-tramp-file-p (buffer-file-name))) | |
502 (make-local-variable 'vc-rcs-release) | |
503 (setq vc-rcs-release nil))) | |
504 (add-hook 'find-file-hooks 'tramp-vc-setup-for-remote t) | |
505 | |
506 ;; No need to load this again if anyone asks. | |
507 (provide 'tramp-vc) | |
508 | |
52401 | 509 ;;; arch-tag: 27cc42ce-da19-468d-ad5c-a2690558db60 |
45861 | 510 ;;; tramp-vc.el ends here |