Many Projects/Repositories and common Libraries

Steven Scott chowarmaan at gmail.com
Wed Jan 12 09:39:34 CST 2011


On Tue, Jan 11, 2011 at 6:39 AM, Martin Geisler <mg at aragost.com> wrote:
> Steven Scott <chowarmaan at gmail.com> writes:
>
>>       I have a new user question so I try to get the most out of
>> Mercurial at the beginning, and not make any bad assumptions/mistakes
>> when starting out. I have a number of projects that I want to place
>> into repositories. As a new user, I have read that it is best to place
>> each project into its own repository. However, I also have a common
>> library/API that is used by a number of those projects. I want to use
>> the library at a version level and be able to replace/update the
>> library in any project at any time. Is it still best to keep
>> individual repositories and then copy the library into the directory
>> of the project as it changes? Is there a way to get it to be copied on
>> a change in case another developer changes the library? Ideally, this
>> would be at a release point (labeled, etc...).
>
> This sounds like an ideal use-case for Mercurial subrepositories. Please
> take a look at the guide we wrote here:
>
>  http://mercurial.aragost.com/kick-start/en/subrepositories/
>
> and the wiki
>
>  http://mercurial.selenic.com/wiki/Subrepository
>
> With subrepos, you have nested repositories. When you clone an outer
> repository, Mercurial will notice the subrepositories declared in a
> special .hgsub file in the root of the outer repo and use the
> information there to clone the nested subrepos. Mercurial then updates
> the subrepos to the versions stored in a second file -- .hgsubstate --
> which Mercurial maintains automatically.
>
> Because the subrepos are restored to the revisions stored in the
> .hgsubstate file, you are certain to get a consistent snapshot: what you
> committed a month ago will be what you get today.
>
> When new library versions are released, you do
>
>  cd foolib
>  hg pull
>  hg update 2.0
>  cd ..
>
> and then you test and adapt your application to the new version. When
> everything works, you do
>
>  hg commit -m 'Updated to foolib 2.0'
>
> and this will now record in the .hgsubstate file that the foolib subrepo
> should be checked out at version 2.0.
>
> The guide and the wiki should explain it! :)
>
> --
> Martin Geisler
>
> aragost Trifork
> Professional Mercurial support
> http://aragost.com/en/services/mercurial/blog/
>

Thanks for all the advice.  It sounds like the Sub-Repositories are
the way to go then.  I will look to include your suggestions.


More information about the Mercurial mailing list