Implemented revlog.append_entry as classmethod, to assure we will alw… · gitpython-developers/GitPython@7029773 · GitHub
Skip to content

Commit 7029773

Browse files
committed
Implemented revlog.append_entry as classmethod, to assure we will always actually write_append the new entry, instead of rewriting the whole file. Added file-locking and directory handling, so the implementation should be similar (enough) to the git reference implementation.
Next up is to implement a way to update the reflog when changing references, which is going to be a little more complicated
1 parent 61f3db7 commit 7029773

4 files changed

Lines changed: 57 additions & 20 deletions

File tree

refs/log.py

Lines changed: 27 additions & 10 deletions

refs/symbolic.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,19 @@ def log(self):
266266
applied to this reference
267267
268268
.. note:: As the log is parsed every time, its recommended to cache it for use
269-
instead of calling this method repeatedly"""
269+
instead of calling this method repeatedly. It should be considered read-only."""
270270
return RefLog.from_file(RefLog.path(self))
271+
272+
def log_append(self, oldbinsha, message, newbinsha=None):
273+
"""Append a logentry to the logfile of this ref
274+
:param oldbinsha: binary sha this ref used to point to
275+
:param message: A message describing the change
276+
:param newbinsha: The sha the ref points to now. If None, our current commit sha
277+
will be used
278+
:return: added RefLogEntry instance"""
279+
return RefLog.append_entry(RefLog.path(self), oldbinsha,
280+
(newbinsha is None and self.commit.binsha) or newbinsha,
281+
message)
271282

272283
@classmethod
273284
def to_full_path(cls, path):

test/test_reflog.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,12 @@ def test_base(self):
7272
# ... as well as each bytes of the written stream
7373
assert open(tfile).read() == open(rlp).read()
7474

75-
# append an entry - it gets written automatically
76-
entry = treflog.append_entry(IndexObject.NULL_BIN_SHA, binsha, msg)
75+
# append an entry
76+
entry = RefLog.append_entry(tfile, IndexObject.NULL_BIN_SHA, binsha, msg)
7777
assert entry.oldhexsha == IndexObject.NULL_HEX_SHA
7878
assert entry.newhexsha == 'f'*40
7979
assert entry.message == msg
80-
assert treflog == RefLog.from_file(tfile)
81-
82-
# but not this time
83-
treflog.append_entry(binsha, binsha, msg, write=False)
84-
assert treflog != RefLog.from_file(tfile)
85-
80+
assert RefLog.from_file(tfile)[-1] == entry
8681
# END for each reflog
8782

8883

util.py

Lines changed: 15 additions & 1 deletion

0 commit comments

Comments
 (0)