pushlog: add API to obtain push from node (
bug 1360007); r?glob
Before, our API was to pass in a changectx. This was not as
flexible as it could be. Let's add a new API to accept a node and
rewrite pushfromchangeset() to call it.
Accepting a hex node would have been easier because everything pushlog
stores hex nodes. However, this is a bad design of pushlog: we should
operate with binary nodes wherever possible. I felt like drawing a
line in the sand.
This change does break some filelog tests in hgext/hgmo for an
obscure reason. The next commit will fix that.
MozReview-Commit-ID: 1WqPBvmWfXS
--- a/hgext/pushlog/__init__.py
+++ b/hgext/pushlog/__init__.py
@@ -7,17 +7,17 @@ from __future__ import absolute_import
import collections
import contextlib
import os
import sqlite3
import stat
import time
-from mercurial.node import bin
+from mercurial.node import bin, hex
from mercurial import (
cmdutil,
encoding,
error,
exchange,
extensions,
registrar,
revset,
@@ -374,33 +374,38 @@ class pushlog(object):
if node:
current.nodes.append(node)
else:
current.nodes.append(node)
if current:
yield current
- def pushfromchangeset(self, ctx):
+ def pushfromnode(self, node):
"""Obtain info about a push that added the specified changeset.
Returns a Push namedtuple of (pushid, who, when, [nodes]) or None if
- there is no pushlog info for this changeset.
+ 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=?',
- (ctx.hex(),)).fetchone()
+ (hex(node),)).fetchone()
if not res:
return None
return self.pushfromid(c, 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
id.
"""
res = conn.execute('SELECT id, user, date, node from pushlog '
'LEFT JOIN changesets on id=pushid '