[PATCH 2 of 2] revset: add keywords() function which searches for individual words

Alexander Plavin alexander at plav.in
Mon Aug 5 16:20:56 CDT 2013


# HG changeset patch
# User Alexander Plavin <alexander at plav.in>
# Date 1375737133 -14400
#      Tue Aug 06 01:12:13 2013 +0400
# Node ID 58bdd9febc8faaac5290c517654277e46f2b7e25
# Parent  bac960d92a8f2d6fd2f833ab041ffe386c76967d
revset: add keywords() function which searches for individual words

This function provides a more convenient way to express a conjunction of
multiple keyword() calls.

diff -r bac960d92a8f -r 58bdd9febc8f mercurial/revset.py
--- a/mercurial/revset.py	Tue Aug 06 01:05:48 2013 +0400
+++ b/mercurial/revset.py	Tue Aug 06 01:12:13 2013 +0400
@@ -931,6 +931,25 @@
             l.append(r)
     return l
 
+def keywords_(repo, subset, x):
+    """``keywords(string)``
+    Search commit message, user name, and names of changed files for all
+    individual words from the string.
+    Equivalent to a conjunction of multiple keyword() calls.
+    The match is case-insensitive.
+    """
+    # i18n: "keywords" is a keyword
+    kws = encoding.lower(getstring(x, _("keywords requires a string"))).split()
+    l = []
+    for r in subset:
+        c = repo[r]
+        if util.all(
+                (util.any(kw in encoding.lower(t)
+                          for t in c.files() + [c.user(), c.description()]))
+                for kw in kws):
+            l.append(r)
+    return l
+
 def limit(repo, subset, x):
     """``limit(set, [n])``
     First n members of set, defaulting to 1.
@@ -1586,6 +1605,7 @@
     "hidden": hidden,
     "id": node_,
     "keyword": keyword,
+    "keywords": keywords_,
     "last": last,
     "limit": limit,
     "_matchfiles": _matchfiles,
diff -r bac960d92a8f -r 58bdd9febc8f tests/test-revset.t
--- a/tests/test-revset.t	Tue Aug 06 01:05:48 2013 +0400
+++ b/tests/test-revset.t	Tue Aug 06 01:12:13 2013 +0400
@@ -331,6 +331,10 @@
   $ log 'keyword("test a")'
   $ log 'descs("0 1")'
   9
+  $ log 'keywords("test a")'
+  0
+  6
+  9
   $ log 'limit(head(), 1)'
   0
   $ log 'matching(6)'


More information about the Mercurial-devel mailing list