# HG changeset patch # User Sean Farley # Date 1395678046 18000 # Node ID 49791c40a8a56243f68a7a76df5a5e782f2040ba # Parent a55339d35066a258cb1550e22660373a00cea6f9 maps: change authormap to initialize with an svnmeta object This refactoring will help us break AuthorMaps access of global options via ui.config allowing us to use svnmeta as the central store for reading and writing configuration options. diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -19,7 +19,7 @@ class AuthorMap(dict): the userid from Subversion is always compared lowercase. ''' - def __init__(self, ui, path, defaulthost=None): + def __init__(self, meta): '''Initialise a new AuthorMap. The ui argument is used to print diagnostic messages. @@ -27,20 +27,19 @@ class AuthorMap(dict): The path argument is the location of the backing store, typically .hg/svn/authors. ''' - 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: - self.defaulthost = '' + self.meta = meta + self.use_defaultauthors = self.meta.ui.configbool('hgsubversion', 'defaultauthors', True) + self.caseignoreauthors = self.meta.ui.configbool('hgsubversion', 'caseignoreauthors', False) + self.defaulthost = '' + if meta.defaulthost: + self.defaulthost = '@%s' % meta.defaulthost.lstrip('@') + self.super = super(AuthorMap, self) self.super.__init__() - self.load(path) + self.load(self.meta.authors_file) # append authors specified from the commandline - clmap = util.configpath(self.ui, 'authormap') + clmap = util.configpath(self.meta.ui, 'authormap') if clmap: self.load(clmap) @@ -52,10 +51,10 @@ class AuthorMap(dict): return writing = False - if path != self.path: - writing = open(self.path, 'a') + if path != self.meta.authors_file: + writing = open(self.meta.authors_file, 'a') - self.ui.debug('reading authormap from %s\n' % path) + self.meta.ui.debug('reading authormap from %s\n' % path) f = open(path, 'r') for number, line_org in enumerate(f): @@ -67,7 +66,7 @@ class AuthorMap(dict): src, dst = line.split('=', 1) except (IndexError, ValueError): msg = 'ignoring line %i in author map %s: %s\n' - self.ui.status(msg % (number, path, line.rstrip())) + self.meta.ui.status(msg % (number, path, line.rstrip())) continue src = src.strip() @@ -78,10 +77,10 @@ class AuthorMap(dict): if writing: if not src in self: - self.ui.debug('adding author %s to author map\n' % src) + self.meta.ui.debug('adding author %s to author map\n' % src) elif dst != self[src]: msg = 'overriding author: "%s" to "%s" (%s)\n' - self.ui.status(msg % (self[src], dst, src)) + self.meta.ui.status(msg % (self[src], dst, src)) writing.write(line_org) self[src] = dst @@ -107,11 +106,11 @@ class AuthorMap(dict): 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)) + self.meta.ui.debug(msg % (author, result)) else: msg = 'author %s has no entry in the author map!' raise hgutil.Abort(msg % author) - self.ui.debug('mapping author "%s" to "%s"\n' % (author, result)) + self.meta.ui.debug('mapping author "%s" to "%s"\n' % (author, result)) return result def reverselookup(self, author): diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- a/hgsubversion/svnmeta.py +++ b/hgsubversion/svnmeta.py @@ -39,7 +39,6 @@ class SVNMeta(object): self._gen_cachedconfig('defaulthost', self.uuid) self._gen_cachedconfig('usebranchnames', True) - author_host = self.ui.config('hgsubversion', 'defaulthost', uuid) branchmap = util.configpath(self.ui, 'branchmap') tagmap = util.configpath(self.ui, 'tagmap') filemap = util.configpath(self.ui, 'filemap') @@ -51,8 +50,7 @@ class SVNMeta(object): ui=self.repo.ui) self._layoutobj = None - self.authors = maps.AuthorMap(self.ui, self.authors_file, - defaulthost=author_host) + self.authors = maps.AuthorMap(self) self.branchmap = maps.BranchMap(self.ui, self.branchmap_file) if branchmap: 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 @@ -84,10 +84,15 @@ class MapTests(test_util.TestBase): def test_author_map_no_overwrite(self): cwd = os.path.dirname(__file__) orig = os.path.join(cwd, 'fixtures', 'author-map-test.txt') - new = open(self.authors, 'w') + # create a fake hgsubversion repo + repopath = os.path.join(self.wc_path, '.hg') + repopath = os.path.join(repopath, 'svn') + if not os.path.isdir(repopath): + os.makedirs(repopath) + new = open(os.path.join(repopath, 'authors'), 'w') new.write(open(orig).read()) new.close() - test = maps.AuthorMap(self.ui(), self.authors) + test = maps.AuthorMap(self.repo.svnmeta(skiperrorcheck=True)) fromself = set(test) test.load(orig) all_tests = set(test)