Is it possible to peg a Mercurial subrepo to a spe

2019-05-04 09:56发布

问题:

I'm migrating a set of projects from Subversion to Mercurial. The projects currently use svn:externals to pull code from one into the others. I've been following the recommendation to point externals to a specific revision number and manually update it as needed (so that when I update to a past revision of the main project, I get the past version of the externals too).

The way to do externals in Mercurial seems to be with subrepos, but I don't see a way to peg them to a specific revision - it looks like Hg will always update the subrepos to the latest revision whenever I update the main repo. Is that correct? And is there a way to work around it?

回答1:

In your .hgsub file you could use the http://[user[:pass]@]host[:port]/[path][#revision] (or local/filesystem/path[#revision]) syntax (see hg help urls for more examples) to anchor the subrepo to a specific revision. For that revision string you could even use #branchname or #tagname so that you track the tip of a specific branch (ex stable) or a moveable tag (ex: release) so that you only get the new version when a branch or tag on the remote subrepo are updated.



回答2:

(copied from my comment above)

Turns out I was wrong. It doesn't update to the latest revision, it updates to the revision specified in the .hgsubstate file, which is version controlled and automatically updated at each commit. So this is actually easier than SVN externals since the revision doesn't have to be manually re-pegged; each revision of the main repo is automatically associated with the corresponding revisions of the subrepos.



回答3:

It does seem that Mercurial subrepos are always updated to the latest tip of the remote repository.

I propose that, if you are using a particular version of a remote repository and updating that version only infrequently, it's better to fold that revision into your main repository. This means you are no longer dependent on the external source for a checkout.