changeset 1374:a17d8874a099

Added dynamic author mapping.
author Jerome M. BERGER <jeberger@free.fr>
date Thu, 28 Jan 2016 19:43:21 +0100
parents b072dc02d1e3
children abc87a62ff51
files hgsubversion/maps.py hgsubversion/svnmeta.py hgsubversion/wrappers.py tests/test_fetch_mappings.py
diffstat 4 files changed, 24 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/maps.py
+++ b/hgsubversion/maps.py
@@ -5,6 +5,7 @@ import os
 from mercurial import util as hgutil
 from mercurial.node import bin, hex, nullid
 
+import subprocess
 import svncommands
 import util
 
@@ -98,15 +99,20 @@ class AuthorMap(dict):
         if self.meta.caseignoreauthors:
             search_author = author.lower()
 
+        result = None
         if search_author in self:
             result = self.super.__getitem__(search_author)
-        elif self.meta.defaultauthors:
-            self[author] = result = '%s%s' % (author, self.defaulthost)
-            msg = 'substituting author "%s" for default "%s"\n'
-            self.meta.ui.debug(msg % (author, result))
-        else:
-            msg = 'author %s has no entry in the author map!'
-            raise hgutil.Abort(msg % author)
+        elif self.meta.mapauthorscmd:
+            self[author] = result = subprocess.check_output (
+                self.meta.mapauthorscmd % author, shell = True).strip()
+        if not result:
+            if self.meta.defaultauthors:
+                self[author] = result = '%s%s' % (author, self.defaulthost)
+                msg = 'substituting author "%s" for default "%s"\n'
+                self.meta.ui.debug(msg % (author, result))
+            else:
+                msg = 'author %s has no entry in the author map!'
+                raise hgutil.Abort(msg % author)
         self.meta.ui.debug('mapping author "%s" to "%s"\n' % (author, result))
         return result
 
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
@@ -55,6 +55,7 @@ class SVNMeta(object):
         self._gen_cachedconfig('lastpulled', 0, configname=False)
         self._gen_cachedconfig('defaultauthors', True)
         self._gen_cachedconfig('caseignoreauthors', False)
+        self._gen_cachedconfig('mapauthorscmd', None)
         self._gen_cachedconfig('defaulthost', self.uuid)
         self._gen_cachedconfig('usebranchnames', True)
         self._gen_cachedconfig('defaultmessage', '')
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -597,6 +597,7 @@ def rebase(orig, ui, repo, **opts):
 optionmap = {
     'tagpaths': ('hgsubversion', 'tagpaths'),
     'authors': ('hgsubversion', 'authormap'),
+    'mapauthorscmd': ('hgsubversion', 'mapauthorscmd'),
     'branchdir': ('hgsubversion', 'branchdir'),
     'trunkdir': ('hgsubversion', 'trunkdir'),
     'infix': ('hgsubversion', 'infix'),
--- a/tests/test_fetch_mappings.py
+++ b/tests/test_fetch_mappings.py
@@ -114,6 +114,15 @@ class MapTests(test_util.TestBase):
         self.assertEqual(self.repo['tip'].user(),
                         'evil@5b65bade-98f3-4993-a01f-b7a6710da339')
 
+    def test_author_map_mapauthorscmd(self):
+        repo_path = self.load_svndump('replace_trunk_with_branch.svndump')
+        ui = self.ui()
+        ui.setconfig('hgsubversion', 'mapauthorscmd', 'echo "svn: %s"')
+        commands.clone(ui, test_util.fileurl(repo_path),
+                       self.wc_path)
+        self.assertEqual(self.repo[0].user(), 'svn: Augie')
+        self.assertEqual(self.repo['tip'].user(), 'svn: evil')
+
     def _loadwithfilemap(self, svndump, filemapcontent,
             failonmissing=True):
         repo_path = self.load_svndump(svndump)