Patchwork journal: add support for seaching by pattern

login
register
mail settings
Submitter Martijn Pieters
Date July 1, 2016, 4:09 p.m.
Message ID <ce87a3f3badb4e960dcb.1467389389@mjpieters-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/15712/
State Deferred
Headers show

Comments

Martijn Pieters - July 1, 2016, 4:09 p.m.
# HG changeset patch
# User Martijn Pieters <mjpieters@fb.com>
# Date 1467389355 -3600
#      Fri Jul 01 17:09:15 2016 +0100
# Node ID ce87a3f3badb4e960dcb82012742ecc97f0545db
# Parent  a16d2698729fe08e8eba71796660062c0141358f
journal: add support for seaching by pattern

If a pattern is used, include the entry name in the output, to make it clear
what name was matched.
Yuya Nishihara - July 4, 2016, 1:49 p.m.
On Fri, 01 Jul 2016 17:09:49 +0100, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com>
> # Date 1467389355 -3600
> #      Fri Jul 01 17:09:15 2016 +0100
> # Node ID ce87a3f3badb4e960dcb82012742ecc97f0545db
> # Parent  a16d2698729fe08e8eba71796660062c0141358f
> journal: add support for seaching by pattern

Dropped this from patchwork for now. Please resend with/after V2 patches.
timeless - July 7, 2016, 1:49 a.m.
On Fri, Jul 1, 2016 at 12:09 PM, Martijn Pieters <mj@zopatista.com> wrote:
> journal: add support for seaching by pattern

searching
Martijn Pieters - July 7, 2016, 5:03 p.m.
On 7 July 2016 at 02:49, timeless <timeless@gmail.com> wrote:
> On Fri, Jul 1, 2016 at 12:09 PM, Martijn Pieters <mj@zopatista.com> wrote:
>> journal: add support for seaching by pattern
>
> searching

Crumbs, I forgot to update the commit message before sending out V3.
Can that be fixed in-flight please? Sorry about this.

Patch

diff --git a/hgext/journal.py b/hgext/journal.py
--- a/hgext/journal.py
+++ b/hgext/journal.py
@@ -349,11 +349,18 @@ 
         Both the namespace and the name are optional; if neither is given all
         entries in the journal are produced.
 
+        Matching supports regular expressions by using the `re:` prefix
+        (use `literal:` to match names or namespaces that start with `re:`)
+
         """
+        if namespace is not None:
+            namespace = util.stringmatcher(namespace)[-1]
+        if name is not None:
+            name = util.stringmatcher(name)[-1]
         for entry in self:
-            if namespace is not None and entry.namespace != namespace:
+            if namespace is not None and not namespace(entry.namespace):
                 continue
-            if name is not None and entry.name != name:
+            if name is not None and not name(entry.name):
                 continue
             yield entry
 
@@ -421,6 +428,10 @@ 
     bookmarks and the working copy; each line will then include the bookmark
     name, or '.' for the working copy, as well.
 
+    If `name` starts with `re:`, the remainder of the name is treated as
+    a regular expression. To match a name that actually starts with `re:`,
+    use the prefix `literal:`.
+
     By default hg journal only shows the commit hash and the command that was
     running at that time. -v/--verbose will show the prior hash, the user, and
     the time at which it happened.
@@ -462,7 +473,9 @@ 
         fm.condwrite(ui.verbose, 'oldhashes', '%s -> ', oldhashesstr)
         fm.write('newhashes', '%s', newhashesstr)
         fm.condwrite(ui.verbose, 'user', ' %s', entry.user.ljust(8))
-        fm.condwrite(opts.get('all'), 'name', '  %s', entry.name.ljust(8))
+        fm.condwrite(
+            opts.get('all') or name.startswith('re:'),
+            'name', '  %s', entry.name.ljust(8))
 
         timestring = util.datestr(entry.timestamp, '%Y-%m-%d %H:%M %1%2')
         fm.condwrite(ui.verbose, 'date', ' %s', timestring)
diff --git a/tests/test-journal.t b/tests/test-journal.t
--- a/tests/test-journal.t
+++ b/tests/test-journal.t
@@ -123,6 +123,12 @@ 
   cb9a9f314b8b  up 0
   1e6c11564562  commit -Aqm b
   cb9a9f314b8b  commit -Aqm a
+  $ hg journal "re:ba."
+  previous locations of 're:ba.':
+  1e6c11564562  baz       book -r tip baz
+  1e6c11564562  bar       up
+  cb9a9f314b8b  bar       book -f bar
+  1e6c11564562  bar       book -r tip bar
 
 Test that verbose and commit output work