[PATCH 3 of 3 V2] journal: add support for seaching by pattern
Martijn Pieters
mj at zopatista.com
Mon Jul 4 14:35:58 UTC 2016
# HG changeset patch
# User Martijn Pieters <mjpieters at fb.com>
# Date 1467637235 -3600
# Mon Jul 04 14:00:35 2016 +0100
# Node ID 9b59a7a071a31cf230fb3cd614be10bfe20f6e4d
# Parent aa864e83d58475a68ba4460289a48a73a0759c47
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
@@ -367,11 +367,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
@@ -436,6 +443,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.
@@ -477,7 +488,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