Subdirectory clone
Kastner Masilko, Friedrich
kastner-masilko at at.festo.com
Thu Feb 9 08:07:32 UTC 2012
> From: mercurial-bounces at selenic.com [mailto:mercurial-bounces at selenic.com] On Behalf Of Sivaraj
>
> I want to clone subdirectories of a Mercurial repository. I am new to Mercurial, and I explored the help page about
> subrepos, but could not get enough details that I wanted. We have recently converted a CVS repo into Mercurial repo
> and we need to clone subdirectories of the repository like we checkout them as individual modules using CVS earlier.
>
> But I could not find ways to convert the existing subdirectories in a repo to subrepo in-place in the repo itself.
You can use "hg convert --filemap <filemap> <orig_repo> <subrepo>" to convert parts of your original repo into a subrepo. For this you have to create the <filemap> file. It is a simple text file containing 2 lines (in your case):
include path/to/subdirX
exclude path/to/subdirX/subdirXY
exclude path/to/subdirX/subdirXZ
exclude ...
...
rename path/to/subdirX .
The resulting subrepo would then contain only the history of all the files in subdirX, but moved to its root. You can then move this subrepo in place in the new infrastructure.
BUT: it is not the complete solution, and unfortunately I don't have a quick answer for the complete solution (besides "code it"). Here is why...
> main
> |
> |- .hg
> |- subdir1
> | |- .hg
> | |- subdir11
> | |- subdir12
> | | |- .hg
> | | |- subdir121
> | | |- subdir122
> | | |- .hgsub
> | |- .hgsub
> |- subdir2
> | |- .hg
> | |- subdir21
> | |- subdir22
> | |- .hgsub
> |- subdir3
> |- .hgsub
>
> Can any one help me how to achieve this in mercurial?
Your listing up there is not showing all necessary files. What you missed there are the .hgsubstate files, and those are essentially what holds the pointers between superrepo and subrepo. So while the above mentioned converting is giving you split-up subrepositories, it is not giving you the history of the .hgsubstate file INSIDE all superrepos. I.e.: you don't have the complete history of the tree as it was in the original repository.
To make that a bit more visual, let's assume the following history in the original repo:
4: Hacked A
3: Hacked B
2: Created project in subdir11 in subdir1 with file B
1: Hacked A
0: Created project subdir1 with file A
If you convert to subrepos and move the repos into place, you'll first get a tree like that:
main
|
|- .hg
|- subdir1
|- .hg
|- subdir11
| |- .hg
| |- B
|- A
If you go into all repositories and issue "hg log", you should have:
* main empty
* subdir1:
2: Hacked A
1: Hacked A
0: Created project subdir1 with file A
* subdir11:
1: Hacked B
0: Created project in subdir11 in subdir1 with file B
If you now edit the .hgsub files in all superrepos to contain the appropriate subrepo, add the .hgsub files, and commit the main repo with e.g. message "Created subrepos", you'll have the layout you suggested in your email (plus the automatically generated .hgsubstate files):
main
|
|- .hg
|- subdir1
| |- .hg
| |- subdir11
| | |- .hg
| | |- B
| |- .hgsub
| |- .hgsubstate
| |- A
|- .hgsub
|- .hgsubstate
A "hg log" would give you:
* main:
0: Created subrepos
* subdir1:
3: Created subrepos
2: Hacked A
1: Hacked A
0: Created project subdir1 with file A
* subdir11:
1: Hacked B
0: Created project in subdir11 in subdir1 with file B
If you then examine the .hgsubstate files, you'd see that the one in main points to revision 3 of subdir1 and the one in subdir1 points to revision 1 of subdir11.
I believe this is not what you want, though. It COULD make sense if the subrepos are individual projects per se. But if the subrepos are part of a larger project, and are revision-dependent on each other, you'd rather aim for logs like that:
* main:
4: Hacked A (changes .hgsubstate to point to 4 of subdir1)
3: Hacked B (changes .hgsubstate to point to 3 of subdir1)
2: Created project in subdir11 in subdir1 with file B (changes .hgsubstate to point to 2 of subdir1)
1: Hacked A (changes .hgsubstate to point to 1 of subdir1)
0: Created project subdir1 with file A (adds .hgsub, .hgsubstate - the later points to 0 of subdir1)
* subdir1:
4: Hacked A (changes A)
3: Hacked B (changes .hgsubstate to point to 1 of subdir11)
2: Created project in subdir11 in subdir1 with file B (adds .hgsub, .hgsubstate - the later points to 0 of subdir11)
1: Hacked A (changes A)
0: Created project subdir1 with file A (adds A)
* subdir11:
1: Hacked B (changes B)
0: Created project in subdir11 in subdir1 with file B (adds B)
Unfortunately, this is today not possible with automatic conversion AFAIK.
regards,
Fritz
Development Software Systems
Festo Gesellschaft m.b.H.
Linzer Strasse 227
Austria - 1140 Wien
Firmenbuch Wien
FN 38435y
UID: ATU14650108
Tel: +43(1)91075-198
Fax: +43(1)91075-282
www.festo.at
Der Inhalt dieses E-Mails ist ausschliesslich fuer den bezeichneten Adressaten bestimmt. Jede Form der Kenntnisnahme,
Veroeffentlichung, Vervielfaeltigung oder Weitergabe des Inhalts dieses E-Mails durch unberechtigte Dritte ist unzulaessig. Wir
bitten Sie, sich mit dem Absender des E-Mails in Verbindung zu setzen, falls Sie nicht der Adressat dieses E-Mails sind und das
Material von Ihrem Computer zu loeschen.
This e-mail and any attachments are confidential and intended solely for the addressee. The perusal, publication, copying or
dissemination of the contents of this e-mail by unauthorised third parties is prohibited. If you are not the intended recipient of this
e-mail, please delete it and immediately notify the sender.
More information about the Mercurial
mailing list