Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding changesets in mercurial by grepping the patch

Tags:

Is there a way in mercurial to find a change by giving a pattern in the edit (the changed code), as opposed to the log message or filename?

I've looked pretty thoroughly in "hg help revsets" and I think there's not a good way to do this. Here's the best hack I came up with, but I'm hoping I missed a capability, or that someone can do a little better.

hg log -M -u goldberg -p | grep '(^changeset:\|<pattern>)' | grep -C 1 '<pattern>'

(and then manually selecting the revision number for later work with those revisions)

like image 258
Joshua Goldberg Avatar asked Mar 16 '11 19:03

Joshua Goldberg


People also ask

How do I revert a changeset in Mercurial?

Revert changes already committed To backout a specific changeset use hg backout -r CHANGESET . This will prompt you directly with a request for the commit message to use in the backout. To revert a file to a specific changeset, use hg revert -r CHANGESET FILENAME . This will revert the file without committing it.

How do you undo a pull in Mercurial?

There is only one level of rollback, and there is no way to undo a rollback. It will also restore the dirstate at the time of the last transaction, losing any dirstate changes since that time. This command does not alter the working directory.

What is Patch in Mercurial?

Patch fileThese files are also called diffs, as they were traditionally generated by the 'diff' program. While there are many different formats for patch files, the most common is the unified diff format. Mercurial can generate patch files in the unified diff format with the hg diff command.

How do I know my Mercurial version?

If you already have Mercurial installed, make sure you have version 1.7 or later. To check, enter hg --version at the command line.


1 Answers

You should take a look at hg grep.

Search revisions of files for a regular expression.  This command behaves differently than Unix grep. It only accepts Python/Perl regexps. It searches repository history, not the working directory. It always prints the revision number in which a match appears.  By default, grep only prints output for the first revision of a file in which it finds a match. To get it to print every revision that contains a change in match status ("-" for a match that becomes a non-match,  or "+" for a non-match that becomes a match), use the --all flag.  Returns 0 if a match is found, 1 otherwise. 

You can type hg grep --help for more informations.

like image 62
krtek Avatar answered Nov 09 '22 00:11

krtek