annotate, file moves, and reindent/refactoring

Matt Mackall mpm at selenic.com
Wed Mar 28 14:28:33 CDT 2012


On Wed, 2012-03-28 at 11:40 -0700, L. David Baron wrote:
> So one of the basic use cases for the "hg annotate" command is to
> answer the question "when or why was this code originally added?".
> 
> The way I usually do this is to use annotate to find the time the
> code was last modified, look at that revision to see if it's what I
> want, and if it's not (e.g., refactoring, reindenting, etc.), rerun
> annotate passing the revision prior to that one.
> 
> The problem I keep running into with hg is that this doesn't work
> across file moves.

I recommend using hg serve + your web browser.

> 
> For example, in a clone of https://hg.csswg.org/test , I did:
> 
> $ cd approved/css3-mediaqueries/src
> $ hg ann test_media_queries.html
> [...snip...]
> 2519:     features = [ "max-aspect-ratio", "device-aspect-ratio" ];
> 2519:     for (i in features) {
> 2519:       feature = features[i];
> 2519:       expression_should_be_parseable(feature + ": 1/1");
> 2519:       expression_should_be_parseable(feature + ": 1  /1");
> 2519:       expression_should_be_parseable(feature + ": 1  / \t\n1");
> 2519:       expression_should_be_parseable(feature + ": 1/\r1");
> [...snip...]
> $ hg log -r2519
> changeset:   2519:39396e95328c
> user:        Ms2ger <ms2ger at gmail.com>
> date:        Tue Jan 17 14:31:01 2012 +0100
> summary:     Reindent run() function and remove carriage returns.
>  
> $ hg ann -r2518 test_media_queries.html 
> abort: approved/css3-mediaqueries/src/test_media_queries.html: no such file in rev 49e6d7b7f2f9

FYI, you probably want -r2519^.

> I really like that following moves is the default behavior of
> annotate -- it saves me having to do this extra step when annotating
> for file moves.  But the fact that I need to manually follow the
> moves in order to annotate an old revision makes this useless (and,
> in fact, harmful) in the cases where there's some other event I need
> to manually step through that precedes the move.
> 
> 
> There seem to be two different things the -r option to annotate
> could mean:
>  (1) Annotate the history of the argument at the revision given (as
>  implemented now)
>  (2) Annotate the history of the argument at the parent revision
>  using its history from the revision given (as would have helped
>  me).

We're philosophically bound to (1). But we might eventually implement
something like:

 hg annotate -r 2519^ "set:follow(somefile)"

..which will annotate all files in 2519 that are ancestors of somefile
in ".". And would automatically do the right thing for diff/cat/etc.
too. See "hg help filesets" for more on this "set:" business.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial mailing list