Patchwork [09,of,15] speedy: adding support for revset.date query

login
register
mail settings
Submitter Tomasz Kleczek
Date Dec. 11, 2012, 6:38 p.m.
Message ID <2d5c84bc6ac522c45476.1355251104@dev408.prn1.facebook.com>
Download mbox | patch
Permalink /patch/56/
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 1355250345 28800
# Branch stable
# Node ID 2d5c84bc6ac522c45476bc7dddad7bdcd524fdef
# Parent  00824bb913d9d40229c883aa002a9a4b13fbad74
speedy: adding support for revset.date query

Adds:
  * Patched revset.date method
  * History server date query handler
  * New index that maps node ids to the commit dates.

Patch

diff --git a/hgext/speedy/client.py b/hgext/speedy/client.py
--- a/hgext/speedy/client.py
+++ b/hgext/speedy/client.py
@@ -76,6 +76,10 @@ 
         resp = self._proxy.request('author', (x,))
         return nodestorevs(self._repo, resp)
 
+    def date(self, x):
+        resp = self._proxy.request('date', (x,))
+        return nodestorevs(self._repo, resp)
+
 def patchedauthor(metapeer, repo, subset, x):
     """Return the revisions commited by user whose name match x
 
@@ -88,7 +92,21 @@ 
     revs = set(metapeer.author(pat))
     lrevsall = metapeer.localrevs()
     revs.update(revset.author(repo, lrevsall, ('symbol', pat)))
-    return [ r for r in subset if r in revs ]
+    return [ r for r in subset if r in revs]
+
+def patcheddate(metapeer, repo, subset, d):
+    """Return a list of revisions matching specified date.
+
+    metapeer: proxy object used to query the metadata server.
+
+    Used to monkey patch revset.date function.
+    """
+    # We want to catch errors early and on client, if possible
+    ds = revset.getstring(d, _("date requires a string"))
+    revs = set(metapeer.date(ds))
+    lrevsall = metapeer.localrevs()
+    revs.update(revset.date(repo, lrevsall, ('symbol', ds)))
+    return [r for r in subset if r in revs]
 
 def _speedysetup(ui, repo):
     """Initialize speedy client.
@@ -122,6 +140,7 @@ 
         return wrapper
 
     revset.symbols['author'] = wrapwithpeer(patchedauthor, mpeer)
+    revset.symbols['date'] = wrapwithpeer(patcheddate, mpeer)
 
 def uisetup(ui):
     # Perform patching and most of the initialization inside log wrapper,
diff --git a/hgext/speedy/index.py b/hgext/speedy/index.py
--- a/hgext/speedy/index.py
+++ b/hgext/speedy/index.py
@@ -22,3 +22,15 @@ 
     for ctx in ctxs:
         newentries.setdefault(ctx.user(), []).append(ctx.node())
     return newentries
+
+
+def makechgdate(ctxs):
+    """Return the `chgdate` index in the form of a dict.
+
+    `chgdate` is keyed by node id, with each value being a commit date
+        of that change.
+
+    ctxs: an iterable with change contexts from which the index is to
+        be created.
+    """
+    return dict([(ctx.node(), ctx.date()[0]) for ctx in ctxs])
diff --git a/hgext/speedy/server.py b/hgext/speedy/server.py
--- a/hgext/speedy/server.py
+++ b/hgext/speedy/server.py
@@ -45,8 +45,18 @@ 
                 nodecands.extend(l)
         return nodecands
 
+    def date(self, d):
+        """Return a list of changes matching specified date.
+
+        Returns a list of node ids.
+        """
+        matcher = util.matchdate(d)
+        return [node for node, date in self.chgdate.iteritems()
+            if matcher(date)]
+
 indicecfg = {
     'userchgs': index.makeuserchgs,
+    'chgdate': index.makechgdate,
 }
 
 def makeserver(repo):
diff --git a/tests/test-speedy.t b/tests/test-speedy.t
--- a/tests/test-speedy.t
+++ b/tests/test-speedy.t
@@ -135,6 +135,13 @@ 
   chg1
   chg0
 
+  $ hg log --rev "date(10/20/2012)"
+  chg1
+  chg5
+
+  $ hg log --rev "date(10/20/2012) & user(testuser2)"
+  chg1
+
 Testing http server
 
 Writing server config file
@@ -160,6 +167,8 @@ 
 
   $ cd $TESTTMP/localrepo
 
+Perform some of the tests again, this time using remote server
+
   $ hg log -r "reverse(user(testuser1))"
   chg8
   chgl6
@@ -169,6 +178,9 @@ 
   chg2
   chg0
 
+  $ hg log --rev "date(10/20/2012) & user(testuser2)"
+  chg1
+
   $ cat >> $TESTTMP/localrepo/.hg/hgrc <<EOF_END
   > [speedy]
   > client = False