mirror of
https://github.com/frej/fast-export.git
synced 2025-11-06 11:15:39 +01:00
Refactor refresh_gitmodules()
Use the change context substate field instead of manually parsing the `.hgsubstate` file.
This commit is contained in:
@@ -137,18 +137,9 @@ def remove_gitmodules(ctx):
|
|||||||
def refresh_gitmodules(ctx):
|
def refresh_gitmodules(ctx):
|
||||||
"""Updates list of ctx submodules according to .hgsubstate file"""
|
"""Updates list of ctx submodules according to .hgsubstate file"""
|
||||||
remove_gitmodules(ctx)
|
remove_gitmodules(ctx)
|
||||||
# Read .hgsubstate file in order to find the revision of each subrepo
|
|
||||||
data=ctx.filectx(".hgsubstate").data()
|
|
||||||
subHashes={}
|
|
||||||
for line in data.split('\n'):
|
|
||||||
if line.strip()=="":
|
|
||||||
continue
|
|
||||||
cols=line.split(' ')
|
|
||||||
subHashes[cols[1]]=cols[0]
|
|
||||||
|
|
||||||
gitmodules=""
|
gitmodules=""
|
||||||
# Create the .gitmodules file and all submodules
|
# Create the .gitmodules file and all submodules
|
||||||
for name in ctx.substate:
|
for name,subrepo_info in ctx.substate.items():
|
||||||
gitRepoLocation=submodule_mappings[name] + "/.git"
|
gitRepoLocation=submodule_mappings[name] + "/.git"
|
||||||
|
|
||||||
# Populate the cache to map mercurial revision to git revision
|
# Populate the cache to map mercurial revision to git revision
|
||||||
@@ -157,16 +148,19 @@ def refresh_gitmodules(ctx):
|
|||||||
load_cache(gitRepoLocation+"/hg2git-marks",
|
load_cache(gitRepoLocation+"/hg2git-marks",
|
||||||
lambda s: int(s)-1))
|
lambda s: int(s)-1))
|
||||||
|
|
||||||
(mapping_cache, marks_cache)=subrepo_cache[name]
|
(mapping_cache,marks_cache)=subrepo_cache[name]
|
||||||
if subHashes[name] in mapping_cache:
|
subrepo_hash=subrepo_info[1]
|
||||||
revnum=mapping_cache[subHashes[name]]
|
if subrepo_hash in mapping_cache:
|
||||||
|
revnum=mapping_cache[subrepo_hash]
|
||||||
gitSha=marks_cache[int(revnum)]
|
gitSha=marks_cache[int(revnum)]
|
||||||
wr('M 160000 %s %s' % (gitSha, name))
|
wr('M 160000 %s %s' % (gitSha,name))
|
||||||
sys.stderr.write("Adding submodule %s, revision %s->%s\n"
|
sys.stderr.write("Adding/updating submodule %s, revision %s->%s\n"
|
||||||
% (name,subHashes[name],gitSha))
|
% (name,subrepo_hash,gitSha))
|
||||||
gitmodules+='[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (name, name, submodule_mappings[name])
|
gitmodules+='[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (name,name,
|
||||||
|
submodule_mappings[name])
|
||||||
else:
|
else:
|
||||||
sys.stderr.write("Warning: Could not find hg revision %s for %s in git %s\n" % (subHashes[name],name,gitRepoLocation))
|
sys.stderr.write("Warning: Could not find hg revision %s for %s in git %s\n" %
|
||||||
|
(subrepo_hash,name,gitRepoLocation))
|
||||||
|
|
||||||
if len(gitmodules):
|
if len(gitmodules):
|
||||||
wr('M 100644 inline .gitmodules')
|
wr('M 100644 inline .gitmodules')
|
||||||
|
|||||||
Reference in New Issue
Block a user