From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Seeing which commits modified a range of lines? Date: Wed, 05 Nov 2014 09:37:19 +0100 Message-ID: <87lhnq3uww.fsf@thinkpad-t440p.tsdh.org> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1415176682 28104 80.91.229.3 (5 Nov 2014 08:38:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 5 Nov 2014 08:38:02 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Tom Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 05 09:37:55 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xlw6D-0008Nw-E5 for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Nov 2014 09:37:53 +0100 Original-Received: from localhost ([::1]:45046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xlw6C-0005T3-La for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Nov 2014 03:37:52 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xlw5t-0005ST-0r for help-gnu-emacs@gnu.org; Wed, 05 Nov 2014 03:37:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xlw5m-0004S9-I0 for help-gnu-emacs@gnu.org; Wed, 05 Nov 2014 03:37:32 -0500 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:50432) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xlw5m-0004S4-E6 for help-gnu-emacs@gnu.org; Wed, 05 Nov 2014 03:37:26 -0500 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id F3A8A20A1F for ; Wed, 5 Nov 2014 03:37:25 -0500 (EST) Original-Received: from frontend2 ([10.202.2.161]) by compute3.internal (MEProxy); Wed, 05 Nov 2014 03:37:25 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:from:to:cc:subject:references :date:in-reply-to:message-id:mime-version:content-type; s= smtpout; bh=E5QzsDWoFfK7Zn9Go6GbMTJxvDk=; b=rd+0rOY26u+aSNDlO4PF 4fBySwUKALN9/Np1+lhb+tOc613WuaSEsmOGhu8aJc+nHoKOKbtxHP8S4T3SBfhz gQhYYPcSDGRA1mDdVbGAK98kToi7i6RTtZHmlJNBq9Ln4XHSLOGG4ETECL2f27xI nrbUrQqcYU4x+FQh3SXalP0= X-Sasl-enc: vCLHb1LL+qGwRtUL7u8Cd8ZFHsf0VTtOmz2rg9rfZAti 1415176645 Original-Received: from thinkpad-t440p.tsdh.org (unknown [2.162.240.213]) by mail.messagingengine.com (Postfix) with ESMTPA id ECF5968013F; Wed, 5 Nov 2014 03:37:24 -0500 (EST) Mail-Followup-To: Tom , help-gnu-emacs@gnu.org In-Reply-To: (Tom's message of "Tue, 4 Nov 2014 20:13:38 +0000 (UTC)") User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.111.4.28 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100758 Archived-At: Tom 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