Environment variables and repository clones
Reading HgInit.com
I realized that cloning is a great way to work on experiments. A lot of times, the experiments开发者_开发问答 fail and one wants to go through the original code, and ideally, step through both at the same time to compare values etc. and see what went wrong. With the projects I am working on, this is a problem as they rely on environment variables for paths.
Is there a good workaround that will allow me to work on repository clones with projects that rely on environment variables? I am willing to declare more environment variables as long as it is not error prone and is scalable (that is, if an experiment with clone succeeds, I simply commit without worrying about changing anything relating to environment variables)
There are a couple ways I tend to approach this sort of situation.
Conditional compilation
Sometimes I'll use the existing DEBUG
symbol or make one of my own and do things like this to replace environment-based configuration:
#if EXPERIMENT
string myVar = "experimental value";
// or just look up a different envvar
#else
string myVar = Environment.GetEnvironmentVariable("myvar");
Normal Release/Debug builds won't contain it if you don't declare EXPERIMENT
anymore in the project settings, and it's easy enough to search for and edit back to normal.
Temporary patches
This is the method I prefer for experimental work, however. Conditional compilation will be easier if you've never worked with patches, but cleaning it up to remove the temporary changes takes longer, too.
I enable the mq
extension in Mercurial and create a new patch for most of the experimental work. I also create a patch on top of that patch for any throw-away changes such as hard-coding a file path or configuration value in order to test something.
HgInit.com doesn't go into patches, but I believe the Hg Book does. You will have to be careful of which patch is the topmost applied patch when making changes and remember to hg qrefresh
to update the patch.
精彩评论