[PATCH] revset: add keywords() and descs() functions which search for individual words
Alexander Plavin
alexander at plav.in
Fri Aug 2 21:37:18 UTC 2013
# HG changeset patch
# User Alexander Plavin <alexander at plav.in>
# Date 1374254768 -14400
# Fri Jul 19 21:26:08 2013 +0400
# Node ID 20776e6f2fbf49d8807cbf308e102f5798bce7d9
# Parent d07c92b5a8382e8182cf63dbf6463c32140e9d14
revset: add keywords() and descs() functions which search for individual words
These functions provide a more convenient way to express a common usage pattern.
diff -r d07c92b5a838 -r 20776e6f2fbf mercurial/revset.py
--- a/mercurial/revset.py Sun Jun 30 11:48:21 2013 +0400
+++ b/mercurial/revset.py Fri Jul 19 21:26:08 2013 +0400
@@ -589,6 +589,23 @@
l.append(r)
return l
+def descs(repo, subset, x):
+ """``descs(string)``
+ Search commit message for all individual words from the string.
+ The match is case-insensitive.
+ """
+ # i18n: "descs" is a keyword
+ dses = encoding.lower(getstring(x, _("descs requires a string"))).split()
+ l = []
+ for r in subset:
+ c = repo[r]
+ for ds in dses:
+ if ds not in encoding.lower(c.description()):
+ break
+ else:
+ l.append(r)
+ return l
+
def _descendants(repo, subset, x, followfirst=False):
args = getset(repo, list(repo), x)
if not args:
@@ -915,6 +932,24 @@
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. 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]
+ t = " ".join(c.files() + [c.user(), c.description()])
+ for kw in kws:
+ if kw not in encoding.lower(t):
+ break
+ else:
+ l.append(r)
+ return l
+
def limit(repo, subset, x):
"""``limit(set, [n])``
First n members of set, defaulting to 1.
@@ -1551,6 +1586,7 @@
"converted": converted,
"date": date,
"desc": desc,
+ "descs": descs,
"descendants": descendants,
"_firstdescendants": _firstdescendants,
"destination": destination,
@@ -1569,6 +1605,7 @@
"hidden": hidden,
"id": node_,
"keyword": keyword,
+ "keywords": keywords_,
"last": last,
"limit": limit,
"_matchfiles": _matchfiles,
diff -r d07c92b5a838 -r 20776e6f2fbf tests/test-revset.t
--- a/tests/test-revset.t Sun Jun 30 11:48:21 2013 +0400
+++ b/tests/test-revset.t Fri Jul 19 21:26:08 2013 +0400
@@ -328,6 +328,10 @@
7
$ log 'keyword(issue)'
6
+ $ log 'keyword(test) and keyword(a)'
+ 0
+ 6
+ 9
$ log 'limit(head(), 1)'
0
$ log 'matching(6)'
More information about the Mercurial-devel
mailing list