tags:

views:

57

answers:

2

Mercurial has an

hg copy file file2

command and the change can propagate change at the first merge. The O'Reilly Mercurial book says that Mercurial is the only source control system that does that.

What is a practical use of this? The book mentioned making a copy of the file and do bug fix, so the bug fix can propagate back to the original file, but with version control, don't we usually edit the file directly, and if the bug fix works, then directly commit that file? Or even if for some reason we need to make a copy, we can cp file file2, test the fix, and mv file2 file to move that file back to the original file, and commit the file. What is a good example of using the hg copy feature?

A: 

Let's say you have a base class in a file. You want to make a derived class so you do an hg copy and customize the derived class by deleting some methods and making changes to others. Now your colleague in another branch has fixed a bug in the base class. When you do a merge, that bug fix will be merged into your derived class as well as your base class.

Karl Bielefeldt
is it true the timing has to be right? If I create the derived class and check in the code, and he fixed the bug, pull, merge, and commit, then the fix won't be there? It can also break the derived class by the way? Now if it is a config file we are copying, then we probably don't want to use `hg copy` since we don't want one change to propagate to the other.
動靜能量
I'm pretty sure it will work whoever does the merge. Yes, it could break the derived class or have another unwanted side effect. That's why you can disable the propagation if you prefer.
Karl Bielefeldt
+2  A: 

Here's one example I've used personally. Software package with complex configuration files sometimes provide examples with names like universe-wsgi.ini.sample (hi, galaxy), and as part of installation you're supposed to copy the .ini.sample file over to being a .ini file. If you do that using:

hg copy universe-wsgi.ini.sample universe-wsgi.ini

then whenever you update the software with hg pull ; hg update the new settings available in the sample will be added with their defaults to your customized version.

Ry4an
Our makefiles do this now for some of our own files, it's great to know that hg can handle it so nicely.
Geoffrey Zheng
It makes sense that this should happen, but I still find it really cool :)
shambulator