contrib/emacs/vc-git.el: support vc-version-other-window
Currently, the vc-git-checkout function uses `git checkout' to fetch a file from the git repository to the working copy. However, it is completely ignoring the input argument that specifies the destination file. `git-checkout' does not support specifying this, so we have to use `git-cat-file', capture the output in a buffer and then save it. Signed-off-by: Junio C Hamano <junkio@cox.net>
Sam Vilain committed
Jan 26, 2007 at 12:41 UTC
fd73423f01361f112dbb9972ebce8eabae7dd8b1
1 file changed
+26
-1
contrib/emacs/vc-git.el
+26
-1
@@ -53,6 +53,10 @@
53
(let ((name (file-relative-name file)))
54
(eq 0 (apply #'call-process "git" nil (get-buffer "*Messages") nil (append args (list name))))))
55
56
+(defun vc-git--run-command-out (output &rest args)
57
+ "Run a git command, output to output."
58
+ (eq 0 (apply #'call-process "git" nil output nil (append args))))
59
+
60
(defun vc-git-registered (file)
61
"Check whether FILE is registered with git."
62
(with-temp-buffer
@@ -120,7 +124,28 @@
124
(vc-git--run-command file "commit" "-m" comment "--only" "--")))
125
126
(defun vc-git-checkout (file &optional editable rev destfile)
123
- (vc-git--run-command file "checkout" (or rev "HEAD")))
127
+ (if destfile
128
+ (let ((mybuff (get-buffer-create "vc-git-checkout-tmp")))
129
+ (let ((rv
130
+ (vc-git--run-command-out
131
+ mybuff "cat-file" "blob"
132
+ (concat (or rev "HEAD")
133
+ ":"
134
+ (let ((output (vc-git--run-command-string
135
+ (file-relative-name file)
136
+ "ls-files" "--full-name")))
137
+ (string-match "\\(.*\\)" output)
138
+ (match-string 1 output))
139
+ )))
140
+ )
141
+ (if rv
142
+ (save-current-buffer
143
+ (set-buffer mybuff)
144
+ (set-visited-file-name destfile t)
145
+ (save-buffer)
146
+ )
147
+ rv)))
148
+ (vc-git--run-command file "checkout" (or rev "HEAD"))))
149
150
(defun vc-git-annotate-command (file buf &optional rev)
151
; FIXME: rev is ignored