[PATCH] journal: add support for seaching by pattern

Martijn Pieters mj at zopatista.com
Fri Jul 1 12:09:49 EDT 2016

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

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

More information about the Mercurial-devel mailing list