all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tsdh@gnu.org>
To: Tom <adatgyujto@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Seeing which commits modified a range of lines?
Date: Wed, 05 Nov 2014 09:37:19 +0100	[thread overview]
Message-ID: <87lhnq3uww.fsf@thinkpad-t440p.tsdh.org> (raw)
In-Reply-To: <loom.20141104T211202-703@post.gmane.org> (Tom's message of "Tue,  4 Nov 2014 20:13:38 +0000 (UTC)")

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	other threads:[~2014-11-05  8:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-04 20:13 Seeing which commits modified a range of lines? Tom
2014-11-05  8:37 ` Tassilo Horn [this message]
2014-11-05 20:30   ` Tom
2014-11-06  7:13     ` Tassilo Horn
2014-11-06 20:46       ` Tom
2014-11-07  7:53         ` Thien-Thi Nguyen
2014-11-07 21:42           ` Tom
2014-11-08  8:26             ` Thien-Thi Nguyen
     [not found] <mailman.12815.1415132057.1147.help-gnu-emacs@gnu.org>
2014-11-04 22:36 ` Stefan Monnier
2014-11-05 20:27   ` Tom
2014-11-05 22:31     ` Stefan Monnier
2014-11-06 20:56       ` Tom
     [not found]       ` <mailman.13069.1415307407.1147.help-gnu-emacs@gnu.org>
2014-11-06 22:42         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lhnq3uww.fsf@thinkpad-t440p.tsdh.org \
    --to=tsdh@gnu.org \
    --cc=adatgyujto@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.