Skip to content

Commit e03a8b3

Browse files
Yuri Volchkovyvolchkov
Yuri Volchkov
authored andcommitted
Fix inheritance issue at commit.iter_items
The iterator used to yield Commit() objects, which does not play well with inheritance. Yield cls() instead. Signed-off-by: Yuri Volchkov <[email protected]>
1 parent 3c19a6e commit e03a8b3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: git/objects/commit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream):
269269
# END handle extra info
270270

271271
assert len(hexsha) == 40, "Invalid line: %s" % hexsha
272-
yield Commit(repo, hex_to_bin(hexsha))
272+
yield cls(repo, hex_to_bin(hexsha))
273273
# END for each line in stream
274274
# TODO: Review this - it seems process handling got a bit out of control
275275
# due to many developers trying to fix the open file handles issue

Diff for: test/test_commit.py

+8
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ def test_iteration(self):
199199
less_ltd_commits = list(Commit.iter_items(self.rorepo, 'master', paths=('CHANGES', 'AUTHORS')))
200200
assert len(ltd_commits) < len(less_ltd_commits)
201201

202+
class Child(Commit):
203+
def __init__(self, *args, **kwargs):
204+
super(Child, self).__init__(*args, **kwargs)
205+
206+
child_commits = list(Child.iter_items(self.rorepo, 'master', paths=('CHANGES', 'AUTHORS')))
207+
assert type(child_commits[0]) == Child
208+
209+
202210
def test_iter_items(self):
203211
# pretty not allowed
204212
self.assertRaises(ValueError, Commit.iter_items, self.rorepo, 'master', pretty="raw")

0 commit comments

Comments
 (0)