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

Tomasz Kleczek tkleczek at fb.com
Thu Dec 13 20:52:14 CST 2012


# HG changeset patch
# User Tomasz Kleczek <tkleczek at fb.com>
# 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 revset.author 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/client.py b/hgext/speedy/client.py
--- a/hgext/speedy/client.py
+++ b/hgext/speedy/client.py
@@ -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 revset.author function.
     """
-    # In the subsequent patches here we are going to forward the query
-    # to the server
-    return revset.author(repo, subset, x)
+    # We want to catch errors early and on client, if possible
+    pat = revset.getstring(x, _("author requires a string"))
+    revs = set(metapeer.author(pat))
+    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/server.py b/hgext/speedy/server.py
new file mode 100644
--- /dev/null
+++ b/hgext/speedy/server.py
@@ -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 revset.author(self.repo, list(self.repo), ('symbol', pat))
+
+def makeserver(repo):
+    """Return an initialized metaserver instance."""
+    return metaserver(repo)


More information about the Mercurial-devel mailing list