# HG changeset patch # User maugustin # Date 1357638278 -3600 # Node ID e015cd34168d9cc3bb1995b6b82d1574c092bb0a # Parent 691078c03ed9f2d69fa7b04235b7d2529ac0d4f6 authormap: allow case-insensitive authormaps for easier conversions diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -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)) diff --git a/tests/test_fetch_mappings.py b/tests/test_fetch_mappings.py --- a/tests/test_fetch_mappings.py +++ b/tests/test_fetch_mappings.py @@ -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 # stuffy\n') + authormap.write("Augie Fackler \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 ') + 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)