kareila: Taking refuge from falling debris under a computer desk. (computercrash)
kareila ([personal profile] kareila) wrote in [site community profile] dw_dev2010-07-09 10:48 pm

Mercurial: (lack of) use of "hg rename"

I've been reading the O'Reilly Mercurial guide, and one item I've run into is the 'hg rename' command for renaming files. We have NOT been using this. Instead, we've been removing the old file and adding the new file.

This is bad for a couple of reasons. One, recent changes to the old file can get dropped on the floor (this has happened at least once). Two, there's a discontinuity in the revision history. You can still access the revision history of the older file under the original file name, but it would be nicer for the entire revision history to remain easily accessible.

Looking Forward



There are a couple of options you can set up in your .hgrc to help with this:

[diff]
git = true


This will tell hg to use "git-style" diffs, which show that a file has been renamed, not add/removed. There are other differences, such as permission changes, that are ignored by the default diff as well.

[defaults]
addremove = --similarity 100


This tells the "hg addremove" command (which should be executed before every commit, probably - how often do committers forget to add new files to the repo?) to detect when the same file has been removed and readded under a different name, and treat it as a rename instead. Presumably values less than 100 allow fuzzier matching.

Looking Backward



I couldn't figure out a way to correct the revision history in our repository without some hideous branch merging scheme for each changeset containing a failed rename, so for now I'll just make a list of the files that should have been renamed and weren't.

27f1a0767ecd: htdocs/userinfo.bml -> htdocs/profile.bml
27f1a0767ecd: htdocs/userinfo.bml.text -> htdocs/profile.bml.text
8428f0b6ae2d: htdocs/translate/* -> htdocs/admin/translate/*
bbe8245e97be: htdocs/mobile/friends.bml -> htdocs/mobile/read.bml
0b30744ab665: htdocs/syn/* -> htdocs/feeds/*
4f61e7788b51: htdocs/editpics.bml -> htdocs/editicons.bml
4f61e7788b51: htdocs/editpics.bml.text -> htdocs/editicons.bml.text
4f61e7788b51: htdocs/stc/editpics.css -> htdocs/stc/editicons.css
4f61e7788b51: htdocs/js/editpics.js -> htdocs/js/editicons.js
8e48610e9122: cgi-bin/talklib.pl -> cgi-bin/LJ/Talk.pm
e932a96a1e51: cgi-bin/parsefeed.pl -> cgi-bin/LJ/ParseFeed.pm
246fde8dc6bf: cgi-bin/cleanhtml.pl -> cgi-bin/LJ/CleanHTML.pm
f8cfab97cc4b: cgi-bin/supportlib.pl -> cgi-bin/LJ/Support.pm
798902bff009: cgi-bin/taglib.pl -> cgi-bin/LJ/Tags.pm
28e0103cbb09: cgi-bin/synlib.pl -> cgi-bin/LJ/Syn.pm
1ad1d37c54ab: cgi-bin/LJ/Event/Befriended.pm -> cgi-bin/LJ/Event/AddedToCircle.pm
1ad1d37c54ab: cgi-bin/LJ/Event/Defriended.pm -> cgi-bin/LJ/Event/RemovedFromCircle.pm
2732c4614ced: cgi-bin/ljlinks.pl -> cgi-bin/LJ/Links.pm
780a3e3275f7: cgi-bin/ljhooks.pl -> cgi-bin/LJ/Hooks.pm
e8d5bfb23489: cgi-bin/ljlang.pl -> cgi-bin/LJ/Lang.pm
f8cfab97cc4b: cgi-bin/supportlib.pl -> cgi-bin/LJ/Support.pm
e808c7233f00: cgi-bin/schoollib.pl -> cgi-bin/LJ/Schools.pm (since deleted)
29f13c2dc059: cgi-bin/ljmood.pl -> cgi-bin/DW/Mood.pm


To be clear, I am not placing blame here, but I would like for us all, and most especially my fellow committers, to be aware of the issue and attempt to do the right thing in the future. :)

Post a comment in response:

If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org