From 1181a0af471fe473919b30f476a253a9ae2282b0 Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Fri, 10 May 2019 18:52:57 +0200 Subject: [PATCH] Allow name sanitizer to be disabled with --no-auto-sanitize Make it possible to completely disable the name sanitizer by the --no-auto-sanitize flag. Previously the sanitizer was run on user remapped names. As the sanitizer rewrites perfectly legal git names (such as __.*) this is probably not what the user wants. Closes #155. --- README.md | 6 ++++++ hg-fast-export.py | 10 ++++++++++ hg-fast-export.sh | 2 ++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 3329b7d..0a5673b 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,12 @@ name the -B and -T options allow a mapping file to be specified to rename branches and tags (respectively). The syntax of the mapping file is the same as for the author mapping. +When the -B and -T flags are used, you will probably want to use the +-n flag to disable the built-in (broken in many cases) sanitizing of +branch/tag names. In the future -n will become the default, but in +order to not break existing incremental conversions, the default +remains with the old behavior. + Content filtering ----------------- diff --git a/hg-fast-export.py b/hg-fast-export.py index 72d9c7f..4709276 100755 --- a/hg-fast-export.py +++ b/hg-fast-export.py @@ -31,6 +31,10 @@ cfg_export_boundary=1000 subrepo_cache={} submodule_mappings=None +# True if fast export should automatically try to sanitize +# author/branch/tag names. +auto_sanitize = None + def gitmode(flags): return 'l' in flags and '120000' or 'x' in flags and '100755' or '100644' @@ -226,6 +230,8 @@ def sanitize_name(name,what="branch", mapping={}): if name[0] == '.': return '_'+name[1:] return name + if not auto_sanitize: + return mapping.get(name,name) n=mapping.get(name,name) p=re.compile('([[ ~^:?\\\\*]|\.\.)') n=p.sub('_', n) @@ -532,6 +538,9 @@ if __name__=='__main__': parser=OptionParser() + parser.add_option("-n", "--no-auto-sanitize",action="store_false", + dest="auto_sanitize",default=True, + help="Do not perform built-in (broken in many cases) sanitizing of names") parser.add_option("-m","--max",type="int",dest="max", help="Maximum hg revision to import") parser.add_option("--mapping",dest="mappingfile", @@ -580,6 +589,7 @@ if __name__=='__main__': (options,args)=parser.parse_args() m=-1 + auto_sanitize = options.auto_sanitize if options.max!=None: m=options.max if options.marksfile==None: bail(parser,'--marks') diff --git a/hg-fast-export.sh b/hg-fast-export.sh index a4cb90e..e1f2f50 100755 --- a/hg-fast-export.sh +++ b/hg-fast-export.sh @@ -70,6 +70,8 @@ Options: -B Read branch map from file -T Read tags map from file -M Set the default branch name (defaults to 'master') + -n Do not perform built-in (broken in many cases) sanitizing + of branch/tag names. -o Use as branch namespace to track upstream (eg 'origin') --hg-hash Annotate commits with the hg hash as git notes in the hg namespace.