]> code.delx.au - gnu-emacs/blobdiff - lisp/vc/vc-git.el
Add "Package:" file headers to denote built-in packages.
[gnu-emacs] / lisp / vc / vc-git.el
index 780afd9db2705d0beb57af162b451ed467cb237a..48a86454f741b2e9d770e05217fa584d88c6a136 100644 (file)
@@ -3,7 +3,8 @@
 ;; Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author: Alexandre Julliard <julliard@winehq.org>
-;; Keywords: tools
+;; Keywords: vc tools
+;; Package: vc
 
 ;; This file is part of GNU Emacs.
 
@@ -563,13 +564,18 @@ or an empty string if none."
   (let* (process-file-side-effects
         (coding-system-for-read 'binary)
         (coding-system-for-write 'binary)
-        (fullname (substring
-                   (vc-git--run-command-string
-                    file "ls-files" "-z" "--full-name" "--")
-                   0 -1)))
+        (fullname
+         (let ((fn (vc-git--run-command-string
+                    file "ls-files" "-z" "--full-name" "--")))
+           ;; ls-files does not return anything when looking for a
+           ;; revision of a file that has been renamed or removed.
+           (if (string= fn "")
+               (file-relative-name file (vc-git-root default-directory))
+             (substring fn 0 -1)))))
     (vc-git-command
      buffer 0
-     (concat (if rev rev "HEAD") ":" fullname) "cat-file" "blob")))
+     nil
+     "cat-file" "blob" (concat (if rev rev "HEAD") ":" fullname))))
 
 (defun vc-git-checkout (file &optional editable rev)
   (vc-git-command nil 0 file "checkout" (or rev "HEAD")))
@@ -723,7 +729,7 @@ or BRANCH^ (where \"^\" can be repeated)."
 
 (defun vc-git-annotate-command (file buf &optional rev)
   (let ((name (file-relative-name file)))
-    (vc-git-command buf 'async name "blame" "--date=iso" "-C" "-C" rev)))
+    (vc-git-command buf 'async nil "blame" "--date=iso" "-C" "-C" rev "--" name)))
 
 (declare-function vc-annotate-convert-time "vc-annotate" (time))
 
@@ -740,8 +746,12 @@ or BRANCH^ (where \"^\" can be repeated)."
     (when (looking-at "\\([0-9a-f^][0-9a-f]+\\) \\(\\([^(]+\\) \\)?")
       (let ((revision (match-string-no-properties 1)))
        (if (match-beginning 2)
-           (cons revision (expand-file-name (match-string-no-properties 3)
-                                            (vc-git-root default-directory)))
+           (let ((fname (match-string-no-properties 3)))
+             ;; Remove trailing whitespace from the file name.
+             (when (string-match " +\\'" fname)
+               (setq fname (substring fname 0 (match-beginning 0))))
+             (cons revision
+                   (expand-file-name fname (vc-git-root default-directory))))
          revision)))))
 
 ;;; TAG SYSTEM
@@ -765,11 +775,10 @@ or BRANCH^ (where \"^\" can be repeated)."
 (defun vc-git-previous-revision (file rev)
   "Git-specific version of `vc-previous-revision'."
   (if file
-      (let* ((default-directory (file-name-directory (expand-file-name file)))
-             (file (file-name-nondirectory file))
+      (let* ((fname (file-relative-name file))
              (prev-rev (with-temp-buffer
                          (and
-                          (vc-git--out-ok "rev-list" "-2" rev "--" file)
+                          (vc-git--out-ok "rev-list" "-2" rev "--" fname)
                           (goto-char (point-max))
                           (bolp)
                           (zerop (forward-line -1))