git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Make several improvements and get annotations to work (Emacs support pending).

From
David Kastrup <dak@gnu.org>
Date
Jul 15, 2007, 23:42 UTC
Message-ID
<4613d30307e12be13b88b76f755ea8756a56f554.1184548803.git.dak@gnu.org>
In-Reply-To
<403842ba71506c7b194812cd9a4f669c847eb7bc.1184548803.git.dak@gnu.org>

(vc-git-symbolic-commit): Allow nil to pass through. (vc-git-previous-version): Use explicit parent argument. (vc-git-next-version): Simplify. (vc-git-annotate-command): Use `vc-do-command'. (vc-git-annotate-extract-revision-at-line): Rename from `vc-annotate-extract-revision-at-line'.

Signed-off-by: David Kastrup <dak@gnu.org>
---
 contrib/emacs/vc-git.el |   76 +++++++++++++++++++++++++++--------------------
 1 files changed, 44 insertions(+), 32 deletions(-)
diff --git a/contrib/emacs/vc-git.el b/contrib/emacs/vc-git.el
index 3637c8a..2a0a0fe 100644
--- a/contrib/emacs/vc-git.el
+++ b/contrib/emacs/vc-git.el
@@ -84,19 +84,20 @@
 (defun vc-git-symbolic-commit (commit)
   "Translate COMMIT string into symbolic form.
 Returns nil if not possible."
-  (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))))))
+  (and commit
+       (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'."
@@ -104,15 +105,13 @@ Returns nil if not possible."
    (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)))))))
+       (call-process "git" nil '(t nil) nil "rev-list"
+		     "--abbrev"
+		     "--abbrev-commit" "-1" "--parents" rev "--"
+		     (file-relative-name file)))
+      (goto-char (point-min))
+      (search-forward-regexp " \\([^ \n]*\\)" nil t)
+      (match-string 1)))))
 
 (defun vc-git-next-version (file rev)
   "git-specific version of `vc-next-version'."
@@ -121,8 +120,9 @@ Returns nil if not possible."
      (and
       (zerop
        (call-process "git" nil '(t nil) nil "rev-list" "--abbrev"
-		     "--abbrev-commit"
+		     "--abbrev-commit"  "--remove-empty"
 		     "HEAD" "--not" rev "--" (file-relative-name file)))
+      (goto-char (point-min))
       (goto-char (point-max))
       (bolp)
       (zerop (forward-line -1))
@@ -174,24 +174,36 @@ Returns nil if not possible."
                        (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))
+            coding-system-for-write)
         (with-temp-file destfile
-          (eq 0 (call-process "git" nil t nil "cat-file" "blob"
-                              (concat (or rev "HEAD") ":" fullname)))))
+	  (prog1
+	      (eq 0 (call-process "git" nil t nil "cat-file" "blob"
+				  (concat (or rev "HEAD") ":" fullname)))
+	    (setq coding-system-for-write 'no-conversion))))
     (vc-git--run-command file "checkout" (or rev "HEAD"))))
 
-(defun vc-git-annotate-command (file buf &optional rev)
-  (let ((name (file-relative-name file)))
-    (if rev
-	(call-process "git" nil buf nil "blame" rev "--" name)
-      (call-process "git" nil buf nil "blame" "--" name))))
+(defun vc-git-annotate-command (file buffer &optional version)
+  "Execute \"git blame\" on FILE, inserting the contents in BUFFER.
+Optional arg VERSION is a version to annotate from."
+  (vc-do-command buffer
+		 'async
+		 "git" file "blame"
+		 (or version "HEAD")
+		 "--"))
+
+;;(defun vc-git-annotate-command (file buf &optional rev)
+;;  (let ((name (file-relative-name file)))
+;;    (vc-setup-buffer buf)
+;;    (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))))))
 
-(defun vc-annotate-extract-revision-at-line ()
+(defun vc-git-annotate-extract-revision-at-line ()
   (save-excursion
     (move-beginning-of-line 1)
     (and (looking-at "[0-9a-f]+")
-- 
1.4.4.2
Previous: Junio C HamanoNext: David Kastrup
Message 5 of 12 in “contrib/emacs/vc-git.el: various improvements.”
  1. contrib/emacs/vc-git.el: various improvements.David Kastrup, Jul 16, 2007
  2. contrib/emacs/Makefile: Also install .el files.David Kastrup, Jul 15, 2007
  3. David KastrupJul 16, 2007
  4. Junio C HamanoJul 16, 2007
  5. Make several improvements and get annotations to work (Emacs support pending).David Kastrup, Jul 15, 2007
  6. vc-git: support asynchronous annotations, and improve versioning.David Kastrup, Jul 15, 2007
  7. Junio C HamanoJul 16, 2007
  8. David KastrupJul 16, 2007
  9. Junio C HamanoJul 16, 2007
  10. (vc-git-annotate-command): Make synchronous for now.David Kastrup, Jul 16, 2007
  11. Junio C HamanoJul 16, 2007
  12. David KastrupJul 16, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.