Patchwork [03,of,15] speedy: convert revs to changeset ids when issuing query

login
register
mail settings
Submitter Tomasz Kleczek
Date Dec. 11, 2012, 6:38 p.m.
Message ID <176b9be2bf3609cd898e.1355251098@dev408.prn1.facebook.com>
Download mbox | patch
Permalink /patch/50/
State Superseded
Headers show

Comments

Tomasz Kleczek - Dec. 11, 2012, 6:38 p.m.
# HG changeset patch
# User Tomasz Kleczek <tkleczek at fb.com>
# Date 1355246303 28800
# Branch stable
# Node ID 176b9be2bf3609cd898eac5c2d4f87c8c4295e0b
# Parent  5d51bf818878db395e2e1f840769a83254c3dcfd
speedy: convert revs to changeset ids when issuing query

Since client history may diverge from server history we cannot
reliably use revision numbers when talking to server.
We use node ids instead (transmitted as 20 byte binary strings).

Please note that the server may return node ids that are unknown to
the client. This can occur when some changsets in the server repo
have not yet been pulled by the client and are in the result of running
the query against server history. It is the client's responsibilty
to filter out such changes before returning the final result to
the caller of patched functions.

Patch

diff --git a/hgext/speedy/client.py b/hgext/speedy/client.py
--- a/hgext/speedy/client.py
+++ b/hgext/speedy/client.py
@@ -9,6 +9,25 @@ 
 from mercurial.i18n import _
 import server
 
+def nodestorevs(repo, nodes):
+    return [repo[n].rev() for n in nodes if repo.changelog.hasnode(n)]
+
+class metapeer(object):
+    """Class that encapsulates communication details with the metadata server.
+
+    Its responsibilities:
+        - delegating the query to the server
+        - translating node ids from server to revision numbers
+    """
+
+    def __init__(self, server, repo):
+        self._server = server
+        self._repo = repo
+
+    def author(self, x):
+        resp = self._server.author(x)
+        return nodestorevs(self._repo, resp)
+
 def patchedauthor(metapeer, repo, subset, x):
     """Return the revisions commited by user whose name match x
 
@@ -28,12 +47,14 @@ 
     serverrepo = localrepo.localrepository(ui, path=repo.root)
     mserver = server.makeserver(serverrepo)
 
+    mpeer = metapeer(mserver, repo)
+
     def wrapwithpeer(fun, peer):
         def wrapper(*args, **kwargs):
             return fun(peer, *args, **kwargs)
         return wrapper
 
-    revset.symbols['author'] = wrapwithpeer(patchedauthor, mserver)
+    revset.symbols['author'] = wrapwithpeer(patchedauthor, mpeer)
 
 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
--- a/hgext/speedy/server.py
+++ b/hgext/speedy/server.py
@@ -22,10 +22,11 @@ 
         User matches pattern if their name has a `pat` substring (case
         insensitive).
 
-        Returns a list of revs.
+        Returns a list of node ids.
         """
         # This is going to be accelerated in the subsequent patches
-        return revset.author(self.repo, list(self.repo), ('symbol', pat))
+        revs = revset.author(self.repo, list(self.repo), ('symbol', pat))
+        return [self.repo[r].node() for r in revs]
 
 def makeserver(repo):
     """Return an initialized metaserver instance."""