changeset 96524:d620ef3acfdc

* vc-git.el (vc-git-registered): Return true for removed files. (vc-git-print-log, vc-git-log-view-mode): Print a single log for all the files instead of one per file. (vc-git-previous-revision): Add support for project-wide previous revision when specified file is nil.
author Alexandre Julliard <julliard@winehq.org>
date Sat, 05 Jul 2008 18:42:07 +0000
parents 090433f48c5f
children b6c89c6c537a
files lisp/ChangeLog lisp/vc-git.el
diffstat 2 files changed, 45 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Jul 05 18:27:16 2008 +0000
+++ b/lisp/ChangeLog	Sat Jul 05 18:42:07 2008 +0000
@@ -1,3 +1,11 @@
+2008-07-05  Alexandre Julliard  <julliard@winehq.org>
+
+	* vc-git.el (vc-git-registered): Return true for removed files.
+	(vc-git-print-log, vc-git-log-view-mode): Print a single log for
+	all the files instead of one per file.
+	(vc-git-previous-revision): Add support for project-wide previous
+	revision when specified file is nil.
+
 2008-07-05  Dan Nicolaescu  <dann@ics.uci.edu>
 
 	* vms-patch.el, vmsproc.el, mail/vms-pmail.el: Move to obsolete dir.
--- a/lisp/vc-git.el	Sat Jul 05 18:27:16 2008 +0000
+++ b/lisp/vc-git.el	Sat Jul 05 18:42:07 2008 +0000
@@ -132,14 +132,18 @@
   (when (vc-git-root file)
     (with-temp-buffer
       (let* ((dir (file-name-directory file))
-	     (name (file-relative-name file dir)))
-	(and (ignore-errors
-               (when dir (cd dir))
-               (vc-git--out-ok "ls-files" "-c" "-z" "--" name))
-	     (let ((str (buffer-string)))
-	       (and (> (length str) (length name))
-		    (string= (substring str 0 (1+ (length name)))
-                             (concat name "\0")))))))))
+             (name (file-relative-name file dir))
+             (str (ignore-errors
+                    (when dir (cd dir))
+                    (vc-git--out-ok "ls-files" "-c" "-z" "--" name)
+                    ;; if result is empty, use ls-tree to check for deleted file
+                    (when (eq (point-min) (point-max))
+                      (vc-git--out-ok "ls-tree" "--name-only" "-z" "HEAD" "--" name))
+                    (buffer-string))))
+        (and str
+             (> (length str) (length name))
+             (string= (substring str 0 (1+ (length name)))
+                      (concat name "\0")))))))
 
 (defun vc-git--state-code (code)
   "Convert from a string to a added/deleted/modified state."
@@ -453,33 +457,26 @@
     ;; If the buffer exists from a previous invocation it might be
     ;; read-only.
     (let ((inhibit-read-only t))
-      ;; XXX `log-view-mode' needs to have something to identify where
-      ;; the log for each individual file starts. It seems that by
-      ;; default git does not output this info. So loop here and call
-      ;; "git rev-list" on each file separately to make sure that each
-      ;; file gets a "File:" header before the corresponding
-      ;; log. Maybe there is a way to do this with one command...
-      (dolist (file flist)
-	(with-current-buffer
-	    buffer
-	  (insert "File: " (file-name-nondirectory file) "\n"))
-	(vc-git-command buffer 'async (file-relative-name file)
+      (with-current-buffer
+          buffer
+	(vc-git-command buffer 'async files
 			"rev-list" "--pretty" "HEAD" "--")))))
 
 (defvar log-view-message-re)
 (defvar log-view-file-re)
 (defvar log-view-font-lock-keywords)
+(defvar log-view-per-file-logs)
 
 (define-derived-mode vc-git-log-view-mode log-view-mode "Git-Log-View"
   (require 'add-log) ;; we need the faces add-log
   ;; Don't have file markers, so use impossible regexp.
-  (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)")
+  (set (make-local-variable 'log-view-file-re) "\\`a\\`")
+  (set (make-local-variable 'log-view-per-file-logs) nil)
   (set (make-local-variable 'log-view-message-re)
        "^commit *\\([0-9a-z]+\\)")
   (set (make-local-variable 'log-view-font-lock-keywords)
        (append
-        `((,log-view-message-re  (1 'change-log-acknowledgement))
-          (,log-view-file-re (1 'change-log-file-face)))
+        `((,log-view-message-re  (1 'change-log-acknowledgement)))
         ;; Handle the case:
         ;; user: foo@bar
         '(("^Author:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)"
@@ -577,19 +574,24 @@
 
 (defun vc-git-previous-revision (file rev)
   "Git-specific version of `vc-previous-revision'."
-  (let ((default-directory (file-name-directory (expand-file-name file)))
-	(file (file-name-nondirectory file)))
-    (vc-git-symbolic-commit
-     (with-temp-buffer
-       (and
-	(vc-git--out-ok "rev-list" "-2" rev "--" file)
-	(goto-char (point-max))
-	(bolp)
-	(zerop (forward-line -1))
-	(not (bobp))
-	(buffer-substring-no-properties
-         (point)
-         (1- (point-max))))))))
+  (if file
+      (let ((default-directory (file-name-directory (expand-file-name file)))
+            (file (file-name-nondirectory file)))
+        (vc-git-symbolic-commit
+         (with-temp-buffer
+           (and
+            (vc-git--out-ok "rev-list" "-2" rev "--" file)
+            (goto-char (point-max))
+            (bolp)
+            (zerop (forward-line -1))
+            (not (bobp))
+            (buffer-substring-no-properties
+             (point)
+             (1- (point-max)))))))
+    (with-temp-buffer
+      (and
+       (vc-git--out-ok "rev-parse" (concat rev "^"))
+       (buffer-substring-no-properties (point-min) (+ (point-min) 40))))))
 
 (defun vc-git-next-revision (file rev)
   "Git-specific version of `vc-next-revision'."