Skip to content

Commit 0e59a6f

Browse files
wence-gitster
authored andcommitted
git-blame.el: Use with-current-buffer where appropriate
In git-blame-filter and git-blame-create-overlay we want to save (along with the values of point and mark) the current-buffer in scope when calling the functions. The idiom (save-excursion (set-buffer buf) ...) will correctly restore the correct buffer, but will not save the values of point and mark in buf (only in the buffer current when the save-excursion call is executed). The intention of these functions is to save the current buffer from the calling scope and the values of point and mark in the buffer they are modifying. The correct idiom for this is (with-current-buffer buf (save-excursion ...)) Signed-off-by: Rüdiger Sonderfeld <[email protected]> Signed-off-by: Lawrence Mitchell <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d7da9a commit 0e59a6f

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

contrib/emacs/git-blame.el

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,16 @@ See also function `git-blame-mode'."
337337
(defvar in-blame-filter nil)
338338

339339
(defun git-blame-filter (proc str)
340-
(save-excursion
341-
(set-buffer (process-buffer proc))
342-
(goto-char (process-mark proc))
343-
(insert-before-markers str)
344-
(goto-char 0)
345-
(unless in-blame-filter
346-
(let ((more t)
347-
(in-blame-filter t))
348-
(while more
349-
(setq more (git-blame-parse)))))))
340+
(with-current-buffer (process-buffer proc)
341+
(save-excursion
342+
(goto-char (process-mark proc))
343+
(insert-before-markers str)
344+
(goto-char 0)
345+
(unless in-blame-filter
346+
(let ((more t)
347+
(in-blame-filter t))
348+
(while more
349+
(setq more (git-blame-parse))))))))
350350

351351
(defun git-blame-parse ()
352352
(cond ((looking-at "\\([0-9a-f]\\{40\\}\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)\n")
@@ -385,33 +385,33 @@ See also function `git-blame-mode'."
385385
info))))
386386

387387
(defun git-blame-create-overlay (info start-line num-lines)
388-
(save-excursion
389-
(set-buffer git-blame-file)
390-
(let ((inhibit-point-motion-hooks t)
391-
(inhibit-modification-hooks t))
392-
(goto-char (point-min))
393-
(forward-line (1- start-line))
394-
(let* ((start (point))
395-
(end (progn (forward-line num-lines) (point)))
396-
(ovl (make-overlay start end))
397-
(hash (car info))
398-
(spec `((?h . ,(substring hash 0 6))
399-
(?H . ,hash)
400-
(?a . ,(git-blame-get-info info 'author))
401-
(?A . ,(git-blame-get-info info 'author-mail))
402-
(?c . ,(git-blame-get-info info 'committer))
403-
(?C . ,(git-blame-get-info info 'committer-mail))
404-
(?s . ,(git-blame-get-info info 'summary)))))
405-
(push ovl git-blame-overlays)
406-
(overlay-put ovl 'git-blame info)
407-
(overlay-put ovl 'help-echo
408-
(format-spec git-blame-mouseover-format spec))
409-
(if git-blame-use-colors
410-
(overlay-put ovl 'face (list :background
411-
(cdr (assq 'color (cdr info))))))
412-
(overlay-put ovl 'line-prefix
413-
(propertize (format-spec git-blame-prefix-format spec)
414-
'face 'git-blame-prefix-face))))))
388+
(with-current-buffer git-blame-file
389+
(save-excursion
390+
(let ((inhibit-point-motion-hooks t)
391+
(inhibit-modification-hooks t))
392+
(goto-char (point-min))
393+
(forward-line (1- start-line))
394+
(let* ((start (point))
395+
(end (progn (forward-line num-lines) (point)))
396+
(ovl (make-overlay start end))
397+
(hash (car info))
398+
(spec `((?h . ,(substring hash 0 6))
399+
(?H . ,hash)
400+
(?a . ,(git-blame-get-info info 'author))
401+
(?A . ,(git-blame-get-info info 'author-mail))
402+
(?c . ,(git-blame-get-info info 'committer))
403+
(?C . ,(git-blame-get-info info 'committer-mail))
404+
(?s . ,(git-blame-get-info info 'summary)))))
405+
(push ovl git-blame-overlays)
406+
(overlay-put ovl 'git-blame info)
407+
(overlay-put ovl 'help-echo
408+
(format-spec git-blame-mouseover-format spec))
409+
(if git-blame-use-colors
410+
(overlay-put ovl 'face (list :background
411+
(cdr (assq 'color (cdr info))))))
412+
(overlay-put ovl 'line-prefix
413+
(propertize (format-spec git-blame-prefix-format spec)
414+
'face 'git-blame-prefix-face)))))))
415415

416416
(defun git-blame-add-info (info key value)
417417
(nconc info (list (cons (intern key) value))))

0 commit comments

Comments
 (0)