[PATCH] Sanitize colon in tag name

13 views
Skip to first unread message

Sebastian Schmidt

unread,
May 27, 2012, 9:46:40 AM5/27/12
to hg-...@googlegroups.com
Besides replacing a space to an underscore when converting hg tags
to git also deal with a colon the same way.
---
hggit/git_handler.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/hggit/git_handler.py b/hggit/git_handler.py
index 98fc96e..0b71a61 100644
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -1,4 +1,4 @@
-import os, math, urllib, re
+import os, math, urllib, re, string

from dulwich.errors import HangupException, GitProtocolError
from dulwich.index import commit_tree
@@ -767,6 +767,9 @@ class GitHandler(object):
except (HangupException, GitProtocolError), e:
raise hgutil.Abort(_("git remote error: ") + str(e))

+ def sanitize_ref(self, ref):
+ return ref.translate(string.maketrans(" :", "__"))
+
def get_changed_refs(self, refs, revs, force):
new_refs = refs.copy()

@@ -791,7 +794,7 @@ class GitHandler(object):
]
else:
labels = lambda c: ctx.tags()
- prep = lambda itr: [i.replace(' ', '_') for i in itr]
+ prep = lambda itr: [self.sanitize_ref(i) for i in itr]

heads = [t for t in prep(labels(ctx)) if t in self.local_heads()]
tags = [t for t in prep(labels(ctx)) if t in self.tags]
@@ -902,7 +905,7 @@ class GitHandler(object):
def export_hg_tags(self):
for tag, sha in self.repo.tags().iteritems():
if self.repo.tagtype(tag) in ('global', 'git'):
- tag = tag.replace(' ', '_')
+ tag = self.sanitize_ref(tag)
self.git.refs['refs/tags/' + tag] = self.map_git_get(hex(sha))
self.tags[tag] = hex(sha)

--
1.7.10

Augie Fackler

unread,
Jun 1, 2012, 11:45:10 AM6/1/12
to hg-...@googlegroups.com
Could you add a test so we don't regress this?
> --
> You received this message because you are subscribed to the Google Groups "hg-git" group.
> To post to this group, send email to hg-...@googlegroups.com.
> To unsubscribe from this group, send email to hg-git+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hg-git?hl=en.
>

Reply all
Reply to author
Forward
0 new messages