The most flexible way to do this with Mercurial is to use revsets. For your example:
hg log -r 'grep("\\b(com-mit|commit)\\b")'
In Python regex syntax, \b
indicates a word boundary, and the backslash needs to be escaped. The (a|b)
syntax is used to match one or the other. The single quotes surrounding the argument are there so that the shell won't interpret the metacharacters itself.
You can also simplify the regular expression by combining revsets with and
:
hg log -r 'grep("\\bcom-mit\\b") or grep("\\bcommit\\b")'
If you don't need to match words exactly (e.g. if you want to match "committer" and "committed" too, not just "commit"), you can use the keyword revsets:
hg log -r 'keyword("com-mit") or keyword("commit")'
By using and
instead of or
, you can find revisions that match both rather than one of them; also, you can use reverse(...)
to list matches in the reverse order, e.g.:
hg log -r 'reverse(keyword("com-mit") or keyword("commit"))'