{"thread":{"id":"6680","subject":"[PATCH (take 2)] git-blame.el --- Minor mode for incremental blame for Git","startedAt":"2007-02-04T20:14:33Z","lastAt":"2007-02-06T16:45:56Z","messageCount":7,"participants":["Jakub Narebski","Junio C Hamano","Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"33587","messageId":"200702042114.34922.jnareb@gmail.com","threadId":"6680","inReplyTo":null,"subject":"[PATCH (take 2)] git-blame.el --- Minor mode for incremental blame for Git","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-02-04T20:14:33Z","receivedAt":"2007-02-04T20:14:33Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Here is an Emacs implementation of incremental git-blame.  When you\nturn it on while viewing a file, the editor buffer will be updated by\nsetting the background of individual lines to a color that reflects\nwhich commit it comes from.  And when you move around the buffer, a\none-line summary will be shown in the echo area.\n\nCreated by David Kågedal, header and comments added by Jakub Narębski.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\nSigned-off-by: David Kågedal <davidk@lysator.liu.se>\n---\nThis time I hope in proper utf-8 encoding.\n\nHere it is as a proper git patch, and with some headers and comments\nadded. As compared to latest version sent by David Kågedal,\n  Message-ID: <87iren2vqx.fsf@morpheus.local>\n  http://permalink.gmane.org/gmane.comp.version-control.git/38246\nit has elisp header and description by David Kågedal, has (require 'cl)\nwith explanation added, and (provide 'git-blame) at the end; no other\nchanges (as of now).\n\nDavid, is it released as GPL? If it is, GPL boilerplate (as in git.el)\ncould be added to the header.\n\n contrib/emacs/git-blame.el |  222 ++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 222 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/emacs/git-blame.el b/contrib/emacs/git-blame.el\nnew file mode 100644\nindex 0000000..fa89889\n--- /dev/null\n+++ b/contrib/emacs/git-blame.el\n@@ -0,0 +1,222 @@\n+;;; git-blame.el --- Minor mode for incremental blame for Git  -*- coding: utf-8 -*-\n+;;\n+;; Copyright (C) 2007 by David Kågedal\n+;;\n+;; Authors:    David Kågedal <davidk@lysator.liu.se>\n+;; Created:    31 Jan 2007\n+;; Keywords:   git, version control, release management\n+;;\n+;; Compatibility: Emacs21\n+\n+;;; Commentary:\n+;;\n+;; Here is an Emacs implementation of incremental git-blame.  When you\n+;; turn it on while viewing a file, the editor buffer will be updated by\n+;; setting the background of individual lines to a color that reflects\n+;; which commit it comes from.  And when you move around the buffer, a\n+;; one-line summary will be shown in the echo area.\n+\n+;;; Installation:\n+;;\n+;;  1) Load into emacs: M-x load-file RET git-blame.el RET\n+;;  2) Open a git-controlled file\n+;;  3) Blame: M-x git-blame-mode\n+\n+;;; Compatibility:\n+;;\n+;; It requires GNU Emacs 21.  If you'are using Emacs 20, try\n+;; changing this:\n+;;\n+;;            (overlay-put ovl 'face (list :background\n+;;                                         (cdr (assq 'color (cddddr info)))))\n+;;\n+;; to\n+;;\n+;;            (overlay-put ovl 'face (cons 'background-color\n+;;                                         (cdr (assq 'color (cddddr info)))))\n+\n+\n+;;; Code:\n+\n+(require 'cl)\t\t\t      ; to use `cddddr', `push', `pop'\n+\n+(defun color-scale (l)\n+  (let* ((colors ())\n+         r g b)\n+    (setq r l)\n+    (while r\n+      (setq g l)\n+      (while g\n+        (setq b l)\n+        (while b\n+          (push (concat \"#\" (car r) (car g) (car b)) colors)\n+          (pop b))\n+        (pop g))\n+      (pop r))\n+    colors))\n+\n+(defvar git-blame-dark-colors\n+  (color-scale '(\"00\" \"04\" \"08\" \"0c\"\n+                 \"10\" \"14\" \"18\" \"1c\"\n+                 \"20\" \"24\" \"28\" \"2c\"\n+                 \"30\" \"34\" \"38\" \"3c\")))\n+\n+(defvar git-blame-light-colors\n+  (color-scale '(\"c0\" \"c4\" \"c8\" \"cc\"\n+                 \"d0\" \"d4\" \"d8\" \"dc\"\n+                 \"e0\" \"e4\" \"e8\" \"ec\"\n+                 \"f0\" \"f4\" \"f8\" \"fc\")))\n+\n+(defvar git-blame-ancient-color \"dark green\")\n+\n+(defvar git-blame-overlays nil)\n+(defvar git-blame-cache nil)\n+\n+(defvar git-blame-mode nil)\n+(make-variable-buffer-local 'git-blame-mode)\n+(push (list 'git-blame-mode \" blame\") minor-mode-alist)\n+\n+(defun git-blame-mode (&optional arg)\n+  (interactive \"P\")\n+  (if arg\n+      (setq git-blame-mode (eq arg 1))\n+    (setq git-blame-mode (not git-blame-mode)))\n+  (make-local-variable 'git-blame-overlays)\n+  (make-local-variable 'git-blame-colors)\n+  (make-local-variable 'git-blame-cache)\n+   (let ((bgmode (cdr (assoc 'background-mode (frame-parameters)))))\n+    (if (eq bgmode 'dark)\n+        (setq git-blame-colors git-blame-dark-colors)\n+      (setq git-blame-colors git-blame-light-colors)))\n+  (if git-blame-mode\n+      (git-blame-run)\n+    (git-blame-cleanup)))\n+\n+(defun git-blame-run ()\n+  (let* ((display-buf (current-buffer))\n+         (blame-buf (get-buffer-create\n+                     (concat \" git blame for \" (buffer-name))))\n+         (proc (start-process \"git-blame\" blame-buf\n+                             \"git\" \"blame\" \"--incremental\"\n+                             (file-name-nondirectory buffer-file-name))))\n+    (mapcar 'delete-overlay git-blame-overlays)\n+    (setq git-blame-overlays nil)\n+    (setq git-blame-cache (make-hash-table :test 'equal))\n+    (with-current-buffer blame-buf\n+      (erase-buffer)\n+      (make-local-variable 'git-blame-file)\n+      (make-local-variable 'git-blame-current)\n+      (setq git-blame-file display-buf)\n+      (setq git-blame-current nil))\n+    (set-process-filter proc 'git-blame-filter)\n+    (set-process-sentinel proc 'git-blame-sentinel)))\n+\n+(defun git-blame-cleanup ()\n+  \"Remove all blame properties\"\n+    (mapcar 'delete-overlay git-blame-overlays)\n+    (setq git-blame-overlays nil)\n+    (let ((modified (buffer-modified-p)))\n+      (remove-text-properties (point-min) (point-max) '(point-entered nil))\n+      (set-buffer-modified-p modified)))\n+\n+\n+(defun git-blame-sentinel (proc status)\n+  ;;(kill-buffer (process-buffer proc))\n+  (message \"git blame finished\"))\n+\n+(defvar in-blame-filter nil)\n+\n+(defun git-blame-filter (proc str)\n+  (save-excursion\n+    (set-buffer (process-buffer proc))\n+    (goto-char (process-mark proc))\n+    (insert-before-markers str)\n+    (goto-char 0)\n+    (unless in-blame-filter\n+      (let ((more t)\n+            (in-blame-filter t))\n+        (while more\n+          (setq more (git-blame-parse)))))))\n+\n+(defun git-blame-parse ()\n+  (cond ((looking-at \"\\\\([0-9a-f]\\\\{40\\\\}\\\\) \\\\([0-9]+\\\\) \\\\([0-9]+\\\\) \\\\([0-9]+\\\\)\\n\")\n+         (let ((hash (match-string 1))\n+               (src-line (string-to-number (match-string 2)))\n+               (res-line (string-to-number (match-string 3)))\n+               (num-lines (string-to-number (match-string 4))))\n+           (setq git-blame-current\n+                 (git-blame-new-commit\n+                  hash src-line res-line num-lines)))\n+         (delete-region (point) (match-end 0))\n+         t)\n+        ((looking-at \"filename \\\\(.+\\\\)\\n\")\n+         (let ((filename (match-string 1)))\n+           (git-blame-add-info \"filename\" filename))\n+         (delete-region (point) (match-end 0))\n+         t)\n+        ((looking-at \"\\\\([a-z-]+\\\\) \\\\(.+\\\\)\\n\")\n+         (let ((key (match-string 1))\n+               (value (match-string 2)))\n+           (git-blame-add-info key value))\n+         (delete-region (point) (match-end 0))\n+         t)\n+        ((looking-at \"boundary\\n\")\n+         (setq git-blame-current nil)\n+         (delete-region (point) (match-end 0))\n+         t)\n+        (t\n+         nil)))\n+\n+\n+(defun git-blame-new-commit (hash src-line res-line num-lines)\n+  (save-excursion\n+    (set-buffer git-blame-file)\n+    (let ((info (gethash hash git-blame-cache))\n+          (inhibit-point-motion-hooks t))\n+      (when (not info)\n+        (let ((color (pop git-blame-colors)))\n+          (unless color\n+            (setq color git-blame-ancient-color))\n+          (setq info (list hash src-line res-line num-lines\n+                           (cons 'color color))))\n+        (puthash hash info git-blame-cache))\n+      (goto-line res-line)\n+      (while (> num-lines 0)\n+        (if (get-text-property (point) 'git-blame)\n+            (forward-line)\n+          (let* ((start (point))\n+                 (end (progn (forward-line 1) (point)))\n+                 (ovl (make-overlay start end)))\n+            (push ovl git-blame-overlays)\n+            (overlay-put ovl 'git-blame info)\n+            (overlay-put ovl 'help-echo hash)\n+            (overlay-put ovl 'face (list :background\n+                                         (cdr (assq 'color (cddddr info)))))\n+            ;;(overlay-put ovl 'point-entered\n+            ;;             `(lambda (x y) (git-blame-identify ,hash)))\n+            (let ((modified (buffer-modified-p)))\n+              (put-text-property (if (= start 1) start (1- start)) (1- end)\n+                                 'point-entered\n+                                 `(lambda (x y) (git-blame-identify ,hash)))\n+              (set-buffer-modified-p modified))))\n+        (setq num-lines (1- num-lines))))))\n+\n+(defun git-blame-add-info (key value)\n+  (if git-blame-current\n+      (nconc git-blame-current (list (cons (intern key) value)))))\n+\n+(defun git-blame-current-commit ()\n+  (let ((info (get-char-property (point) 'git-blame)))\n+    (if info\n+        (car info)\n+      (error \"No commit info\"))))\n+\n+(defun git-blame-identify (&optional hash)\n+  (interactive)\n+  (shell-command\n+   (format \"git log -1 --pretty=oneline %s\" (or hash\n+                                                (git-blame-current-commit)))))\n+\n+(provide 'git-blame)\n+\n+;;; git-blame.el ends here\n-- \n1.4.4.4\n"},{"id":"33595","messageId":"7vfy9lqusg.fsf@assigned-by-dhcp.cox.net","threadId":"6680","inReplyTo":"200702042114.34922.jnareb@gmail.com","subject":"Re: [PATCH (take 2)] git-blame.el --- Minor mode for incremental blame for Git","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-05T01:04:31Z","receivedAt":"2007-02-05T01:04:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> Here is an Emacs implementation of incremental git-blame.  When you\n\nMissing \"From: \" in-body header?\n\n> turn it on while viewing a file, the editor buffer will be updated by\n> setting the background of individual lines to a color that reflects\n> which commit it comes from.  And when you move around the buffer, a\n> one-line summary will be shown in the echo area.\n>\n> Created by David Kågedal, header and comments added by Jakub Narębski.\n\nAre you Narbski, or Narebski, or are they the same?\n\n> Signed-off-by: Jakub Narebski <jnareb@gmail.com>\n> Signed-off-by: David Kågedal <davidk@lysator.liu.se>\n\nI do not think David meant to go proprietary, but I did not see\nhis sign-off.\n\nDavid, is this patch Ok with you?  I'll fix up to have \"author\"\nline point fingers at you if it is, or you can send in your own\ncorrections/improvements (or a Nak) yourself.\n"},{"id":"33596","messageId":"200702050225.45328.jnareb@gmail.com","threadId":"6680","inReplyTo":"7vfy9lqusg.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH (take 2)] git-blame.el --- Minor mode for incremental blame for Git","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-02-05T01:25:42Z","receivedAt":"2007-02-05T01:25:42Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Junio C Hamano wrote:\n\n> Are you Narbski, or Narebski, or are they the same?\n\nI usually avoid using letters outside US-ASCII, approximating Narębski \n(with eogonek) with Narebski, but with David using aa in his name...\n-- \nJakub Narebski\nPoland\n"},{"id":"33598","messageId":"7vwt2xpeju.fsf@assigned-by-dhcp.cox.net","threadId":"6680","inReplyTo":"200702050225.45328.jnareb@gmail.com","subject":"Re: [PATCH (take 2)] git-blame.el --- Minor mode for incremental blame for Git","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-05T01:40:37Z","receivedAt":"2007-02-05T01:40:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> Junio C Hamano wrote:\n>\n>> Are you Narbski, or Narebski, or are they the same?\n>\n> I usually avoid using letters outside US-ASCII, approximating Narębski \n> (with eogonek) with Narebski, but with David using aa in his name...\n\nAhh, sorry, I usually use iso-ascii in an Emacs running on an\nASCII-only term-emu even when I am in X, and I did not see the\n<ę> character between r and b in your name (right now I am in\nanother Emacs I opened only to compose this message).\n\nJunio (aka 濱野 純)\n"},{"id":"33734","messageId":"200702061650.05221.jnareb@gmail.com","threadId":"6680","inReplyTo":"873b5jz5zw.fsf@morpheus.local","subject":"Re: [PATCH (take 2)] git-blame.el --- Minor mode for incremental blame for Git","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-02-06T15:50:04Z","receivedAt":"2007-02-06T15:50:04Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"David Kågedal wrote:\n\n> I have a feeling that my emails are not reaching the git list.  I\n> normally read through gmane, but to to keep people happy, I tried\n> answering the reply mails I got instead of following up in the\n> newsgroup.  But since I'm not directly subscribed, my emails are\n> probably dropped.\n> \n> I don't see Jakub's recent mails in this thread in gmane either, so\n> maybe he suffers from the same problem?\n\nIt looks like the whole subdiscussion didn't reach git list. I also\nread git through GMane NNTP interface, but it looks as if MARC also\nshows only 4 messages in this thread (no subthread starting from\nDavid reply). Junio, Alexandre, are you subscribed to git mailing\nlist; can you confirm if there is no copy of this (and previous)\nmessages via git@vger.kernel.org?\n\nPerhaps VGER anti-spam filter went funky again (it happened). \npostmaster@vger.kernel.org is to be pestered then.\n\n-- \nJakub Narebski\nPoland\n"},{"id":"33736","messageId":"20070206163126.GA18711@diana.vm.bytemark.co.uk","threadId":"6680","inReplyTo":"200702061650.05221.jnareb@gmail.com","subject":"Re: [PATCH (take 2)] git-blame.el --- Minor mode for incremental blame for Git","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2007-02-06T16:31:26Z","receivedAt":"2007-02-06T16:31:26Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2007-02-06 16:50:04 +0100, Jakub Narebski wrote:\n\n> can you confirm if there is no copy of this (and previous) messages\n> via git@vger.kernel.org?\n\nI get the list mails via mail, and I haven't seen any discussion\nbetween you and David.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"33739","messageId":"200702061745.57372.jnareb@gmail.com","threadId":"6680","inReplyTo":"20070206163126.GA18711@diana.vm.bytemark.co.uk","subject":"Re: [PATCH (take 2)] git-blame.el --- Minor mode for incremental blame for Git","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-02-06T16:45:56Z","receivedAt":"2007-02-06T16:45:56Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Karl Hasselström wrote:\n> On 2007-02-06 16:50:04 +0100, Jakub Narebski wrote:\n> \n>> can you confirm if there is no copy of this (and previous) messages\n>> via git@vger.kernel.org?\n> \n> I get the list mails via mail, and I haven't seen any discussion\n> between you and David.\n\nHmmm... I wonder if it was because of using\n  Junio C.Hamano <junkio@cox.net>\ninstead of\n  Junio Hamano <junkio@cox.net>\n\nIn short: David said that git-blame.el is GPLv2 or later, and we agreed\non using `define-minor-mode' later when we have keymap.\n\n-- \nJakub Narebski\nPoland\n"}]}