Patchwork [02,of,21,V2] speedy: stub history query server

mail settings
Submitter Tomasz Kleczek
Date Dec. 14, 2012, 2:52 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/83/
State Deferred, archived
Headers show


Tomasz Kleczek - Dec. 14, 2012, 2:52 a.m.
# HG changeset patch
# User Tomasz Kleczek <tkleczek at>
# Date 1355419299 28800
# Node ID 0101e7572322e87d2cc80120af17da02a56e4f9e
# Parent  136696ee699f3cfa85fd9e43a95f3ec9f1bc1c74
speedy: stub history query server

Introduce a server component to which clients delegate their
history requests.

For now, server instance is initialized by the client using
`makeserver` helper function and used directly from client
(all work is in the client python instance). This is going
to change in subsequent patches.

Also server still handles only author query and it simply
calls function, so no performance gain for now.

Subsequent patches are going to incrementally add functionality
to both the client and the server.


diff --git a/hgext/speedy/ b/hgext/speedy/
--- a/hgext/speedy/
+++ b/hgext/speedy/
@@ -5,19 +5,35 @@ 
 from mercurial import extensions, commands
 from mercurial import revset
+from mercurial import localrepo
+from mercurial.i18n import _
+import server
-def patchedauthor(repo, subset, x):
+def patchedauthor(metapeer, repo, subset, x):
     """Return the revisions commited by user whose name match x
+    metapeer: proxy object used to query the metadata server
     Used to monkey patch function.
-    # In the subsequent patches here we are going to forward the query
-    # to the server
-    return, subset, x)
+    # We want to catch errors early and on client, if possible
+    pat = revset.getstring(x, _("author requires a string"))
+    revs = set(
+    return [r for r in subset if r in revs]
 def _speedysetup(ui, repo):
     """Initialize speedy client."""
-    revset.symbols['author'] = patchedauthor
+    # For now, local repo and server repo are the same. This is going
+    # to change soon
+    serverrepo = localrepo.localrepository(ui, path=repo.root)
+    mserver = server.makeserver(serverrepo)
+    def wrapwithpeer(fun, peer):
+        def wrapper(*args, **kwargs):
+            return fun(peer, *args, **kwargs)
+        return wrapper
+    revset.symbols['author'] = wrapwithpeer(patchedauthor, mserver)
 def uisetup(ui):
     # Perform patching and most of the initialization inside log wrapper,
diff --git a/hgext/speedy/ b/hgext/speedy/
new file mode 100644
--- /dev/null
+++ b/hgext/speedy/
@@ -0,0 +1,32 @@ 
+# Copyright 2012 Facebook
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+"""Server component
+metaserver: contains all the logic behind query acceleration
+from mercurial import revset
+class metaserver(object):
+    """Contains all the logic behind the query acceleration."""
+    def __init__(self, repo):
+        self.repo = repo
+    def author(self, pat):
+        """Return a list of changes commited by a user that matches pattern.
+        User matches pattern if their name has a `pat` substring (case
+        insensitive).
+        Returns a list of revs.
+        """
+        # This is going to be accelerated in the subsequent patches
+        return, list(self.repo), ('symbol', pat))
+def makeserver(repo):
+    """Return an initialized metaserver instance."""
+    return metaserver(repo)