hg-fast-import.py: Sanitize ref names

At least the opensolaris hg repo has tag names containing '*',
so sanitize all branch and tag names roughly according to the
specs for git-check-ref-format(1).

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
This commit is contained in:
Rocco Rutte
2007-10-26 16:06:40 +02:00
parent 431c32de6b
commit 4cc930807d

View File

@@ -133,10 +133,31 @@ def is_merge(parents):
c+=1
return c>1
def sanitize_name(name,what="branch"):
"""Sanitize input roughly according to git-check-ref-format(1)"""
def dot(name):
if name[0] == '.': return '_'+name[1:]
return name
n=name
p=re.compile('([[ ^:?*]|\.\.)')
n=p.sub('_', n)
if n[-1] == '/': n=n[:-1]+'_'
n='/'.join(map(dot,n.split('/')))
p=re.compile('_+')
n=p.sub('_', n)
if n!=name:
sys.stderr.write('Warning: sanitized %s [%s] to [%s]\n' % (what,name,n))
return n
def export_commit(ui,repo,revision,marks,heads,last,max,count,authors,sob):
(revnode,_,user,(time,timezone),files,desc,branch,_)=get_changeset(ui,repo,revision,authors)
parents=repo.changelog.parentrevs(revision)
branch=sanitize_name(branch)
wr('commit refs/heads/%s' % branch)
wr('mark :%d' % (revision+1))
if sob:
@@ -220,6 +241,7 @@ def export_commit(ui,repo,revision,marks,heads,last,max,count,authors,sob):
def export_tags(ui,repo,marks_cache,start,end,count,authors):
l=repo.tagslist()
for tag,node in l:
tag=sanitize_name(tag,"tag")
# ignore latest revision
if tag=='tip': continue
rev=repo.changelog.rev(node)