authormap: allow case-insensitive authormaps for easier conversions

This commit is contained in:
maugustin 2013-01-08 10:44:38 +01:00
parent 482bd34c10
commit 0e3dd689bd
2 changed files with 33 additions and 3 deletions

View File

@ -14,6 +14,9 @@ class AuthorMap(dict):
If the 'hgsubversion.defaultauthors' configuration option is set to false,
attempting to obtain an unknown author will fail with an Abort.
If the 'hgsubversion.caseignoreauthors' configuration option is set to true,
the userid from Subversion is always compared lowercase.
'''
def __init__(self, ui, path, defaulthost=None):
@ -26,6 +29,8 @@ class AuthorMap(dict):
'''
self.ui = ui
self.path = path
self.use_defaultauthors = self.ui.configbool('hgsubversion', 'defaultauthors', True)
self.caseignoreauthors = self.ui.configbool('hgsubversion', 'caseignoreauthors', False)
if defaulthost:
self.defaulthost = '@%s' % defaulthost.lstrip('@')
else:
@ -63,6 +68,9 @@ class AuthorMap(dict):
src = src.strip()
dst = dst.strip()
if self.caseignoreauthors:
src = src.lower()
if writing:
if not src in self:
self.ui.debug('adding author %s to author map\n' % src)
@ -83,9 +91,15 @@ class AuthorMap(dict):
as well as the backing store. '''
if author is None:
author = '(no author)'
if author in self:
result = self.super.__getitem__(author)
elif self.ui.configbool('hgsubversion', 'defaultauthors', True):
if self.caseignoreauthors:
search_author = author.lower()
else:
search_author = author
if search_author in self:
result = self.super.__getitem__(search_author)
elif self.use_defaultauthors:
self[author] = result = '%s%s' % (author, self.defaulthost)
msg = 'substituting author "%s" for default "%s"\n'
self.ui.debug(msg % (author, result))

View File

@ -93,6 +93,22 @@ class MapTests(test_util.TestBase):
all_tests = set(test)
self.assertEqual(fromself.symmetric_difference(all_tests), set())
def test_author_map_caseignore(self):
repo_path = self.load_svndump('replace_trunk_with_branch.svndump')
authormap = open(self.authors, 'w')
authormap.write('augie=Augie Fackler <durin42@gmail.com> # stuffy\n')
authormap.write("Augie Fackler <durin42@gmail.com>\n")
authormap.close()
ui = self.ui()
ui.setconfig('hgsubversion', 'authormap', self.authors)
ui.setconfig('hgsubversion', 'caseignoreauthors', True)
commands.clone(ui, test_util.fileurl(repo_path),
self.wc_path, authors=self.authors)
self.assertEqual(self.repo[0].user(),
'Augie Fackler <durin42@gmail.com>')
self.assertEqual(self.repo['tip'].user(),
'evil@5b65bade-98f3-4993-a01f-b7a6710da339')
def _loadwithfilemap(self, svndump, filemapcontent,
failonmissing=True):
repo_path = self.load_svndump(svndump)