From 4cc930807d314f63ee3867e1143c62e34bc15aa6 Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Fri, 26 Oct 2007 16:06:40 +0200 Subject: [PATCH] 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 --- hg-fast-export.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hg-fast-export.py b/hg-fast-export.py index 6b501f8..97dba5f 100755 --- a/hg-fast-export.py +++ b/hg-fast-export.py @@ -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) -- 2.11.4.GIT