mirror of
https://github.com/frej/fast-export.git
synced 2026-02-27 06:50:41 +01:00
Add support for git submodules
Mercurial supports not only submodules which are Mercurial repositories, but also Git and Subversion repositories. This patch adds support for submodules which are Git repositories to hg-fast-export. As submodules which are Git repositories won't need a mapping file we trigger the submodule update only on the occurence of the `.hgsubstate` file and push the check for a valid `submodule_mappings` to `refresh_gitmodules(ctx)`
This commit is contained in:
@@ -2,11 +2,21 @@
|
||||
|
||||
## Introduction
|
||||
|
||||
Subrepositories must first be converted in order for the conversion of
|
||||
the super repository to know how hg commits map to git commits in the
|
||||
sub repositories. When all subrepositories have been converted, a
|
||||
mapping file that maps the mercurial subrepository path to a converted
|
||||
git submodule path must be created. The format for this file is:
|
||||
hg-fast-export supports migrating mercurial subrepositories in the
|
||||
repository being converted into git submodules in the converted repository.
|
||||
|
||||
Git submodules must be git repositories while mercurial's subrepositories can
|
||||
be git, mercurial or subversion repositories. hg-fast-export will handle any
|
||||
git subrepositories automatically, any other kinds must first be converted
|
||||
to git repositories. Currently hg-fast-export does not support the conversion
|
||||
of subversion subrepositories. The rest of this page covers the conversion of
|
||||
mercurial subrepositories which require some manual steps:
|
||||
|
||||
The first step for mercurial subrepositories involves converting the
|
||||
subrepository into a git repository using hg-fast-export. When all
|
||||
subrepositories have been converted, a mapping file that maps the mercurial
|
||||
subrepository path to a converted git submodule path must be created. The
|
||||
format for this file is:
|
||||
|
||||
"<mercurial subrepo path>"="<git submodule path>"
|
||||
"<mercurial subrepo path2>"="<git submodule path2>"
|
||||
|
||||
@@ -141,6 +141,13 @@ def remove_gitmodules(ctx):
|
||||
wr('D %s' % submodule)
|
||||
wr('D .gitmodules')
|
||||
|
||||
def refresh_git_submodule(name,subrepo_info):
|
||||
wr('M 160000 %s %s' % (subrepo_info[1],name))
|
||||
sys.stderr.write("Adding/updating submodule %s, revision %s\n"
|
||||
% (name,subrepo_info[1]))
|
||||
return '[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (name,name,
|
||||
subrepo_info[0])
|
||||
|
||||
def refresh_hg_submodule(name,subrepo_info):
|
||||
gitRepoLocation=submodule_mappings[name] + "/.git"
|
||||
|
||||
@@ -171,7 +178,9 @@ def refresh_gitmodules(ctx):
|
||||
gitmodules=""
|
||||
# Create the .gitmodules file and all submodules
|
||||
for name,subrepo_info in ctx.substate.items():
|
||||
if name in submodule_mappings:
|
||||
if subrepo_info[2]=='git':
|
||||
gitmodules+=refresh_git_submodule(name,subrepo_info)
|
||||
elif submodule_mappings and name in submodule_mappings:
|
||||
gitmodules+=refresh_hg_submodule(name,subrepo_info)
|
||||
|
||||
if len(gitmodules):
|
||||
@@ -183,7 +192,7 @@ def export_file_contents(ctx,manifest,files,hgtags,encoding='',plugins={}):
|
||||
count=0
|
||||
max=len(files)
|
||||
for file in files:
|
||||
if submodule_mappings and file==".hgsubstate":
|
||||
if file==".hgsubstate":
|
||||
refresh_gitmodules(ctx)
|
||||
# Skip .hgtags files. They only get us in trouble.
|
||||
if not hgtags and file == ".hgtags":
|
||||
|
||||
Reference in New Issue
Block a user