Skip to contentSkip to conversation

contrib/emacs/vc-git.el: support vc-version-other-window

PATCH Alexandre Julliard 1 participant 1 message Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 5 lines · Sam Vilain

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.

This looks good, though the code can be made simpler by using with-temp-file to create the file. Also you need to avoid charset conversions when reading and writing, and you should use ls-files -z to avoid problems with strange file names.

I'd suggest something like this:

Quoted 1 line

From b37cff5399dd94abe3d4e9778cdbf5cee53d46c0 Mon Sep 17 00:00:00 2001

From: Alexandre Julliard <[email protected]>
Date: Fri, 26 Jan 2007 11:39:55 +0100
Subject: [PATCH] vc-git.el: Take into account the destination name in vc-checkout.

This is necessary for vc-version-other-window. Based on a patch by Sam Vilain <[email protected]>.

---
 contrib/emacs/vc-git.el |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
contrib/emacs/vc-git.el +10 -1
index 3eb4bd1..e456ab9 100644
@@ -120,7 +120,16 @@
     (vc-git--run-command file "commit" "-m" comment "--only" "--")))
 
 (defun vc-git-checkout (file &optional editable rev destfile)
-  (vc-git--run-command file "checkout" (or rev "HEAD")))
+  (if destfile
+      (let ((fullname (substring
+                       (vc-git--run-command-string file "ls-files" "-z" "--full-name" "--")
+                       0 -1))
+            (coding-system-for-read 'no-conversion)
+            (coding-system-for-write 'no-conversion))
+        (with-temp-file destfile
+          (eq 0 (call-process "git" nil t nil "cat-file" "blob"
+                              (concat (or rev "HEAD") ":" fullname)))))
+    (vc-git--run-command file "checkout" (or rev "HEAD"))))
 
 (defun vc-git-annotate-command (file buf &optional rev)
   ; FIXME: rev is ignored
Signature · 7 lines
1.5.0.rc2.gc651



-- 
Alexandre Julliard
[email protected]