Patchwork [3,of,3,V3] journal: add support for seaching by pattern

login
register
mail settings
Submitter Martijn Pieters
Date July 7, 2016, 5 p.m.
Message ID <81dc3a2e7a8930385258.1467910807@mjpieters-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/15770/
State Superseded
Delegated to: Yuya Nishihara
Headers show

Comments

Martijn Pieters - July 7, 2016, 5 p.m.
# HG changeset patch
# User Martijn Pieters <mjpieters@fb.com>
# Date 1467714538 -3600
#      Tue Jul 05 11:28:58 2016 +0100
# Node ID 81dc3a2e7a8930385258fc4d627f0f50c8bfe3e4
# Parent  e125ff50245cb519307dc75d606c9c8061784488
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 8, 2016, 3:25 p.m.
On Thu, 07 Jul 2016 18:00:07 +0100, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com>
> # Date 1467714538 -3600
> #      Tue Jul 05 11:28:58 2016 +0100
> # Node ID 81dc3a2e7a8930385258fc4d627f0f50c8bfe3e4
> # Parent  e125ff50245cb519307dc75d606c9c8061784488
> journal: add support for seaching by pattern

LGTM. I'll queue this with the patch 1.

Patch

diff --git a/hgext/journal.py b/hgext/journal.py
--- a/hgext/journal.py
+++ b/hgext/journal.py
@@ -366,11 +366,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
 
@@ -435,6 +442,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.
@@ -476,7 +487,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