help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Seeing which commits modified a range of lines?


From: Tassilo Horn
Subject: Re: Seeing which commits modified a range of lines?
Date: Wed, 05 Nov 2014 09:37:19 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Tom <adatgyujto@gmail.com> writes:

Hi Tom,

> So I could select one or more consecutive lines and then call this
> function which would list all the commits which modified some of these
> selected lines, so I could see all changes that impacted this block of
> code.
>
> Can VC do this? If not then it could be a useful addition.

I don't think it can do this.  I've checked the docs for bzr log, hg
log, and git log, and it seems that git is the only one that can do what
you want, i.e., restrict the log to a range of lines in a file.  Well,
but if you use git, then this command should make you happy (only
briefly tested):

--8<---------------cut here---------------start------------->8---
(defun th/git-commits-on-region (beg end)
  (interactive "r")
  (let ((start-line (line-number-at-pos beg))
        (end-line (line-number-at-pos end)))
    (if (and (vc-root-dir)
             (eq 'Git (vc-backend buffer-file-name)))
        (let ((default-directory (vc-root-dir))
              (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 "Cannot find a vc root directory or not a Git repo!"))))
--8<---------------cut here---------------end--------------->8---

Just mark the region you want the log for and do `M-x
th/git-commits-on-region RET'.  It'll create a buffer

  *git commits touching foo.el, lines 17 to 35*

which shows you the log messages and diffs modifying those lines in
`diff-mode'.

Bye,
Tassilo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]