diff hggit/git_handler.py @ 450:163ac98569d3

- add "author file" extension, allows an author translation map to put more legit author names in the outgoing git repo
author Mike Bayer <mike_mp@zzzcomputing.com>
date Thu, 23 Feb 2012 13:49:07 -0500
parents e58a6d0b80e2
children 797a3584c78f
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -80,6 +80,8 @@
         else:
             self.gitdir = self.repo.join('git')
 
+        self.init_author_file()
+
         self.paths = ui.configitems('paths')
 
         self.branch_bookmark_suffix = ui.config('git', 'branch_bookmark_suffix')
@@ -95,6 +97,19 @@
             os.mkdir(self.gitdir)
             self.git = Repo.init_bare(self.gitdir)
 
+    def init_author_file(self):
+        self.author_map = {}
+        if self.ui.config('git', 'authors'):
+            with open(self.repo.wjoin(
+                self.ui.config('git', 'authors')
+            )) as f:
+                for line in f:
+                    line = line.strip()
+                    if not line or line.startswith('#'):
+                        continue
+                    from_, to = re.split(r'\s*=\s*', line, 2)
+                    self.author_map[from_] = to
+
     ## FILE LOAD AND SAVE METHODS
 
     def map_set(self, gitsha, hgsha):
@@ -401,6 +416,10 @@
         # hg authors might not have emails
         author = ctx.user()
 
+        # see if a translation exists
+        if author in self.author_map:
+            author = self.author_map[author]
+
         # check for git author pattern compliance
         regex = re.compile('^(.*?) ?\<(.*?)(?:\>(.*))?$')
         a = regex.match(author)