{"thread":{"id":"12262","subject":"[RFC PATCH] Implement vc-git-annotate-show-diff-revision-at-line for emacs vc-git","startedAt":"2008-02-22T18:58:13Z","lastAt":"2008-02-23T09:09:24Z","messageCount":5,"participants":["Alex Bennee","Alexandre Julliard","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"69611","messageId":"1203706693.7552.56.camel@alexjb-desktop.transitives.com","threadId":"12262","inReplyTo":null,"subject":"[RFC PATCH] Implement vc-git-annotate-show-diff-revision-at-line for emacs vc-git","fromName":"Alex Bennee","fromEmail":"kernel-hacker@bennee.com","sentAt":"2008-02-22T18:58:13Z","receivedAt":"2008-02-22T18:58:13Z","isPatch":true,"sender":{"key":"kernel-hacker@bennee.com","avatar":null},"body":"Hi,\n\nI've had an initial stab at doing this for jumping to the commit in\nannotate mode. You can manually call it with M-x\nvc-git-annotate-show-diff-revision-at-line and it all works fine.\nHowever the vc logic wants vc-git-previous-version to exist before it\nwill call it directly from the mode. I considered evil key-rebinding\nhacks but that seems to nasty.\n\nWhats the easiest command to show the parent commit of a given commit id\n(the closest analogy I can think of)? I tried:\n\n git-show 486a974a --pretty=\"format:%P\"\n\nBut that shows the whole commit as well. Anyway here is the current form\nof the patch. As you can probably tell elisp is not my first language:\n\n>From 84ef7155339b60c21851eab72842cb5c4e8b3d47 Mon Sep 17 00:00:00 2001\nFrom: Alex Bennee <alex@bennee.com>\nDate: Fri, 22 Feb 2008 18:51:43 +0000\nSubject: [PATCH] Attempt to implement annotate-jump-to-diff for vc-git.el\n\n---\n contrib/emacs/vc-git.el |   46 ++++++++++++++++++++++++++++++++++++++++------\n 1 files changed, 40 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/emacs/vc-git.el b/contrib/emacs/vc-git.el\nindex b8f6be5..67cca95 100644\n--- a/contrib/emacs/vc-git.el\n+++ b/contrib/emacs/vc-git.el\n@@ -38,6 +38,16 @@\n (defvar git-commits-coding-system 'utf-8\n   \"Default coding system for git commits.\")\n \n+;; Helper functions\n+;\n+; These are helper functions that don't hook into vc-mode as git's\n+; view of the versioned world is a little different to vc's\n+\n+(defun git-show-commit-diff (commit-id &optional buffer)\n+  \"Show a given commit id in patch form in a buffer\"\n+  (let ((buf (or buffer \"*vc-diff*\")))\n+    (vc-do-command buf t \"git\" nil \"show\" commit-id)))\n+\n (defun vc-git--run-command-string (file &rest args)\n   \"Run a git command on FILE and return its output as string.\"\n   (let* ((ok t)\n@@ -196,6 +206,34 @@ Returns nil if not possible.\"\n                               (concat (or rev \"HEAD\") \":\" fullname)))))\n     (vc-git--run-command file \"checkout\" (or rev \"HEAD\"))))\n \n+;; Not really useful since we can't do anything with the revision yet\n+(defun vc-git-annotate-extract-revision-at-line ()\n+  (save-excursion\n+    (move-beginning-of-line 1)\n+    (and (looking-at \"[0-9a-f]+\")\n+         (buffer-substring (match-beginning 0) (match-end 0)))))\n+\n+;;Jump to the diff for a given revision\n+;\n+; The internal vc logic has the concept of prev and next, GIT worries\n+; about commit ids. If we are in a git-annotate-view we really want to\n+; be doing this ourselves.\n+(defun vc-git-annotate-show-diff-revision-at-line ()\n+  \"Visit the diff of the version at line (git version).\"\n+  (interactive)\n+  (if (not (equal major-mode 'vc-annotate-mode))\n+      (message \"Cannot be invoked outside of a vc annotate buffer\")\n+    (let ((rev-at-line (vc-annotate-extract-revision-at-line)))\n+      (if (not rev-at-line)\n+\t  (message \"Cannot extract revision number from the current line\")\n+\t(save-window-excursion\n+\t  (git-show-commit-diff rev-at-line))\n+\t(switch-to-buffer \"*vc-diff*\")))))\n+\n+(defun vc-git-previous-version (file rev)\n+  0)\n+\n+;; Do the annotate for VC\n (defun vc-git-annotate-command (file buf &optional rev)\n   ; FIXME: rev is ignored\n   (let ((name (file-relative-name file)))\n@@ -206,11 +244,7 @@ Returns nil if not possible.\"\n        (vc-annotate-convert-time\n         (apply #'encode-time (mapcar (lambda (match) (string-to-number (match-string match))) '(6 5 4 3 2 1 7))))))\n \n-;; Not really useful since we can't do anything with the revision yet\n-;;(defun vc-annotate-extract-revision-at-line ()\n-;;  (save-excursion\n-;;    (move-beginning-of-line 1)\n-;;    (and (looking-at \"[0-9a-f]+\")\n-;;         (buffer-substring (match-beginning 0) (match-end 0)))))\n+\n+\n \n (provide 'vc-git)\n-- \n1.5.2.5\n\n\n\n-- \nAlex, homepage: http://www.bennee.com/~alex/\nHire me? http://www.bennee.com/~alex/cv.php\nnetgod: My calculator has more registers than the x86, and -- thats- sad\n"},{"id":"69612","messageId":"87ejb4kaob.fsf@wine.dyndns.org","threadId":"12262","inReplyTo":"1203706693.7552.56.camel@alexjb-desktop.transitives.com","subject":"Re: [RFC PATCH] Implement vc-git-annotate-show-diff-revision-at-line for emacs vc-git","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2008-02-22T20:17:56Z","receivedAt":"2008-02-22T20:17:56Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"Alex Bennee <kernel-hacker@bennee.com> writes:\n\n> I've had an initial stab at doing this for jumping to the commit in\n> annotate mode. You can manually call it with M-x\n> vc-git-annotate-show-diff-revision-at-line and it all works fine.\n> However the vc logic wants vc-git-previous-version to exist before it\n> will call it directly from the mode. I considered evil key-rebinding\n> hacks but that seems to nasty.\n\nvc-git is now maintained in the main Emacs repository, so that's the\nversion you should look at; it does have a vc-git-previous-version\nimplementation. The vc-git.el in the git repository is an older version\nthat is not being updated anymore.\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"},{"id":"69613","messageId":"7voda891jr.fsf@gitster.siamese.dyndns.org","threadId":"12262","inReplyTo":"1203706693.7552.56.camel@alexjb-desktop.transitives.com","subject":"Re: [RFC PATCH] Implement vc-git-annotate-show-diff-revision-at-line for emacs vc-git","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-22T20:30:32Z","receivedAt":"2008-02-22T20:30:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Bennee <kernel-hacker@bennee.com> writes:\n\n> Whats the easiest command to show the parent commit of a given commit id\n> (the closest analogy I can think of)? I tried:\n>\n>  git-show 486a974a --pretty=\"format:%P\"\n\n * Have rev before option, like \"git show --pretty=... 486a974\"\n\n * Use -s to squelch diff output.\n\nYou should check how the %P format shows parents for a merge and\ndecide which parent you would want to follow.\n"},{"id":"69615","messageId":"7vbq6890km.fsf@gitster.siamese.dyndns.org","threadId":"12262","inReplyTo":"1203706693.7552.56.camel@alexjb-desktop.transitives.com","subject":"Re: [RFC PATCH] Implement vc-git-annotate-show-diff-revision-at-line for emacs vc-git","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-22T20:51:37Z","receivedAt":"2008-02-22T20:51:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Bennee <kernel-hacker@bennee.com> writes:\n\n> +(defun vc-git-annotate-extract-revision-at-line ()\n> +  (save-excursion\n> +    (move-beginning-of-line 1)\n> +    (and (looking-at \"[0-9a-f]+\")\n> +         (buffer-substring (match-beginning 0) (match-end 0)))))\n\nDoes this grab the commit object name from the annotation\nof a _full_ file?  How is the annotation done?  With \"blame\"\nwithout frills?\n\nIt may be interesting to run:\n\n\tgit blame -w -n -f -C -- $path\n\nwhich would give you the code movement (ignoring whitespace\nchanges) across files, so that you can view where the line\nreally originated from.\n\nYou can also throw in -L line range limiter like this:\n\n\tgit blame -L$lineno-10,+20 -w -n -f -C -- $path\n\nwhich would limit the output to lines around the current line,\nand that would be slightly less expensive than annotating the\nwhole file, if you do this on-demand.\n\nE.g.\n\n\t$ git blame -L48,+20 -w -n -f -C -- block/blk-exec.c\n\nwould give you something like:\n\n    165125e1 block/ll_rw_blk.c         2585 (Jens Axboe       2007-07-2...\n    f1970baf drivers/block/ll_rw_blk.c 2255 (James Bottomley  2005-06-2...\n    8ffdc655 block/ll_rw_blk.c         2320 (Tejun Heo        2006-01-0...\n    f1970baf drivers/block/ll_rw_blk.c 2257 (James Bottomley  2005-06-2...\n    f1970baf drivers/block/ll_rw_blk.c 2258 (James Bottomley  2005-06-2...\n    f1970baf drivers/block/ll_rw_blk.c 2259 (James Bottomley  2005-06-2...\n    f1970baf drivers/block/ll_rw_blk.c 2260 (James Bottomley  2005-06-2...\n    4aff5e23 block/ll_rw_blk.c         2530 (Jens Axboe       2006-08-1...\n    f1970baf drivers/block/ll_rw_blk.c 2262 (James Bottomley  2005-06-2...\n    4c5d0bbd block/ll_rw_blk.c         2480 (Andrew Morton    2006-03-2...\n    4c5d0bbd block/ll_rw_blk.c         2481 (Andrew Morton    2006-03-2...\n    4c5d0bbd block/ll_rw_blk.c         2482 (Andrew Morton    2006-03-2...\n    4c5d0bbd block/ll_rw_blk.c         2483 (Andrew Morton    2006-03-2...\n    4c5d0bbd block/ll_rw_blk.c         2484 (Andrew Morton    2006-03-2...\n    f1970baf drivers/block/ll_rw_blk.c 2265 (James Bottomley  2005-06-2...\n    6e39b69e block/ll_rw_blk.c         2309 (Mike Christie    2005-11-1...\n    6e39b69e block/ll_rw_blk.c         2310 (Mike Christie    2005-11-1...\n    637b48c8 drivers/block/ll_rw_blk.c 1872 (Jens Axboe       2004-03-1...\n    637b48c8 drivers/block/ll_rw_blk.c 1873 (Jens Axboe       2004-03-1...\n    637b48c8 drivers/block/ll_rw_blk.c 1874 (Jens Axboe       2004-03-1...\n"},{"id":"69664","messageId":"b2cdc9f30802230109x27af2b90qf27cd6f92dd767e@mail.gmail.com","threadId":"12262","inReplyTo":"87ejb4kaob.fsf@wine.dyndns.org","subject":"Re: [RFC PATCH] Implement vc-git-annotate-show-diff-revision-at-line for emacs vc-git","fromName":"Alex Bennee","fromEmail":"kernel-hacker@bennee.com","sentAt":"2008-02-23T09:09:24Z","receivedAt":"2008-02-23T09:09:24Z","isPatch":true,"sender":{"key":"kernel-hacker@bennee.com","avatar":null},"body":"On 2/22/08, Alexandre Julliard <julliard@winehq.org> wrote:\n> Alex Bennee <kernel-hacker@bennee.com> writes:\n>\n>  > I've had an initial stab at doing this for jumping to the commit in\n>  > annotate mode.\n<snip>\n> vc-git is now maintained in the main Emacs repository, so that's the\n>  version you should look at; it does have a vc-git-previous-version\n>  implementation. The vc-git.el in the git repository is an older version\n>  that is not being updated anymore.\n\nPerhaps it would be worth mirroring the updates to vc-git.el in the\ngit repo for people that don't\nrun bleeding edge emacs but do track git development? Or does it need\nchanges that have been made to vc.el in the mainline?\n\n--\nAlex, homepage: http://www.bennee.com/~alex/\n"}]}