Inspecting changes related to a specific region

11 views
Skip to first unread message

Lele Gaifax

unread,
Nov 10, 2014, 3:52:09 AM11/10/14
to ma...@googlegroups.com
Hi all,

a couple of days ago I needed to dig into the history of a region of one
source file. I started with "magit-blame", then tried "mo-git-blame",
because I found its "back and forth navigation" thru the changeset
slightly more intuitive (but that may be just ignorance on my part: for
example, I learned about "repeated M-x magit-blame" right then :-). At
last I found what I was looking for.

Anyway, yesterday I did remember about a related little function
appeared on comp.emacs.help by Tassilo Horn, and quickly tried it after
a few tweaks to adapt it to magit:

(defun git-commits-on-region (beg end)
(interactive "r")
(let ((start-line (line-number-at-pos beg))
(end-line (line-number-at-pos end))
(default-directory (magit-toplevel)))
(if default-directory
(let ((file (buffer-file-name))
(buffer (get-buffer-create (format "*git commits touching %s, lines %d to %d*"
(buffer-file-name) start-line end-line))))
(with-current-buffer buffer
(erase-buffer)
(call-process "git" nil t
t "log" "-L" (format "%d,%d:%s"
start-line end-line
(file-relative-name file)))
(diff-mode)
(goto-char (point-min)))
(display-buffer buffer))
(user-error "Probably not in a Git repo!"))))

It shows a single buffer, with all the changesets that touched the given
region of code.

I wonder if this could be a nice little feature to integrate into magit,
if it's not already there :-)

Thank you,
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
le...@metapensiero.it | -- Fortunato Depero, 1929.

Óscar Fuentes

unread,
Nov 10, 2014, 7:37:34 AM11/10/14
to ma...@googlegroups.com
Lele Gaifax <le...@metapensiero.it> writes:

[snip]

> It shows a single buffer, with all the changesets that touched the given
> region of code.
>
> I wonder if this could be a nice little feature to integrate into magit,
> if it's not already there :-)

FYI: this was implemented on Emacs development sources (what some day
will be Emacs 25) on 2014-11-05 as `vc-region-history'.

Reply all
Reply to author
Forward
0 new messages