pushlog: extract code for obtaining a Push from a push ID; r?glandium
MozReview-Commit-ID: 5AK0Zcv6xLq
--- 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