1

Summarized questions:

What is the simplest (and best) way to shift a group of files from an existing repository to a new sub repository, so those files can be integrated with other parent repositories, some of which may not yet exist?

Do files in subrepositories need to be in discrete folders, or can they exist alongside other files?

Detailed Questions:

I have begun the process of creating multiple repositories representing several projects that have shared components, and that is going well, thanks to SO and some helpful answers to my question here

As I move on to adding a second project I notice there are a few files in my projects that are duplicated, and are essentially the same thing, with enough similarity to warrant taking them out of a main project repository and creating a new subrepository so they can be

  1. used by any new projects I begin, and
  2. removed from other existing repositories, since they are identical.

I am assuming the best way is to simply create a new repository, move the files across on the local file system, push both repositories, and then create a .hgsub file and proceeed as in the answer to my earlier question. This would obviously then shift the files concerned to a subfolder in the local file system under each main project, which i can live with, but it does raise the hypothetical question - is it possible to have a list of files in a repository that are effectively part of a sub repository but reside alongside other files (i.e. not in a sub folder).

If I wanted to (for example) have a "acme.h" file in each project that is part of another repository could I do this? as it happens, I don't need to do this at this point in time, and in my current situation it would be better from a design point of view to have the files I need to "refactor" into another repository in their own subfolder, however that might not always be the case. I use refactor in quotes here, as strictly speaking it's more about refactoring duplicated files that is refactoring code - however the same principle applies.

hopefully my questions are succinct enough to be answered without too much more explanation.

Community
  • 1
  • 1
unsynchronized
  • 4,828
  • 2
  • 31
  • 43

1 Answers1

2

Thanks for summary, makes it much easier to answer!

What is the simplest (and best) way to shift a group of files from an existing repository to a new sub repository, so those files can be integrated with other parent repositories, some of which may not yet exist?

You can use the convert extension to extract a directory from an existing Mercurial repository. You'll want to use the --filemap flag and in the filemap you include the directory you want and rename it to the root. See hg help convert for more info.

After you get a smaller repository with the

Do files in subrepositories need to be in discrete folders, or can they exist alongside other files?

They must be in their own folders. This is simply because that's how a repository looks like in Mercurial, Git, Subversion, ... When you're dealing with subrepositories, then Mercurial is not tracking the files inside the subrepo: it's just asking some (other) system to make a checkout of repository foo at some location.

So when your .hgsub file has

foo = foo
bar = [git]bar
baz = [svn]baz

then Mercurial will notice this on hg update and run

hg clone default-path-of-this-repo/foo foo
git clone default-path-of-this-repo/bar bar
svn checkout default-path-of-this-repo/baz baz

for your. This explains why subrepostories are directories in the outer repository: that's simply what a clone/checkout looks like these days.

As you can see, subrepositories can be of different types. It's conceivable that someone could add a RCS subrepository type for tracking individual files. They would then not have to live in a directory.

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
  • not sure if this warrants a whole new question, but your comments above raise an interesting side question: some of my third party code is in folders i downloaded a while ago from opensource efforts on github. is it possible to have mercurial "know" about those git server urls (and revisions), so i can then have mercurial clone it direct from there when i clone the parent repos? (rather than just have them as mercurial sub repos that happen to contain files that are also stored on github) if you prefer i can ask it as another question and link to it here – unsynchronized Jan 18 '12 at 22:01
  • 1
    I think that does warrent a new question — it's a five line comment :-) Please ask each question in a separate question. – Martin Geisler Jan 18 '12 at 22:06
  • ahh.. should have googled it myself... i just discovered this http://mercurial.selenic.com/wiki/Subrepository?action=show&redirect=subrepos#Git_subrepositories which i think answers my question. i will leave it there for anyone who come searching, and will ask anyway, as it does not seem to have been asked before. – unsynchronized Jan 18 '12 at 22:07
  • 1
    Ah, good that you figured it out yourself. Feel free to upvote my answer if you feel you learned something from it. – Martin Geisler Jan 18 '12 at 22:19
  • sorry, i keep forgetting about the upvoting. the upvotes are on me. I have posted a new question which incorporates the above, and develops it further – unsynchronized Jan 18 '12 at 22:38
  • 1
    Thanks, you're right they're free so I feel they should be used generously (I already used 20 today). Thanks for asking [another good question](http://stackoverflow.com/q/8918546/110204)! I've added an answer. – Martin Geisler Jan 18 '12 at 22:51