pushlog: extract code for obtaining a Push from a push ID; r?glandium draft
authorGregory Szorc <gps@mozilla.com>
Thu, 25 Aug 2016 12:46:44 -0700
changeset 9294 e094f8ce0682efa033eb936f5c1fe284099f96a5
parent 9293 80b567ff7820f72e3ac1bfea79db0ce8a88082af
child 9295 819785d1c3c9017d2a5a1504fd6f12f653e58502
child 9298 180537ad5fe1f0a616f89b63bbfceef2ef8ea76b
push id1124
push userbmo:gps@mozilla.com
push dateThu, 25 Aug 2016 23:55:33 +0000
reviewersglandium
pushlog: extract code for obtaining a Push from a push ID; r?glandium MozReview-Commit-ID: 5AK0Zcv6xLq
hgext/pushlog/__init__.py
--- a/hgext/pushlog/__init__.py
+++ b/hgext/pushlog/__init__.py
@@ -391,27 +391,36 @@ class pushlog(object):
             if not c:
                 return None
 
             res = c.execute('SELECT pushid from changesets WHERE node=?',
                             (ctx.hex(),)).fetchone()
             if not res:
                 return None
 
-            pushid = res[0]
+            return self.pushfromid(c, res[0])
+
+    def pushfromid(self, conn, pushid):
+        """Obtain a push from its numeric push id.
 
-            res = c.execute('SELECT id, user, date, node from pushlog '
-                            'LEFT JOIN changesets on id=pushid '
-                            'WHERE id=? ORDER BY rev ASC', (pushid,))
-            nodes = []
-            for pushid, who, when, node in res:
-                who = who.encode('utf-8')
-                nodes.append(node.encode('ascii'))
+        Returns a Push namedtuple or None if there is no push with this push
+        id.
+        """
+        res = conn.execute('SELECT id, user, date, node from pushlog '
+                           'LEFT JOIN changesets on id=pushid '
+                           'WHERE id=? ORDER BY rev ASC', (pushid,))
+        nodes = []
+        for pushid, who, when, node in res:
+            who = who.encode('utf-8')
+            nodes.append(node.encode('ascii'))
 
-            return Push(pushid, who, when, nodes)
+        if not nodes:
+            return None
+
+        return Push(pushid, who, when, nodes)
 
     def verify(self):
         # Attempt to create database (since .pushes below won't).
         with self.conn():
             pass
 
         repo = self.repo
         ui = self.repo.ui