cloning files without tracking changes

Jens Alfke jens at mooseyard.com
Wed Oct 3 11:43:04 CDT 2007


On 3 Oct '07, at 5:02 AM, Nenad Bulatovic wrote:

> Does Mercurial have some kind of mechanism to prevent certain files in
> repository from being modified?
> More precisely  - I need some files cloned from the repository, but  
> I don't
> want to track the changes in those files.
> When I do a 'hg add' on all files from my (very large) source tree,  
> I need
> some files in the repository to be intact (because, for example, build
> process modifies them) and I want to have a clean changeset with  
> files that
> only I have modified.

I'm not sure I understand your situation exactly, but...

Any file that gets modified by the build system isn't really part of  
your source tree. Instead, you should check in a clean "master copy"  
of the file under a different name, and then as part of the checkout  
or build process copy the master file to the working file that will be  
modified. Then you can add a line to your .hgignore file to tell Hg to  
ignore the working copy.

So for example, if the file in question is called dynamic.h ...
1. Check in a clean copy of the file as dynamic_master.h
2. Add a statement to your makefile that declares dynamic.h as  
dependent on dynamic_master.h, with the action simply being 'cp'. Or  
add the equivalent dependency in your IDE. Or add a post-update hook  
that does the copying (if the master header is newer.)
3. Add "dynamic.h" to the .hgignore file. (You probably want a path- 
specific pattern, which I don't remember how to do...)

Does that make sense in your situation?

(Actually, in my experience I've found it's not a good idea to have  
the build system modify files in place; it can lead to strange build  
failures. It's better to have it always copy a fixed starting file to  
a different destination. In this case, to always read  
dynamic_master.h, modify it, and write it out as dynamic.h.)

--Jens


More information about the Mercurial mailing list