Skip to content

Commit

Permalink
Allow name sanitizer to be disabled with --no-auto-sanitize
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
frej committed Sep 13, 2019
1 parent 7ab47e0 commit 1181a0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------

Expand Down
10 changes: 10 additions & 0 deletions hg-fast-export.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
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'

Expand Down Expand Up @@ -226,6 +230,8 @@ def dot(name):
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)
Expand Down Expand Up @@ -532,6 +538,9 @@ def bail(parser,opt):

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",
Expand Down Expand Up @@ -580,6 +589,7 @@ def bail(parser,opt):
(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')
Expand Down
2 changes: 2 additions & 0 deletions hg-fast-export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Options:
-B <file> Read branch map from file
-T <file> Read tags map from file
-M <name> Set the default branch name (defaults to 'master')
-n Do not perform built-in (broken in many cases) sanitizing
of branch/tag names.
-o <name> Use <name> as branch namespace to track upstream (eg 'origin')
--hg-hash Annotate commits with the hg hash as git notes in the
hg namespace.
Expand Down

0 comments on commit 1181a0a

Please sign in to comment.