From 581b1b3d1703357d619bc124527b00e585f1978e Mon Sep 17 00:00:00 2001 From: MokhamedDakhraui Date: Thu, 15 Aug 2019 03:13:52 +0300 Subject: [PATCH] Remove git submodules if .hgsubstate file was removed or emptied --- hg-fast-export.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hg-fast-export.py b/hg-fast-export.py index 897c2f0..72d9c7f 100755 --- a/hg-fast-export.py +++ b/hg-fast-export.py @@ -128,11 +128,14 @@ def get_author(logmessage,committer,authors): return committer def remove_gitmodules(ctx): - """Removes all submodules""" - # Remove all submodules as we don't detect deleted submodules properly - # in any other way. We will add the ones not deleted back again below. - for module in submodule_mappings.keys(): - wr('D %s' % module) + """Removes all submodules of ctx parents""" + # Removing all submoduies coming from all parents is safe, as the submodules + # of the current commit will be re-added below. A possible optimization would + # be to only remove the submodules of the first parent. + for parent_ctx in ctx.parents(): + for submodule in parent_ctx.substate.keys(): + wr('D %s' % submodule) + wr('D .gitmodules') def refresh_gitmodules(ctx): """Updates list of ctx submodules according to .hgsubstate file""" @@ -171,7 +174,7 @@ def export_file_contents(ctx,manifest,files,hgtags,encoding='',plugins={}): count=0 max=len(files) for file in files: - if submodule_mappings and ctx.substate and file==".hgsubstate": + if submodule_mappings and file==".hgsubstate": refresh_gitmodules(ctx) # Skip .hgtags files. They only get us in trouble. if not hgtags and file == ".hgtags": @@ -311,6 +314,8 @@ def export_commit(ui,repo,revision,old_marks,max,count,authors, if fn_encoding: filename=filename.decode(fn_encoding).encode('utf8') filename=strip_leading_slash(filename) + if filename=='.hgsubstate': + remove_gitmodules(ctx) wr('D %s' % filename) export_file_contents(ctx,man,added,hgtags,fn_encoding,plugins)