Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to search a set of diffs for a particular string for a file?

Tags:

mercurial

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?

like image 605
jcollum Avatar asked Jul 05 '12 17:07

jcollum


2 Answers

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.

like image 168
Tim Henigan Avatar answered Oct 08 '22 09:10

Tim Henigan


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.

like image 42
Steve S Avatar answered Oct 08 '22 08:10

Steve S