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.
--- a/hgext/journal.py Mon Jul 11 14:45:41 2016 +0100
+++ b/hgext/journal.py Fri Jul 08 16:48:38 2016 +0100
@@ -361,11 +361,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
@@ -430,6 +437,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.
@@ -471,7 +482,9 @@
fm.condwrite(ui.verbose, 'oldhashes', '%s -> ', oldhashesstr)
fm.write('newhashes', '%s', newhashesstr)
fm.condwrite(ui.verbose, 'user', ' %-8s', entry.user)
- fm.condwrite(opts.get('all'), 'name', ' %-8s', entry.name)
+ fm.condwrite(
+ opts.get('all') or name.startswith('re:'),
+ 'name', ' %-8s', entry.name)
timestring = util.datestr(entry.timestamp, '%Y-%m-%d %H:%M %1%2')
fm.condwrite(ui.verbose, 'date', ' %s', timestring)
--- a/tests/test-journal.t Mon Jul 11 14:45:41 2016 +0100
+++ b/tests/test-journal.t Fri Jul 08 16:48:38 2016 +0100
@@ -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, JSON and commit output work