git-blame.el: blame unsaved changes
Make git-blame use the current buffer contents for the blame, instead of the saved file. This makes the blame correct even if there are unsaved changes. Also added a git-reblame command. Signed-off-by: David Kågedal <davidk@lysator.liu.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
David Kågedal committed
Feb 9, 2007 at 09:21 UTC
f0f39bb4c4ba36a07d7a6f034ba12f2ca0522db8
1 file changed
+44
-21
contrib/emacs/git-blame.el
+44
-21
@@ -102,8 +102,17 @@
102
103
(defvar git-blame-ancient-color "dark green")
104
105
-(defvar git-blame-overlays nil)
106
-(defvar git-blame-cache nil)
105
+(defvar git-blame-proc nil
106
+ "The running git-blame process")
107
+(make-variable-buffer-local 'git-blame-proc)
108
+
109
+(defvar git-blame-overlays nil
110
+ "The git-blame overlays used in the current buffer.")
111
+(make-variable-buffer-local 'git-blame-overlays)
112
+
113
+(defvar git-blame-cache nil
114
+ "A cache of git-blame information for the current buffer")
115
+(make-variable-buffer-local 'git-blame-cache)
116
117
(defvar git-blame-mode nil)
118
(make-variable-buffer-local 'git-blame-mode)
@@ -118,9 +127,7 @@
127
(if arg
128
(setq git-blame-mode (eq arg 1))
129
(setq git-blame-mode (not git-blame-mode)))
121
- (make-local-variable 'git-blame-overlays)
130
(make-local-variable 'git-blame-colors)
123
- (make-local-variable 'git-blame-cache)
131
(git-blame-cleanup)
132
(if git-blame-mode
133
(progn
@@ -131,24 +138,37 @@
138
(setq git-blame-cache (make-hash-table :test 'equal))
139
(git-blame-run))))
140
141
+;;;###autoload
142
+(defun git-reblame ()
143
+ "Recalculate all blame information in the current buffer"
144
+ (unless git-blame-mode
145
+ (error "git-blame is not active"))
146
+ (interactive)
147
+ (git-blame-cleanup)
148
+ (git-blame-run))
149
+
150
(defun git-blame-run ()
135
- (let* ((display-buf (current-buffer))
136
- (blame-buf (get-buffer-create
137
- (concat " git blame for " (buffer-name))))
138
- (proc (start-process "git-blame" blame-buf
139
- "git" "blame" "--incremental"
140
- (file-name-nondirectory buffer-file-name))))
141
- (mapcar 'delete-overlay git-blame-overlays)
142
- (setq git-blame-overlays nil)
143
- (setq git-blame-cache (make-hash-table :test 'equal))
144
- (with-current-buffer blame-buf
145
- (erase-buffer)
146
- (make-local-variable 'git-blame-file)
147
- (make-local-variable 'git-blame-current)
148
- (setq git-blame-file display-buf)
149
- (setq git-blame-current nil))
150
- (set-process-filter proc 'git-blame-filter)
151
- (set-process-sentinel proc 'git-blame-sentinel)))
151
+ (if git-blame-proc
152
+ ;; Should maybe queue up a new run here
153
+ (message "Already running git blame")
154
+ (let ((display-buf (current-buffer))
155
+ (blame-buf (get-buffer-create
156
+ (concat " git blame for " (buffer-name)))))
157
+ (setq git-blame-proc
158
+ (start-process "git-blame" blame-buf
159
+ "git" "blame"
160
+ "--incremental" "--contents" "-"
161
+ (file-name-nondirectory buffer-file-name)))
162
+ (with-current-buffer blame-buf
163
+ (erase-buffer)
164
+ (make-local-variable 'git-blame-file)
165
+ (make-local-variable 'git-blame-current)
166
+ (setq git-blame-file display-buf)
167
+ (setq git-blame-current nil))
168
+ (set-process-filter git-blame-proc 'git-blame-filter)
169
+ (set-process-sentinel git-blame-proc 'git-blame-sentinel)
170
+ (process-send-region git-blame-proc (point-min) (point-max))
171
+ (process-send-eof git-blame-proc))))
172
173
(defun git-blame-cleanup ()
174
"Remove all blame properties"
@@ -159,6 +179,9 @@
179
(set-buffer-modified-p modified)))
180
181
(defun git-blame-sentinel (proc status)
182
+ (with-current-buffer (process-buffer proc)
183
+ (with-current-buffer git-blame-file
184
+ (setq git-blame-proc nil)))
185
;;(kill-buffer (process-buffer proc))
186
(message "git blame finished"))
187