Function History with Mercurial

I would like to be able to get the full history of a function or a specific text block inside my code.

I know that I may have differences between all my commits in a specific file, but I only want to monitor the life of a certain small block of text inside my files (for example, the C ++ function).

I want this to change, despite previous versions, whether it is moved inside a file or to another file or even renamed (the rest of the function remains more or less the same when renaming)

I heard that Mercurial could do this easily by correctly recording the story, but I donโ€™t remember where I heard it (in a dream?), And I canโ€™t find any tool or way to do this other than traditional history and tools. Maybe I'm not looking for suitable keywords ... Who can help?

thanks

PS: I still use SVN for other projects, and if someone knows a way to do the same with SVN, I accept it too :-)

+8
function dvcs svn mercurial
source share
2 answers

This is actually quite doable with hg grep . The example speaks for itself:

 $ hg grep 'def revrange' --all mercurial/cmdutil.py:14319:-:def revrange(repo, revs): mercurial/scmutil.py:14319:+:def revrange(repo, revs): mercurial/cmdutil.py:3707:-:def revrange(ui, repo, revs): mercurial/cmdutil.py:3707:+:def revrange(repo, revs): mercurial/cmdutil.py:3090:+:def revrange(ui, repo, revs): mercurial/commands.py:3090:-:def revrange(ui, repo, revs): mercurial/commands.py:2331:-:def revrange(ui, repo, revs, revlog=None): mercurial/commands.py:2331:+:def revrange(ui, repo, revs): mercurial/commands.py:705:-:def revrange(ui, repo, revs = [], revlog = None): mercurial/commands.py:705:+:def revrange(ui, repo, revs, revlog=None): mercurial/commands.py:697:-:def revrange(ui, repo, revs = [], revlog = None): mercurial/commands.py:697:+:def revrange(ui, repo, revs, revlog=None): mercurial/commands.py:580:+:def revrange(ui, repo, revs = [], revlog = None): 

I asked hg find def revrange (function definition). Combined with the --all flag on grep , this prints each revision that contains a change in compliance state.

Thus, we can easily see the evolution of this function:

  • it was first introduced in edition 580, in commands.py
  • 697 removed the default argument revs
  • 705 seems like a merger
  • 2331 removed the argument revlog
  • 3090 moved the function to cmdutil.py
  • 3707 deleted the argument ui
  • and finally 14319 moved the function to scmutil.py

Of course, this is not ideal, because if the function was renamed, the chain will end after renaming. But depending on your particular use case, this may be enough.

To be more complex, you can write a relatively simple script that can even perform renames.

+4
source share

Studying the delta and / or the hg log, it does not seem to be able to do what your request or have enough information to write a script to regularly express the information. If you wanted, you could see the changes that happened to the file over a period of time and look for them for what you are looking for.

0
source share