pushlog: add API to obtain push from node (bug 1360007); r?glob draft
authorGregory Szorc <gps@mozilla.com>
Tue, 23 May 2017 17:12:41 -0700
changeset 11084 3c465c83e6f38b28ea98812a677903e5000c9ad7
parent 11083 135fc4946cd96084f066838622cd149a76570d96
child 11085 f8a2a76ca20b3bd26ec04acb2f67b852b41b0c98
push id1683
push userbmo:gps@mozilla.com
push dateWed, 24 May 2017 01:08:55 +0000
reviewersglob
bugs1360007
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
hgext/pushlog/__init__.py
--- 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 '