summaryrefslogtreecommitdiff
path: root/git/refs/log.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/refs/log.py')
-rw-r--r--git/refs/log.py26
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):