Search code examples
mercurial

Mercurial repository statistics, for finding candidates for refactoring?


In a busy repository, I can foresee some files with too much central logic in one place being edited constantly.

Is there any way to find such files by asking Mercurial, either through bundled extensions, 3rd party extensions, or any external tools?

Basically I'd like some statistics that shows files that are edited the most over time, so that I can use this to find candidates for splitting, like refactoring the code into multiple files, to avoid having constant merge pain for single files.

I'm aware of the churn extension, but it seems to only focus on how much each author does to the repository, not what the authors do it to.


Solution

  • I don't think any of the churn, activity, or chart extensions does exactly that, though they're all a simple tweak away from it I think (they group by user not by file).

    You could use a loop like:

    for therev in $(seq 1 $(hg id -n -r tip)) ; do
      hg diff --change $therev --stats
    done
    

    And then total by file.