Patchwork [10,of,15] speedy: make author query take a list of user name patterns

login
register
mail settings
Submitter Tomasz Kleczek
Date Dec. 11, 2012, 6:38 p.m.
Message ID <2fcc58f469d294c99f92.1355251105@dev408.prn1.facebook.com>
Download mbox | patch
Permalink /patch/59/
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 1355181691 28800
# Branch stable
# Node ID 2fcc58f469d294c99f929b65d080637e6601242d
# Parent  2d5c84bc6ac522c45476bc7dddad7bdcd524fdef
speedy: make author query take a list of user name patterns

The result of the query is the list of node ids of changesets
commited by any of the users whose name matches pattern.

This is a step in adding support for log -u option (which may be
specified multiple times).

Patch

diff --git a/hgext/speedy/client.py b/hgext/speedy/client.py
--- a/hgext/speedy/client.py
+++ b/hgext/speedy/client.py
@@ -72,27 +72,32 @@ 
         """Return a list of local revisions."""
         return self._localrevs
 
-    def author(self, x):
-        resp = self._proxy.request('author', (x,))
+    def author(self, pats):
+        resp = self._proxy.request('author', (pats,))
         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, pats):
+    """Return the revisions commited by matching users.
+
+    A user matches if their name matches any of the patterns in `pats`.
+
+    metapeer: proxy object used to query the metadata server.
+    """
+    revs = set(metapeer.author(pats))
+    lrevsall = metapeer.localrevs()
+    for pat in pats:
+        revs.update(revset.author(repo, lrevsall, ('symbol', pat)))
+    return [r for r in subset if r in revs]
+
 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.
-    """
+    """Used to monkey patch revset.author function."""
     # We want to catch errors early and on client, if possible
     pat = revset.getstring(x, _("author requires a string"))
-    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 _patchedauthor(metapeer, repo, subset, [pat])
 
 def patcheddate(metapeer, repo, subset, d):
     """Return a list of revisions matching specified date.
diff --git a/hgext/speedy/server.py b/hgext/speedy/server.py
--- a/hgext/speedy/server.py
+++ b/hgext/speedy/server.py
@@ -29,20 +29,25 @@ 
         for name, idx in indices.iteritems():
             setattr(self, name, idx)
 
-    def author(self, pat):
-        """Return a list of changes commited by a user that matches pattern.
+    def author(self, pats):
+        """Return a list of changes commited by matching users.
 
-        User matches pattern if their name has a `pat` substring (case
-        insensitive).
+        User matches if for any pattern in `pats` their name has
+        this pattern a substring. Matching is case insensitive.
 
         Returns a list of node ids.
         """
-        pat = encoding.lower(pat)
-        kind, pattern, matcher = revset._substringmatcher(pat)
+        def makematcher(pat):
+            pat = encoding.lower(pat)
+            kind, pattern, matcher = revset._substringmatcher(pat)
+            return matcher
+        matchers = map(makematcher, pats)
         nodecands = []
         for user, l in self.userchgs.iteritems():
-            if matcher(encoding.lower(user)):
-                nodecands.extend(l)
+            for matcher in matchers:
+                if matcher(encoding.lower(user)):
+                    nodecands.extend(l)
+                    break
         return nodecands
 
     def date(self, d):