summaryrefslogtreecommitdiff
path: root/git/refs/log.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-06 16:11:34 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-06 16:11:34 +0100
commit56e942318f3c493c8dcd4759f806034331ebeda5 (patch)
tree82cdca65cd197f36ea3680171186e0ddcf234266 /git/refs/log.py
parentd46e3fe9cb0dea2617cd9231d29bf6919b0f1e91 (diff)
parent68f8a43d1b643318732f30ee1cd75e1d315a4537 (diff)
downloadgitpython-56e942318f3c493c8dcd4759f806034331ebeda5.tar.gz
Merge branch 'py3' into 0.3
Conflicts: git/refs/log.py
Diffstat (limited to 'git/refs/log.py')
-rw-r--r--git/refs/log.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/git/refs/log.py b/git/refs/log.py
index 07465e6f..7708dd73 100644
--- a/git/refs/log.py
+++ b/git/refs/log.py
@@ -17,6 +17,11 @@ from git.objects.util import (
Serializable,
altz_to_utctz_str,
)
+from git.compat import (
+ xrange,
+ string_types,
+ defenc
+)
import time
import re
@@ -34,9 +39,8 @@ class RefLogEntry(tuple):
def __repr__(self):
"""Representation of ourselves in git reflog format"""
act = self.actor
- name = act.name.encode('utf-8')
time = self.time
- return self._fmt % (self.oldhexsha, self.newhexsha, name, act.email,
+ return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email,
time[0], altz_to_utctz_str(time[1]), self.message)
@property
@@ -78,7 +82,7 @@ class RefLogEntry(tuple):
@classmethod
def from_line(cls, line):
""":return: New RefLogEntry instance from the given revlog line.
- :param line: line without trailing newline
+ :param line: line bytes without trailing newline
:raise ValueError: If line could not be parsed"""
fields = line.split('\t', 1)
if len(fields) == 1:
@@ -89,6 +93,7 @@ class RefLogEntry(tuple):
raise ValueError("Line must have up to two TAB-separated fields."
" Got %s" % repr(line))
# END handle first split
+
oldhexsha = info[:40]
newhexsha = info[41:81]
for hexsha in (oldhexsha, newhexsha):
@@ -174,7 +179,7 @@ class RefLog(list, Serializable):
:param stream: file-like object containing the revlog in its native format
or basestring instance pointing to a file to read"""
new_entry = RefLogEntry.from_line
- if isinstance(stream, basestring):
+ if isinstance(stream, string_types):
stream = file_contents_ro_filepath(stream)
# END handle stream type
while True:
@@ -253,15 +258,18 @@ class RefLog(list, Serializable):
# END handle sha type
assure_directory_exists(filepath, is_file=True)
committer = isinstance(config_reader, Actor) and config_reader or Actor.committer(config_reader)
- entry = RefLogEntry(
- (bin_to_hex(oldbinsha), bin_to_hex(newbinsha), committer, (int(time.time()), time.altzone), message))
+ entry = RefLogEntry((
+ bin_to_hex(oldbinsha).decode('ascii'),
+ bin_to_hex(newbinsha).decode('ascii'),
+ committer, (int(time.time()), time.altzone), message
+ ))
lf = LockFile(filepath)
lf._obtain_lock_or_raise()
- fd = open(filepath, 'a')
+ fd = open(filepath, 'ab')
try:
- fd.write(repr(entry))
+ fd.write(repr(entry).encode(defenc))
finally:
fd.close()
lf._release_lock()
@@ -286,7 +294,7 @@ class RefLog(list, Serializable):
# write all entries
for e in self:
- write(repr(e))
+ write(repr(e).encode(defenc))
# END for each entry
def _deserialize(self, stream):