8000 test_reflog works · gitpython-developers/GitPython@b5a3756 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b5a3756

Browse files
committed
test_reflog works
1 parent 45c1c99 commit b5a3756

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

git/refs/log.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
)
2020
from git.compat import (
2121
xrange,
22-
string_types
22+
string_types,
23+
defenc
2324
)
2425

2526
import time
@@ -38,9 +39,8 @@ class RefLogEntry(tuple):
3839
def __repr__(self):
3940
"""Representation of ourselves in git reflog format"""
4041
act = self.actor
41-
name = act.name.encode('utf-8')
4242
time = self.time
43-
return self._fmt % (self.oldhexsha, self.newhexsha, name, act.email,
43+
return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email,
4444
time[0], altz_to_utctz_str(time[1]), self.message)
4545

4646
@property
@@ -82,8 +82,9 @@ def new(self, oldhexsha, newhexsha, actor, time, tz_offset, message):
8282
@classmethod
8383
def from_line(cls, line):
8484
""":return: New RefLogEntry instance from the given revlog line.
85-
:param line: line without trailing newline
85+
:param line: line bytes without trailing newline
8686
:raise ValueError: If line could not be parsed"""
87+
line = line.decode(defenc)
8788
try:
8889
info, msg = line.split('\t', 1)
8990
except ValueError:
@@ -253,15 +254,18 @@ def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message):
253254
# END handle sha type
254255
assure_directory_exists(filepath, is_file=True)
255256
committer = isinstance(config_reader, Actor) and config_reader or Actor.committer(config_reader)
256-
entry = RefLogEntry(
257-
(bin_to_hex(oldbinsha), bin_to_hex(newbinsha), committer, (int(time.time()), time.altzone), message))
257+
entry = RefLogEntry((
258+
bin_to_hex(oldbinsha).decode('ascii'),
259+
bin_to_hex(newbinsha).decode('ascii'),
260+
committer, (int(time.time()), time.altzone), message
261+
))
258262

259263
lf = LockFile(filepath)
260264
lf._obtain_lock_or_raise()
261265

262-
fd = open(filepath, 'a')
266+
fd = open(filepath, 'ab')
263267
try:
264-
fd.write(repr(entry))
268+
fd.write(repr(entry).encode(defenc))
265269
finally:
266270
fd.close()
267271
lf._release_lock()
@@ -286,7 +290,7 @@ def _serialize(self, stream):
286290

287291
# write all entries
288292
for e in self:
289-
write(repr(e))
293+
write(repr(e).encode(defenc))
290294
# END for each entry
291295

292296
def _deserialize(self, stream):

git/test/test_reflog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
RefLog
99
)
1010
from git.util import Actor
11+
from gitdb.util import hex_to_bin
1112

1213
import tempfile
1314
import shutil
@@ -51,7 +52,7 @@ def test_base(self):
5152
assert len(reflog)
5253

5354
# iter_entries works with path and with stream
54-
assert len(list(RefLog.iter_entries(open(rlp_master))))
55+
assert len(list(RefLog.iter_entries(open(rlp_master, 'rb'))))
5556
assert len(list(RefLog.iter_entries(rlp_master)))
5657

5758
# raise on invalid revlog
@@ -65,7 +66,7 @@ def test_base(self):
6566
self.failUnlessRaises(ValueError, RefLog().write)
6667

6768
# test serialize and deserialize - results must match exactly
68-
binsha = chr(255) * 20
69+
binsha = hex_to_bin(('f' * 40).encode('ascii'))
6970
msg = "my reflog message"
7071
cr = self.rorepo.config_reader()
7172
for rlp in (rlp_head, rlp_master):

0 commit comments

Comments
 (0)
0