Computers, Science, Technology, Xen Virtualization, Hosting, Photography, The Internet, Geekdom And More

Mercurial Tricks : Counting Insertions

Posted on | December 10, 2010 | 2 Comments

Do you have a policy where patches that make above nn number of insertions or deletions require review before being pushed? We do, but the policy is quite loose. Actually, it is sufficiently loose to manage the whole process with simple commit hooks.

I was digging through Mercurial today to see if it had a feature to tell me how many lines I added or removed, but I didn’t see anything. So, I’m using this (somewhat inaccurate) hack to determine if a hook has to send e-mail:

hg diff -r tip | grep ^+ | sed -e '/^+++/d' | wc -l

hg diff -r tip | grep ^- | sed -e '/^---/d' | wc -l

Not 100% accurate, but it does let commit hooks do trivial things for you when you commit a substantial patch. ┬áIt’s basically just counting the number of insertions and removals from a diff against the previous tip.

May come in handy for someone, so I decided to post it. My last commit was 12,550 lines inserted .. and it wasn’t even a merge :) Yeowzers.


2 Responses to “Mercurial Tricks : Counting Insertions”

  1. Tim G
    December 23rd, 2010 @ 11:31 am

    Good Hint :)

    You could also pipe a diff to the application ‘diffstat’, which not only will calculate the amount of lines which have been inserted and deleted, but it will also show which files have the most inserts/deletes

  2. tinkertim
    December 27th, 2010 @ 4:58 am

    @Tim G that comes dangerously close to extensions that do the same :) My HG posts are usually working with it out of the box, so to say.

Leave a Reply

  • Monkey Plus Typewriter
  • Stack Overflow

  • Me According To Ohloh

  • Meta