Mercurial - view all changesets that change a specific line in a file

Annotate allows you to see the most recent change on this line, if that change is a merge, then I have no choice but to break through the change history and find the next time it is changed.

I also tried hg grep -l '[contents of line]' , but:

  • a) I can’t figure out how to target specific files (so a moderate size repository is required forever)
  • b) Only the last version number seems to return

The following link is vaguely similar - How can I find all the changes in which the function reference has been changed?

+6
source share
3 answers

Use Tortoisehg:

  • Browse β†’ Manifesto
  • Right-click the file of interest and click File History
  • click annotate version numbers

The upper panel allows you to quickly view the file history from the point of view of fixing, the lower panel displays an annotated file based on the selected version in the upper panel.

+8
source

Using arielf answer without additional script:

UNIX:

  • Command:

     hg log --template '{rev}\n' <FILE> | xargs -I @ hg grep <PATTERN> -r @ <FILE> 
  • you can use this to add an alias to your configuration file (.hgrc):

     [alias] _grep_line_in_history = ! $HG log --template '{rev}\n' $2 | xargs -I @ hg grep '$1' -r @ $2 

WINDOWS:

  • Command:

     FOR /F "usebackq" %i IN (`hg log --template "{rev}\n" <FILE>`) DO @(echo %i & hg grep <PATTERN> -r %i <FILE>) 
  • nickname:

     [alias] _grep_line_in_history = ! FOR /F "usebackq" %i IN (`%HG% log --template "{rev}\n" "$2"`) DO @(echo %i & %HG% grep "$1" -r %i "$2") 
+2
source

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.
+1
source

All Articles