Patchwork revset: add keywords() and descs() functions which search for individual words

login
register
mail settings
Submitter Alexander Plavin
Date Aug. 2, 2013, 9:37 p.m.
Message ID <20776e6f2fbf49d8807c.1375479438@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/1991/
State Changes Requested
Headers show

Comments

Alexander Plavin - Aug. 2, 2013, 9:37 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@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.
Matt Mackall - Aug. 2, 2013, 9:59 p.m.
On Sat, 2013-08-03 at 01:37 +0400, Alexander Plavin wrote:
> # HG changeset patch
> # User Alexander Plavin <alexander@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

Quiz: If the odds of me accepting feature X is x% and the odds of me
accepting feature Y is y%, what are the odds of me accepting both in one
patch?

a) max(x, y)
b) min(x, y)
c) x * y / 100
d) 0

If you know your probability, you might suspect the answer is (c), which
is always less than min(x, y): you're always decreasing your odds of
acceptance by combining. But if you know me, you'll realize the answer
is actually zero, because I reject such patches on principle.
Alexander Plavin - Aug. 3, 2013, 10:33 a.m.
03.08.2013, 01:59, "Matt Mackall" <mpm@selenic.com>:
> On Sat, 2013-08-03 at 01:37 +0400, Alexander Plavin wrote:
>
>>  # HG changeset patch
>>  # User Alexander Plavin <alexander@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
>
> Quiz: If the odds of me accepting feature X is x% and the odds of me
> accepting feature Y is y%, what are the odds of me accepting both in one
> patch?
>
> a) max(x, y)
> b) min(x, y)
> c) x * y / 100
> d) 0
>
> If you know your probability, you might suspect the answer is (c), which
> is always less than min(x, y): you're always decreasing your odds of
> acceptance by combining. But if you know me, you'll realize the answer
> is actually zero, because I reject such patches on principle.

I don't fully get what exactly did you mean here: these changes themselves are not acceptable, no matter how they are sent, OR changes are ok, just send in separate patches?

>
> --
> Mathematics is the supreme nostalgia of our time.
Matt Mackall - Aug. 5, 2013, 6:43 p.m.
On Sat, 2013-08-03 at 14:33 +0400, Alexander Plavin wrote:
> 
> 03.08.2013, 01:59, "Matt Mackall" <mpm@selenic.com>:
> > On Sat, 2013-08-03 at 01:37 +0400, Alexander Plavin wrote:
> >
> >>  # HG changeset patch
> >>  # User Alexander Plavin <alexander@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
> >
> > Quiz: If the odds of me accepting feature X is x% and the odds of me
> > accepting feature Y is y%, what are the odds of me accepting both in one
> > patch?
> >
> > a) max(x, y)
> > b) min(x, y)
> > c) x * y / 100
> > d) 0
> >
> > If you know your probability, you might suspect the answer is (c), which
> > is always less than min(x, y): you're always decreasing your odds of
> > acceptance by combining. But if you know me, you'll realize the answer
> > is actually zero, because I reject such patches on principle.
> 
> I don't fully get what exactly did you mean here: these changes
> themselves are not acceptable, no matter how they are sent

There is intentionally no critique of X or Y here, only of the fact that
you sent X+Y. My priority is to get you to see why that is always going
to be a waste of everyone's time.

Patch

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)'