title: mercurial subrepos at the current revision of a specific branch
body: <p>I'm quite new to mercurial, I've read a lot of topics on this subject but I still can't understand if I can achieve what I'm trying to do.</p>
  
  <p>Basically I'd be interested in cloning the current revision of a branch from a main repository and its subrepos in a single command (acting on the main repo). I will try to explain it better in a moment.</p>
  
  <p>Let's say that I separated my code into modules (only one module in the example below). I'd like to have each module in its own repository, and a master repo (the one that has the .hgsub) as a glue to keep all the subrepos in place. The master repo just contains .hgsub and a script which (1) <code>hg archive</code> each subrepo in a predefined directory and (2) performs an out-of-source build of the code. All development, commit, push, pull, merge is done in the individual subrepos.</p>
  
  <pre><code># create a module (subrepo of the master)
  hg init subrepo
  cd subrepo/
  echo "a file" &gt; aFile.c
  echo "another file" &gt; anotherFile.txt
  hg add
  hg ci -m "initial rev of subrepo"
  
  # create the main (master) repo &amp; add the reference to subrepo
  cd ../
  hg init main
  cd main
  hg clone ../subrepo subrepo
  echo subrepo = ../subrepo &gt; .hgsub
  echo hg archive and out-of-source build &gt; build.script
  hg add
  hg ci -m "initial rev of main repo"
  </code></pre>
  
  <p>So far, so good. If I <code>hg clone main</code> I get the current revision of the default branch of subrepo, as expected.</p>
  
  <p>BUT, let's imagine now that I'm ready to ship my code into a release: the 1.0.0. I'd do as follows.</p>
  
  <pre><code># create the branch 1.0 to manage the bug fixes to 1.0.0 and furthers
  cd ../subrepo/
  hg branch 1.0
  hg ci -m "creating the branch 1.0"
  
  # backstep to the main line to carry on the development of new features
  hg up default 
  echo "working in the main line" &gt; aNewFeature.c
  hg add
  hg ci -m "carrying on the development in the main line (a new feature)"
  hg glog 
  @  changeset:   2:c499329c2729
  |  tag:         tip
  |  parent:      0:50d4522a99ea
  |  user:        XXXX
  |  date:        Tue Dec 07 16:13:28 2010 +0100
  |  summary:     carrying on the development in the main line (a new feature)
  |
  | o  changeset:   1:0a81043e6e8a
  |/   branch:      1.0
  |    user:        XXXX
  |    date:        Tue Dec 07 16:12:02 2010 +0100
  |    summary:     creating the branch 1.0
  |
  o  changeset:   0:50d4522a99ea
     user:        XXXX
     date:        Tue Dec 07 15:52:57 2010 +0100
     summary:     initial rev of subrepo
  </code></pre>
  
  <p>And here's where the problems happen. How do I change the master repo to get the current revision of the default or, eventually, the 1.0 branch of subrepo, when I perform <code>hg clone</code>?</p>
  
  <p>I would have said that this worked.</p>
  
  <pre><code># replicate the branch structure also in the main repo
  cd ../main/
  hg branch 1.0
  echo subrepo = ../subrepo -r 1.0 &gt; .hgsub
  hg ci -m "adding -r 1.0 to .hgsub"
  hg up default 
  echo subrepo = ../subrepo -r default &gt; .hgsub
  hg ci -m "adding -r default to .hgsub"
  hg glog 
  @  changeset:   2:f97c90a31a21
  |  tag:         tip
  |  parent:      0:1fd6b5d528b4
  |  user:        XXXX
  |  date:        Tue Dec 07 16:22:05 2010 +0100
  |  summary:     adding -r default to .hgsub
  |
  | o  changeset:   1:3d9ed2f8b026
  |/   branch:      1.0
  |    user:        XXXX
  |    date:        Tue Dec 07 16:21:32 2010 +0100
  |    summary:     adding -r 1.0 to .hgsub
  |
  o  changeset:   0:1fd6b5d528b4
     user:        XXXX
     date:        Tue Dec 07 15:55:53 2010 +0100
     summary:     initial rev of main repo
  </code></pre>
  
  <p>But when I <code>hg clone</code> the main repo, I get</p>
  
  <pre><code>cd /a/directory
  hg clone /path/to/main -r 1.0 main
  requesting all changes
  adding changesets
  adding manifests
  adding file changes
  added 2 changesets with 3 changes to 2 files
  updating to branch 1.0
  pulling subrepo subrepo
  abort: HTTP Error 404: Not Found
  </code></pre>
  
  <p>Is there a way to achieve what I want to do?</p>
  
  <p>Thanks.</p>
  
  <p><strong>Quick update</strong>: just a minute after I posted the question, I found an <a href="https://stackoverflow.com/questions/3190386">answer</a> I've never seen before. There, it is suggested to use the following syntax</p>
  
  <pre><code>http://[user[:pass]@]host[:port]/[path][#revision]
  </code></pre>
  
  <p>by using <code>#branchname</code> in place of <code>#revision</code>. So, in my example, the following should work (for the branch 1.0):</p>
  
  <pre><code>echo subrepo = ../subrepo#1.0 &gt; .hgsub
  </code></pre>
  
  <p>But when I <code>hg clone</code> the master repo I get:</p>
  
  <pre><code>pulling subrepo subrepo
  abort: unsupported URL component: "1.0"
  Exception AttributeError: "'httprepository' object has no attribute 'urlopener'" in &lt;bound method httprepository.__del__ of &lt;mercurial.httprepo.httprepository object at 0x871332c&gt;&gt; ignored
  </code></pre>
  
  <p>I'm working on Ubuntu 10.04, mercurial 1.4.3-1. Suggestions?</p>
  
  <p>--
  Dylan</p>