title: Creating Mercurial subrepositories, while maintaining the history
body: <p>I am about to make some major changes to my Mercurial repositories. As I am going to be using a <a href="http://mercurial.selenic.com/wiki/FeaturesOfLastResort" rel="nofollow noreferrer">Feature of Last Resort</a>, I am looking for some advice and reassurance that I am not doing something stupid.</p>
  
  <h1>Where I Am:</h1>
  
  <p>I have a Mercurial repository with a complete history of all of these files:</p>
  
  <pre><code>/source
      /secret_subsystem
      /unclassified_subsystem
      /common_files       
  </code></pre>
  
  <p>Source is the Mercurial repository.
  The secret subsystem folder contains code which is intellectual property we want to keep in-house.
  The unclassified subsystem folder contains code which we want to outsource to a third-party to maintain.
  The common files folder contains code that both subsystems depend on. We will be keeping ownership, but we want to share it with the third-party.</p>
  
  <p>Obviously, I can't just push out my whole repository to the third-party company. The third-party would see too much.</p>
  
  <h1>Where I Want To Be:</h1>
  
  <p><a href="http://mercurial.selenic.com/wiki/ConvertExtension" rel="nofollow noreferrer">Having</a> <a href="http://mercurial.aragost.com/kick-start/en/subrepositories/" rel="nofollow noreferrer">read</a> <a href="https://stackoverflow.com/questions/4602452/how-to-convert-an-existing-mercurial-repository-to-use-subrepositories-and-keep">up</a> <a href="http://www.selenic.com/mercurial/hg.1.html#graft" rel="nofollow noreferrer">on</a> <a href="http://mercurial.selenic.com/wiki/Subrepository" rel="nofollow noreferrer">subrepositories</a>, this is where I think I need to be:</p>
  
  <p>Have THREE subrepositories: secret_subsystem, unclassified_subsystem, common_files.
  Ensure there are no other files at the /source level, due to <a href="http://mercurial.selenic.com/wiki/Subrepository#Use_a_thin_shell_repository_to_manage_your_subrepositories" rel="nofollow noreferrer">this recommendation</a>.</p>
  
  <p>Have the outsourcers create a brand new respository at the source level on their machines, and two corresponding subrepositories.</p>
  
  <p>Push the unclassified_subsystem and common_files to the out-sourcer, pulling back unclassified_subsystem as required, pushing out new common_files repositories as required.</p>
  
  <h1>Maintaining History:</h1>
  
  <p>I would like to maintain the commit history, as much as practical, for all of the subsystems.</p>
  
  <p>To do this, I will run the <a href="http://mercurial.selenic.com/wiki/ConvertExtension" rel="nofollow noreferrer">hg convert</a> extension command three times, once for each subrepository. I will filter down to only the files that belong in each subrepository. I may also need to map filenames to move the files from ./common_files/foo.py to ./foo.py (for example).</p>
  
  <h1>My Questions:</h1>
  
  <p>1) Is dividing up a repository into subrepository a reasonable way of implementing security - viz. that a third-party can only see and edit some of our files?</p>
  
  <p>2) Is using <code>hg convert</code> a reasonable way to create a subrepository from an existing repository, while still maintaining the history?</p>
  
  <p>3) Will <code>hg convert</code>'s filter strip out (a) all commits messages about files NOT in the filtered respository? Will it filter out all diffs for files NOT in the filtered repository?</p>
  
  <p>There is another implied question: Am I heading into a world of hurt? If so, I will simply give up on retaining file histories, or even make them seperate repositories and forget about cross-repository commits.</p>