Comments
Patch
@@ -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,
new file mode 100644
@@ -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)