* [PATCH] contrib/emacs/vc-git.el: support vc-version-other-window
@ 2007-01-25 23:41 Sam Vilain
0 siblings, 0 replies; 2+ messages in thread
From: Sam Vilain @ 2007-01-25 23:41 UTC (permalink / raw)
To: git
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.
---
contrib/emacs/vc-git.el | 27 ++++++++++++++++++++++++++-
1 files changed, 26 insertions(+), 1 deletions(-)
(this is a second re-send, the original patch got dropped, probably
because it had an unsubscribed sender)
diff --git a/contrib/emacs/vc-git.el b/contrib/emacs/vc-git.el
index 8b63619..35a0e76 100644
--- a/contrib/emacs/vc-git.el
+++ b/contrib/emacs/vc-git.el
@@ -53,6 +53,10 @@
(let ((name (file-relative-name file)))
(eq 0 (apply #'call-process "git" nil (get-buffer "*Messages") nil (append args (list name))))))
+(defun vc-git--run-command-out (output &rest args)
+ "Run a git command, output to output."
+ (eq 0 (apply #'call-process "git" nil output nil (append args))))
+
(defun vc-git-registered (file)
"Check whether FILE is registered with git."
(with-temp-buffer
@@ -119,7 +123,28 @@
(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 ((mybuff (get-buffer-create "vc-git-checkout-tmp")))
+ (let ((rv
+ (vc-git--run-command-out
+ mybuff "cat-file" "blob"
+ (concat (or rev "HEAD")
+ ":"
+ (let ((output (vc-git--run-command-string
+ (file-relative-name file)
+ "ls-files" "--full-name")))
+ (string-match "\\(.*\\)" output)
+ (match-string 1 output))
+ )))
+ )
+ (if rv
+ (save-current-buffer
+ (set-buffer mybuff)
+ (set-visited-file-name destfile t)
+ (save-buffer)
+ )
+ rv)))
+ (vc-git--run-command file "checkout" (or rev "HEAD"))))
(defun vc-git-annotate-command (file buf &optional rev)
; FIXME: rev is ignored
--
1.4.4.1.g6a1a-dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] contrib/emacs/vc-git.el: support vc-version-other-window
[not found] <20070125234352.340DACB9F4@localhost.localdomain>
@ 2007-01-26 10:57 ` Alexandre Julliard
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Julliard @ 2007-01-26 10:57 UTC (permalink / raw)
To: Sam Vilain; +Cc: git
Sam Vilain <sam.vilain@catalyst.net.nz> writes:
> 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:
>From b37cff5399dd94abe3d4e9778cdbf5cee53d46c0 Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
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 <sam.vilain@catalyst.net.nz>.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
contrib/emacs/vc-git.el | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/contrib/emacs/vc-git.el b/contrib/emacs/vc-git.el
index 3eb4bd1..e456ab9 100644
--- a/contrib/emacs/vc-git.el
+++ b/contrib/emacs/vc-git.el
@@ -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
--
1.5.0.rc2.gc651
--
Alexandre Julliard
julliard@winehq.org
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-01-26 10:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20070125234352.340DACB9F4@localhost.localdomain>
2007-01-26 10:57 ` [PATCH] contrib/emacs/vc-git.el: support vc-version-other-window Alexandre Julliard
2007-01-25 23:41 Sam Vilain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).