diff --git a/hg-fast-export.py b/hg-fast-export.py index f46d85e..ab9f60d 100755 --- a/hg-fast-export.py +++ b/hg-fast-export.py @@ -141,33 +141,37 @@ def remove_gitmodules(ctx): wr('D %s' % submodule) wr('D .gitmodules') +def refresh_hg_submodule(name,subrepo_info): + gitRepoLocation=submodule_mappings[name] + "/.git" + + # Populate the cache to map mercurial revision to git revision + if not name in subrepo_cache: + subrepo_cache[name]=(load_cache(gitRepoLocation+"/hg2git-mapping"), + load_cache(gitRepoLocation+"/hg2git-marks", + lambda s: int(s)-1)) + + (mapping_cache,marks_cache)=subrepo_cache[name] + subrepo_hash=subrepo_info[1] + if subrepo_hash in mapping_cache: + revnum=mapping_cache[subrepo_hash] + gitSha=marks_cache[int(revnum)] + wr('M 160000 %s %s' % (gitSha,name)) + sys.stderr.write("Adding/updating submodule %s, revision %s->%s\n" + % (name,subrepo_hash,gitSha)) + return '[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (name,name, + submodule_mappings[name]) + else: + sys.stderr.write("Warning: Could not find hg revision %s for %s in git %s\n" % + (subrepo_hash,name,gitRepoLocation)) + return '' + def refresh_gitmodules(ctx): """Updates list of ctx submodules according to .hgsubstate file""" remove_gitmodules(ctx) gitmodules="" # Create the .gitmodules file and all submodules for name,subrepo_info in ctx.substate.items(): - gitRepoLocation=submodule_mappings[name] + "/.git" - - # Populate the cache to map mercurial revision to git revision - if not name in subrepo_cache: - subrepo_cache[name]=(load_cache(gitRepoLocation+"/hg2git-mapping"), - load_cache(gitRepoLocation+"/hg2git-marks", - lambda s: int(s)-1)) - - (mapping_cache,marks_cache)=subrepo_cache[name] - subrepo_hash=subrepo_info[1] - if subrepo_hash in mapping_cache: - revnum=mapping_cache[subrepo_hash] - gitSha=marks_cache[int(revnum)] - wr('M 160000 %s %s' % (gitSha,name)) - sys.stderr.write("Adding/updating submodule %s, revision %s->%s\n" - % (name,subrepo_hash,gitSha)) - gitmodules+='[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (name,name, - submodule_mappings[name]) - else: - sys.stderr.write("Warning: Could not find hg revision %s for %s in git %s\n" % - (subrepo_hash,name,gitRepoLocation)) + gitmodules+=refresh_hg_submodule(name,subrepo_info) if len(gitmodules): wr('M 100644 inline .gitmodules')