From 12edc3aaf996b9491f5504401ffcaf1d7ef47175 Mon Sep 17 00:00:00 2001
From: Jeremy Stanley <fungi@yuggoth.org>
Date: Fri, 16 Jan 2015 19:35:13 +0000
Subject: [PATCH] Only decode email if already encoded

* gertty/gitrepo.py(CommitContext.decorateMessage): A regression was
introduced by 3e23dba where some platforms already used unicode for
the author.email and committer.email values. In those circumstances
attempting to decode from UTF-8 fails spectacularly, so now we only
decode when we need to.

Change-Id: I267a4cb7ff35a8c864a7f3396abd5bf44ecd1ffc
---
 gertty/gitrepo.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/gertty/gitrepo.py b/gertty/gitrepo.py
index 728e5c0..182a71e 100644
--- a/gertty/gitrepo.py
+++ b/gertty/gitrepo.py
@@ -83,12 +83,18 @@ class CommitContext(object):
             commit.authored_date, commit.author_tz_offset)
         commit_date = self.decorateGitTime(
             commit.committed_date, commit.committer_tz_offset)
+        if type(author.email) is unicode:
+            author_email = author.email
+        else:
+            author_email = unicode(author.email, 'utf8')
+        if type(committer.email) is unicode:
+            committer_email = committer.email
+        else:
+            committer_email = unicode(committer.email, 'utf8')
         return [u"Parent: %s\n" % parentsha,
-                u"Author: %s <%s>\n" % (author.name,
-                                        unicode(author.email, 'utf8')),
+                u"Author: %s <%s>\n" % (author.name, author_email),
                 u"AuthorDate: %s\n" % author_date,
-                u"Commit: %s <%s>\n" % (committer.name,
-                                        unicode(committer.email, 'utf')),
+                u"Commit: %s <%s>\n" % (committer.name, committer_email),
                 u"CommitDate: %s\n" % commit_date,
                 u"\n"] + commit.message.splitlines(True)