pushlog: factor out code to obtain a push from a node (
bug 1303904); r?glob
A subsequent commit will introduce a consumer that wants to obtain
push records for multiple nodes. To facilitate doing this with a
single database handle, refactor the code into a function that takes
a database connection as an argument.
MozReview-Commit-ID: 3P6tLIz4C4N
--- a/hgext/pushlog/__init__.py
+++ b/hgext/pushlog/__init__.py
@@ -387,22 +387,25 @@ class pushlog(object):
there is no pushlog info for this node.
Argument is specified as binary node.
"""
with self.conn(readonly=True) as c:
if not c:
return None
- res = c.execute('SELECT pushid from changesets WHERE node=?',
- (hex(node),)).fetchone()
- if not res:
- return None
+ return self._push_from_node(c, node)
- return self.pushfromid(c, res[0])
+ def _push_from_node(self, conn, node):
+ res = conn.execute('SELECT pushid from changesets WHERE node=?',
+ (hex(node),)).fetchone()
+ if not res:
+ return None
+
+ return self.pushfromid(conn, res[0])
def pushfromchangeset(self, ctx):
return self.pushfromnode(ctx.node())
def pushfromid(self, conn, pushid):
"""Obtain a push from its numeric push id.
Returns a Push namedtuple or None if there is no push with this push