I think this requires a bit of (two-step) programming.
The following shell script works for me very well. It prints both revisions and corresponding lines. If you only need a list of versions, you can add a step to break the corresponding text and leave only the revision prefix and possibly pass it through "sort -u":
#!/bin/bash # # script to grep for a pattern in all revisions of a file # Usage: scriptname 'pattern' filepath # function fatal() { echo " $@ " 1>&2 exit 1 } function usage() { echo " $@ " 1>&2 fatal Usage: $0 pattern file } case "$1" in '') usage 'missing pattern to search for' ;; *) Pat="$1" ;; esac if [ "$2" != '' ]; then File="$2" else usage 'must pass file as 2nd argument' fi # -- generate list of revisions (change-sets) involving $File for rev in `hg log --template '{rev}\n' $File`; do # -- grep the wanted pattern in that particular revision hg grep "$Pat" -r $rev $File done
Notes:
- not completely reliable (for example, quotation marks in a template)
- I do not check for the existence of a file to support renamed / deleted files.
source share