Mercurial > hg > hg-git
changeset 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 | 2e8820592bd3 |
children | 753c89b5c0aa 797a3584c78f |
files | README.md hggit/git_handler.py |
diffstat | 2 files changed, 49 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/README.md +++ b/README.md @@ -150,6 +150,36 @@ [git] intree = True +git.authors +----------- + +Git uses a strict convention for "author names" when representing changesets, +using the form `[realname] [email address]`. Mercurial encourages this +convention as well but is not as strict, so it's not uncommon for a Mercurial +repo to have authors listed as simple usernames. hg-git by default will +translate such names using the email address `none@none`, which then shows up +unpleasantly on GitHub as "illegal email address". + +The `git.authors` option provides for an "authors translation file" that will +be used during outgoing transfers from mercurial to git only, by modifying +`hgrc` as such: + + [git] + authors = authors.txt + +Where `authors.txt` is the name of a text file containing author name translations, +one per each line, using the following format: + + johnny = John Smith <jsmith@foo.com> + dougie = Doug Johnson <dougiej@bar.com> + +Empty lines and lines starting with a "#" are ignored. + +It should be noted that **this translation is on the hg->git side only**. Changesets +coming from Git back to Mercurial will not translate back into hg usernames, so +it's best that the same username/email combination be used on both the hg and git sides; +the author file is mostly useful for translating legacy changesets. + git.branch_bookmark_suffix ---------------------------
--- 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)