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: Stefan Monnier
Subject: Re: Seeing which commits modified a range of lines?
Date: Wed, 05 Nov 2014 17:31:40 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

>> Oh, yes, I've been dreaming of it ever since I started using GNU Arch.
>> IIUC the only tool which does provide the needed info is Git where
>> you have "git log -L<begline>,<endline>:<file>".

BTW, I've just installed into trunk new code that gives access to this
functionality (called `vc-region-history' and which currently is only
supported for the Git backend).

> Out of the box, yes, but the point of vc is to make the life of the
> user easier and hide complexities.  So this functionality could be 
> implmented behind the scenes.

In theory, yes, but it can be pretty tedious to do (and the result can
be painfully slow) if done in Elisp.  In most cases it would be simpler
and much more efficient to implement it directly in the VCS tool.

> For example, VC tools provide annotate (blame) which can tell
> the last change for lines in a file.  So this can be called for
> a file and then the last changes for the interesting lines
> are known.

Actually, one of the reasons why I want vc-region-history is
specifically because annotate/blame does *not* always show you the
last revision.  The case where it doesn't is when you're looking for
a revision that just removed some lines.  Annotate/blame won't tell you
that between like N and N+1 there used to be some other lines and they
were removed in revision foo.

vc-region-history could be implemented for Bzr by running "bzr
log --show-diff" after which you "just" need to filter out the undesired
commits and patch hunks.

For a generic solution, you could write a loop that does:
- call annotate REV to find the last commit REV' that affected those lines.
- call diff between REV and REV' to adjust the line-numbers according to
  the changes that happened elsewhere in the mean time.
- call diff between REV'-1 and REV', filtering out the hunk that are
  outside of the affected region (and adjusting yet again the line numbers).
For most backends, such a loop will take forever to terminate (and of
course, it will miss some commits, as mentioned above).

An alternative is to do a "log" for the file, then a loop calling "diff"
for every revision in the log.  At that point you have the same data as
"bzr log --show-diff" and you can "just" filter out the commit and hunks
that don't affect the region.

Patch welcome.


        Stefan




reply via email to

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