diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-01-07 15:35:55 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-01-07 15:35:55 +0100 |
commit | f4a49ff2dddc66bbe25af554caba2351fbf21702 (patch) | |
tree | 54ba82b7490038b911fc46bc1407cd7955bd7edf /git/refs/log.py | |
parent | 45eb728554953fafcee2aab0f76ca65e005326b0 (diff) | |
parent | c6ee00d0dadcd7b10d60a2985db4fe137ca7cfed (diff) | |
download | gitpython-f4a49ff2dddc66bbe25af554caba2351fbf21702.tar.gz |
Merge branch 'firm1-commit_by_actor'
Diffstat (limited to 'git/refs/log.py')
-rw-r--r-- | git/refs/log.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/git/refs/log.py b/git/refs/log.py index 8ce98d30..f8dc88da 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -18,6 +18,7 @@ from git.objects.util import ( altz_to_utctz_str, ) from git.compat import ( + PY3, xrange, string_types, defenc @@ -32,16 +33,30 @@ __all__ = ["RefLog", "RefLogEntry"] class RefLogEntry(tuple): """Named tuple allowing easy access to the revlog data fields""" - _fmt = "%s %s %s <%s> %i %s\t%s\n" _re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$') __slots__ = tuple() def __repr__(self): """Representation of ourselves in git reflog format""" + res = self.format() + if PY3: + return res + else: + # repr must return a string, which it will auto-encode from unicode using the default encoding. + # This usually fails, so we encode ourselves + return res.encode(defenc) + + def format(self): + """:return: a string suitable to be placed in a reflog file""" act = self.actor time = self.time - return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email, - time[0], altz_to_utctz_str(time[1]), self.message) + return u"{0} {1} {2} <{3}> {4!s} {5}\t{6}\n".format(self.oldhexsha, + self.newhexsha, + act.name, + act.email, + time[0], + altz_to_utctz_str(time[1]), + self.message) @property def oldhexsha(self): @@ -267,10 +282,9 @@ class RefLog(list, Serializable): lf = LockFile(filepath) lf._obtain_lock_or_raise() - fd = open(filepath, 'ab') try: - fd.write(repr(entry).encode(defenc)) + fd.write(entry.format().encode(defenc)) finally: fd.close() lf._release_lock() @@ -295,7 +309,7 @@ class RefLog(list, Serializable): # write all entries for e in self: - write(repr(e).encode(defenc)) + write(e.format().encode(defenc)) # END for each entry def _deserialize(self, stream): |