version-controlmercurial

Finding changes to a block of text with mercurial


I have a text file that I'd like to track changes with. It's a file that stores values (as well as strings and arrays) and has the following format for its entries:

NAME: some_name
  UNIT: some_unit
  ...
  VALUE: 10
  ...
END

I can setup a repsoitory and track changes on this file to see when VALUEs change, BUT how can I understand the change history of an entry like some_name? The value changing shows up but since the line with NAME: some_name doesn't change I'm not seeing it in search results. So as of now I don't see how I can see when the last time some_name changed or how many times it has changed, etc.

I think this would be similar to understanding the change history of a function, where the user would like to understand the history of the entire function between various revisions.

As of now I'm working with TortoiseHg on a preliminary setup so I'm open to switching tools at this point, I'm also completely new to version-control.


Solution

  • In mercurial the hg grep command accepts python regular expressions.

    grep

    search revision history for a pattern in specified files:

    hg grep [OPTION]... PATTERN [FILE]... Search revision history for a regular expression in the specified files or the entire project.

    So hg grep --diff "(\bsome_name\b)(.|\s)*?(\bEND\b)" will match the text from some_name to END and will return the changes that happened within this chunk of text. Try it here and adapted from here.

    Also, the same can be accomplished in TortoiseHg using View>Search and putting the regex (\bsome_name\b)(.|\s)*?(\bEND\b) in the Search field (see here).