views:

82

answers:

4

I mainly code small programs for myself, but recently, I've been starting to code for my peers on my team. To that end, I've started using a Mercurial repository to maintain my code in some form of version control (specifically, Tortoise-Hg on Windows). I have many small scripts, each in their own directory, all under one repository. However, while reading Joel's Hg Tutorial, I tried cloning a directory for one of my bigger scripts to create a "stable" version and found I couldn't do it because the directory wasn't itself a repository.

So, I assume (and please correct me if I'm mistaken) that in order to use cloning properly, I'd have to create a repository for each script/directory. But.. would that be a "good idea" or a future maintenance nightmare waiting to happen?

Succinctly, do I keep all my (unrelated) scripts in one repository, or should I create a repository for each? Or some unknown third option?

A: 

Creating a separate repository for each actual directory would probably be a good idea, as it separates it from the rest of your code. Just as modularity in coding is beneficial, so is modularity in repositories. If you wanted to publish one of your scripts on something like GitHub, it is easier if the repos are already separate.

However, if you have a bunch of small scripts that are one file long, you probably are fine keeping them under a single repository. However, if you ever wanted to release the revisions of it, you would have to release all of them at once.

Chacha102
+1  A: 

Use separate repos for everything that you might want to use independently at some point. It's very easy to combine repos in the future and much harder to pull them apart. The subrepos feature (like svn externals) even lets you make an umbrella repo that includes all the small repos if that's still something you'd like to be able to clone in a single command.

Ry4an
Is there a Mercurial command that's analogous to `git filter-branch`? This is how you move things into subrepos with git. It's scary but easy enough once you learn it.
intuited
I've seen svn externals referred to as an anti-pattern; does subrepos share the same problems as svn externals?
romandas
@romandas It's not how I like to do things. I let dependencies be expressed by my build tools (ivy!) not by my source control. I think it brings better decoupling and better tracking of required versions at each point of development. http://stackoverflow.com/questions/2392404/dvcs-how-structure-with-large-integrated-code-base-with-multiple-projects-sharin/2393475#2393475
Ry4an
@intuited yeah, the convert command with a --filemap will let you split an existing repo up into parts without losing history.
Ry4an
+1 and accepted. I separated out my larger scripting efforts into their own repos and kept all the single file scripts in one repo.
romandas
+1  A: 
Norman Ramsey
A: 

Use a repository for each project and for each logical block of mini-projects.

hg subrepo functionality is not ready for prime-time yet, in my opinion; quite a few of the core hg commands don't understand subrepos and therefore you can stab yourself quite handily, especially with shared code. You can find more info about subrepos in the latest patch notes for hg.

Paul Nathan