[PATCH] contrib/emacs/vc-git.el: various improvements.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



(vc-git-symbolic-commit): Simplify and make it return
something useful in almost all cases.
(vc-git-previous-version): Simplify.
(vc-git-next-version): Simplify and make more efficient.
(vc-git-annotate-command): heed REV argument.
(vc-annotate-extract-revision-at-line): Activate.

Signed-off-by: David Kastrup <dak@xxxxxxx>
---
 contrib/emacs/vc-git.el |  110 ++++++++++++++++++++---------------------------
 1 files changed, 47 insertions(+), 63 deletions(-)

diff --git a/contrib/emacs/vc-git.el b/contrib/emacs/vc-git.el
index b8f6be5..3637c8a 100644
--- a/contrib/emacs/vc-git.el
+++ b/contrib/emacs/vc-git.el
@@ -84,67 +84,51 @@
 (defun vc-git-symbolic-commit (commit)
   "Translate COMMIT string into symbolic form.
 Returns nil if not possible."
-  (and commit
-       (with-temp-buffer
-	 (and
-	  (zerop
-	   (call-process "git" nil '(t nil) nil "name-rev"
-			 "--name-only" "--tags"
-			 commit))
-	  (goto-char (point-min))
-	  (= (forward-line 2) 1)
-	  (bolp)
-	  (buffer-substring-no-properties (point-min) (1- (point-max)))))))
+  (with-temp-buffer
+    (and
+     (zerop
+      (call-process "git" nil '(t nil) nil "name-rev"
+		    commit))
+     (goto-char (point-max))
+     (bolp)
+     (zerop (forward-line -1))
+     (bobp)
+     (progn
+       (search-forward " " nil t)
+       (not (eolp)))
+     (buffer-substring-no-properties (point) (1- (point-max))))))
 
 (defun vc-git-previous-version (file rev)
   "git-specific version of `vc-previous-version'."
-  (let ((default-directory (file-name-directory (expand-file-name file)))
-	(file (file-name-nondirectory file)))
-    (vc-git-symbolic-commit
-     (with-temp-buffer
-       (and
-	(zerop
-	 (call-process "git" nil '(t nil) nil "rev-list"
-		       "-2" rev "--" file))
-	(goto-char (point-max))
-	(bolp)
-	(zerop (forward-line -1))
-	(not (bobp))
-	(buffer-substring-no-properties
-	   (point)
-	   (1- (point-max))))))))
+  (vc-git-symbolic-commit
+   (with-temp-buffer
+     (and
+      (zerop
+       (call-process "git" nil '(t nil) nil "rev-list" "--abbrev"
+		     "--abbrev-commit" "-2" rev "--" (file-relative-name file)))
+      (goto-char (point-max))
+      (bolp)
+      (zerop (forward-line -1))
+      (not (bobp))
+      (buffer-substring-no-properties
+       (point)
+       (1- (point-max)))))))
 
 (defun vc-git-next-version (file rev)
   "git-specific version of `vc-next-version'."
-  (let* ((default-directory (file-name-directory
-			     (expand-file-name file)))
-	(file (file-name-nondirectory file))
-	(current-rev
-	 (with-temp-buffer
-	   (and
-	    (zerop
-	     (call-process "git" nil '(t nil) nil "rev-list"
-			   "-1" rev "--" file))
-	    (goto-char (point-max))
-	    (bolp)
-	    (zerop (forward-line -1))
-	    (bobp)
-	    (buffer-substring-no-properties
-	     (point)
-	     (1- (point-max)))))))
-    (and current-rev
-	 (vc-git-symbolic-commit
-	  (with-temp-buffer
-	    (and
-	     (zerop
-	      (call-process "git" nil '(t nil) nil "rev-list"
-			    "HEAD" "--" file))
-	     (goto-char (point-min))
-	     (search-forward current-rev nil t)
-	     (zerop (forward-line -1))
-	     (buffer-substring-no-properties
-	      (point)
-	      (progn (forward-line 1) (1- (point))))))))))
+  (vc-git-symbolic-commit
+   (with-temp-buffer
+     (and
+      (zerop
+       (call-process "git" nil '(t nil) nil "rev-list" "--abbrev"
+		     "--abbrev-commit"
+		     "HEAD" "--not" rev "--" (file-relative-name file)))
+      (goto-char (point-max))
+      (bolp)
+      (zerop (forward-line -1))
+      (buffer-substring-no-properties
+       (point)
+       (1- (point-max)))))))
 
 (defun vc-git-revert (file &optional contents-done)
   "Revert FILE to the version stored in the git repository."
@@ -197,20 +181,20 @@ Returns nil if not possible."
     (vc-git--run-command file "checkout" (or rev "HEAD"))))
 
 (defun vc-git-annotate-command (file buf &optional rev)
-  ; FIXME: rev is ignored
   (let ((name (file-relative-name file)))
-    (call-process "git" nil buf nil "blame" name)))
+    (if rev
+	(call-process "git" nil buf nil "blame" rev "--" name)
+      (call-process "git" nil buf nil "blame" "--" name))))
 
 (defun vc-git-annotate-time ()
   (and (re-search-forward "[0-9a-f]+ (.* \\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\) \\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) \\([-+0-9]+\\) +[0-9]+)" nil t)
        (vc-annotate-convert-time
         (apply #'encode-time (mapcar (lambda (match) (string-to-number (match-string match))) '(6 5 4 3 2 1 7))))))
 
-;; Not really useful since we can't do anything with the revision yet
-;;(defun vc-annotate-extract-revision-at-line ()
-;;  (save-excursion
-;;    (move-beginning-of-line 1)
-;;    (and (looking-at "[0-9a-f]+")
-;;         (buffer-substring (match-beginning 0) (match-end 0)))))
+(defun vc-annotate-extract-revision-at-line ()
+  (save-excursion
+    (move-beginning-of-line 1)
+    (and (looking-at "[0-9a-f]+")
+         (buffer-substring (match-beginning 0) (match-end 0)))))
 
 (provide 'vc-git)
-- 
1.4.4.2


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux