Skip to content

Commit

Permalink
back out 706fb17 and 58ba440 to stop munging our git shas
Browse files Browse the repository at this point in the history
  • Loading branch information
escapewindow committed Apr 25, 2013
1 parent 9edc7f1 commit f480d06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -3,7 +3,7 @@ PYTHON=python
help:
@echo 'Commonly used make targets:'
@echo ' tests - run all tests in the automatic test suite'
@echo ' all-version-tests - run all tests against many hg versions'
@echo ' all-version-tests - run all tests against many hg versions'
@echo ' tests-%s - run all tests in the specified hg version'

all: help
Expand Down
57 changes: 6 additions & 51 deletions hggit/git_handler.py
Expand Up @@ -32,8 +32,6 @@

RE_GIT_AUTHOR = re.compile('^(.*?) ?\<(.*?)(?:\>(.*))?$')

RE_GIT_SANITIZE_AUTHOR = re.compile('[<>\n]')

RE_GIT_AUTHOR_EXTRA = re.compile('^(.*?)\ ext:\((.*)\) <(.*)\>$')

# Test for git:// and git+ssh:// URI.
Expand Down Expand Up @@ -448,50 +446,7 @@ def export_hg_commit(self, rev, exporter):
return commit.id

def get_valid_git_username_email(self, name):
r"""Sanitize usernames and emails to fit git's restrictions.
The following is taken from the man page of git's fast-import
command:
[...] Likewise LF means one (and only one) linefeed [...]
committer
The committer command indicates who made this commit,
and when they made it.
Here <name> is the person's display name (for example
"Com M Itter") and <email> is the person's email address
("cm@example.com[1]"). LT and GT are the literal
less-than (\x3c) and greater-than (\x3e) symbols. These
are required to delimit the email address from the other
fields in the line. Note that <name> and <email> are
free-form and may contain any sequence of bytes, except
LT, GT and LF. <name> is typically UTF-8 encoded.
Accordingly, this function makes sure that there are none of the
characters <, >, or \n in any string which will be used for
a git username or email. Before this, it first removes left
angle brackets and spaces from the beginning, and right angle
brackets and spaces from the end, of this string, to convert
such things as " <john@doe.com> " to "john@doe.com" for
convenience.
TESTS:
>>> from mercurial.ui import ui
>>> g = GitHandler('', ui()).get_valid_git_username_email
>>> g('John Doe')
'John Doe'
>>> g('john@doe.com')
'john@doe.com'
>>> g(' <john@doe.com> ')
'john@doe.com'
>>> g(' <random<\n<garbage\n> > > ')
'random???garbage?'
>>> g('Typo in hgrc >but.hg-git@handles.it.gracefully>')
'Typo in hgrc ?but.hg-git@handles.it.gracefully'
"""
return RE_GIT_SANITIZE_AUTHOR.sub('?', name.lstrip('< ').rstrip('> '))
return name.lstrip('< ').rstrip('> ')

def get_git_author(self, ctx):
# hg authors might not have emails
Expand All @@ -504,8 +459,8 @@ def get_git_author(self, ctx):
a = RE_GIT_AUTHOR.match(author)

if a:
name = self.get_valid_git_username_email(a.group(1))
email = self.get_valid_git_username_email(a.group(2))
name = a.group(1)
email = a.group(2)
if a.group(3) != None and len(a.group(3)) != 0:
name += ' ext:(' + urllib.quote(a.group(3)) + ')'
author = self.get_valid_git_username_email(name) + ' <' + self.get_valid_git_username_email(email) + '>'
Expand Down Expand Up @@ -920,7 +875,7 @@ def get_changed_refs(self, refs, revs, force):
ctx = self.repo[rev]
if getattr(ctx, 'bookmarks', None):
labels = lambda c: ctx.tags() + [
fltr for fltr, bm
fltr for fltr, bm
in self._filter_for_bookmarks(ctx.bookmarks())
]
else:
Expand Down Expand Up @@ -1063,7 +1018,7 @@ def local_heads(self):
bms = bookmarks.parse(self.repo)
else:
bms = self.repo._bookmarks
return dict([(filtered_bm, hex(bms[bm])) for
return dict([(filtered_bm, hex(bms[bm])) for
filtered_bm, bm in self._filter_for_bookmarks(bms)])
except AttributeError: #pragma: no cover
return {}
Expand Down Expand Up @@ -1132,7 +1087,7 @@ def update_hg_bookmarks(self, refs):
real_branch_names = self.repo.branchmap()
bms = dict(
(
bm_name + self.branch_bookmark_suffix
bm_name + self.branch_bookmark_suffix
if bm_name in real_branch_names
else bm_name,
bms[bm_name]
Expand Down

0 comments on commit f480d06

Please sign in to comment.