pushlog: factor out code to obtain a push from a node (bug 1303904); r?glob draft
authorGregory Szorc <gps@mozilla.com>
Thu, 08 Jun 2017 11:24:18 -0700
changeset 11235 5cc88b2d2b8cf33d341780678114240df8331397
parent 11234 442f057545cd56c529841eccc103f55cae50acf1
child 11236 6504363eb1aaf7d66a163e6df855fbd7735bcdc2
push id1708
push usergszorc@mozilla.com
push dateMon, 19 Jun 2017 18:36:36 +0000
reviewersglob
bugs1303904
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
hgext/pushlog/__init__.py
--- 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