Skip to content

Commit 46017b8

Browse files
author
Jaakko Kangasharju
committed
Produce proper commit objects when iterating over all commits
The iter_individual_commits method that allowed iterating over all the commits stored in the database was producing the commits as they are stored in the database. This meant that the line_counts and test_counts attributes weren't populated, which reduced the utility of the regression checking. Instead of database-level commits, produce the processed commit objects that have the line and test counts computed. This added two new requirements: 1) Implement __eq__ and __hash__ for authors so that the comparison in regression checking works for the count dictionaries. 2) Load the Author relationship of Commit eagerly so that the author of a commit is available afterwards.
1 parent b8408b1 commit 46017b8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

githammer/dbtypes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ def name(self):
7474
else:
7575
return None
7676

77+
def __eq__(self, other):
78+
return self.canonical_name == other.canonical_name and self.aliases == other.aliases
79+
80+
def __hash__(self):
81+
return hash(self.canonical_name)
82+
7783
def __repr__(self):
7884
return self.name
7985

@@ -89,7 +95,7 @@ class Commit(Base):
8995
commit_time_utc_offset = Column(Integer, nullable=False)
9096
parent_ids = Column(JSONType)
9197

92-
author = relationship('Author', back_populates='commits')
98+
author = relationship('Author', back_populates='commits', lazy='joined')
9399

94100
def __init__(self, **kwargs):
95101
super(Commit, self).__init__(**kwargs)

githammer/hammer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,5 +343,5 @@ def iter_individual_commits(self):
343343
self._fail_unless_database_exists()
344344
session = self._Session()
345345
for commit in session.query(Commit).order_by(Commit.commit_time):
346-
yield commit
346+
yield self._shas_to_commits.get(commit.hexsha)
347347
session.close()

0 commit comments

Comments
 (0)