I'd like to search the diffs of one file (ideally a set of files) for a specified set of revisions (or all). I'm looking for a diff report that is text searchable. I've got this:
hg diff -r 0:47131 .\TheFile.cs | grep 'theSearch' -Context 50
OK, that works well enough, but deciding how much context to include is an issue as well as finding the first and last revision. I can automate this better but it seems like it'll be a bit of work.
I'm wondering if there's a tool out there that will do this better. Maybe a diff report web page for the hg server?
You can use hg grep
to search the entire repo history.
For example:
hg grep --all --include .\TheFile.cs 'theSearch'
will find all instances of 'theSearch'
in every revision of the repo. Without the --all
flag, it stops at the first revision that includes the string.
I've a feeling that hg grep
searches the contents of the entire file for every matching revision. Whereas if you want to search only the diff, try something like this:
hg log --template "{ifcontains('TODO', diff(), '{node} {desc}\n', '')}"
This will list revisions containing "TODO" in their diff. Note this will also search lines removed as well as the diff context (+/- 3 lines), so it's not perfect.
You can restrict further using args to diff() - see hg help template
- and using revsets (-r ...
).
This may be better than using your hg diff | grep
approach because it diffs each changeset one by one rather than diffing the entire repo across two changesets, and allows you to use revsets to filter out merge revisions, for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With