annotate, file moves, and reindent/refactoring

L. David Baron dbaron at dbaron.org
Wed Mar 28 13:40:09 CDT 2012


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.


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




This is failing because the file was moved more recently than the
reindenting:

$ hg log -r2809
changeset:   2809:b047c7e7c66b
user:        fantasai <fantasai.cvs at inkedblade.net>
date:        Wed Feb 29 19:05:51 2012 -0800
summary:     Move Media Queries test suite to Approved
$ hg exp 2809
[...snip...]
diff --git a/contributors/anne/submitted/mediaqueries/test_media_queries.html b/approved/css3-mediaqueries/src/test_media_queries.html
rename from contributors/anne/submitted/mediaqueries/test_media_queries.html
rename to approved/css3-mediaqueries/src/test_media_queries.html
[...snip...]



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).

I should probably get a bug filed on this, but I'm not quite sure
what that bug ought to suggest.  Should annotate have two different
revision arguments?  Should it have an option to toggle the
semantics of the current revision argument?  Should the behavior
simply be changed (perhaps in a way that doesn't change the behavior
of any cases that work correctly now, such as by trying to find the
file using (1) and if that fails trying (2))?

-David

-- 
𝄞   L. David Baron                         http://dbaron.org/   𝄂
𝄢   Mozilla                           http://www.mozilla.org/   𝄂


More information about the Mercurial mailing list