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

login
register
mail settings
Submitter Tomasz Kleczek
Date Dec. 14, 2012, 2:52 a.m.
Message ID <b01a4cbad06879c7ce9d.1355453541@dev408.prn1.facebook.com>
Download mbox | patch
Permalink /patch/91/
State Deferred, archived
Headers show

Comments

Tomasz Kleczek - Dec. 14, 2012, 2:52 a.m.
# HG changeset patch
# User Tomasz Kleczek <tkleczek at fb.com>
# Date 1355434898 28800
# Node ID b01a4cbad06879c7ce9dec25429d841d1b5756f8
# Parent  31118161d007e4a274b151d9403640275667a070
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
@@ -23,3 +23,12 @@ 
     for ctx in ctxs:
         newentries.setdefault(ctx.user(), []).append(ctx.node())
     return newentries
+
+
+def makechgdate(ctxs):
+    """Return the `chgdate` index.
+
+    `chgdate` is keyed by change id, with each value being a commit date
+        of that change.
+    """
+    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
@@ -134,6 +134,13 @@ 
   chg1
   chg0
 
+  $ hg log --rev "date(10/20/2012)"
+  chg1
+  chg5
+
+  $ hg log --rev "date(10/20/2012) & user(testuser2)"
+  chg1
+
 Testing socket server
 
 Writing server config file
@@ -145,7 +152,7 @@ 
 Writing local config file
   $ cat >> $TESTTMP/localrepo/.hg/hgrc <<EOF_END
   > [speedy]
-  > host = localhost:8123
+  > host = http://localhost:8123
   > EOF_END
 
   $ cd $TESTTMP/serverrepo
@@ -154,11 +161,13 @@ 
   > hg metaserve > out 2>&1 & 
   > METASERVER_PID=$!
   > echo $METASERVER_PID 1> pidfile
-  > ) > /dev/null 2>&1
+  > ) > out 2> err
   $ sleep 1
 
   $ cd $TESTTMP/localrepo
 
+Perform some of the tests again, this time using remote server
+
   $ hg log -r "reverse(user(testuser1))"
   chg8
   chgl6
@@ -168,6 +177,9 @@ 
   chg2
   chg0
 
+  $ hg log --rev "date(10/20/2012) & user(testuser2)"
+  chg1
+
   $ cat >> $TESTTMP/localrepo/.hg/hgrc <<EOF_END
   > [speedy]
   > client = False