changeset 1097:e015cd34168d

authormap: allow case-insensitive authormaps for easier conversions
author maugustin
date Tue, 08 Jan 2013 10:44:38 +0100
parents 691078c03ed9
children 28116a204b6a
files hgsubversion/maps.py tests/test_fetch_mappings.py
diffstat 2 files changed, 33 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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))
--- 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 <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)