mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 08:18:15 +03:00
authormap: allow case-insensitive authormaps for easier conversions
This commit is contained in:
parent
482bd34c10
commit
0e3dd689bd
@ -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))
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user