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

Martijn Pieters mj at zopatista.com
Thu Jul 7 13:00:07 EDT 2016

# HG changeset patch
# User Martijn Pieters <mjpieters at 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.

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):
-            if name is not None and entry.name != name:
+            if name is not None and not name(entry.name):
             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

More information about the Mercurial-devel mailing list