Counting changed lines of code over time

前端 未结 3 890
长情又很酷
长情又很酷 2021-02-01 02:24

Is there any good tool that computes the number of changed lines of code over a certain time period in a mercurial repository? Something along the lines of statsvn would be grea

3条回答
  •  囚心锁ツ
    2021-02-01 03:01

    Edit: hg diff and hg log both support a --stat option that can do this for you, only better and quicker.


    I made an alias called lines to count changed lines (not necessarily lines of code) for me. Try putting this alias in your .hgrc file:

    [alias]
    lines = !echo `hg log -pr $@ | grep "^+" | wc -l` Additions; echo `hg log -pr $@ | grep "^-" | wc -l` Deletions; 
    

    Then pass it the revision first, followed by any optional arguments:

    hg lines tip or hg lines 123:456 -u brian

    Sometimes you want to know the number of lines changed excluding whitespace-only changes. This requires using diff -w underneath instead of log -p. I set up a linesw alias for this:

    #ignore whitespace
    linesw = ![[ $1 =~ : ]] && r=$1 || r="$1~1:$1"; echo `hg diff -wr $r | grep "^+\([^+]\|$\)" | wc -l` Additions; echo `hg diff -wr $r | grep "^-\([^-]\|$\)" | wc -l` Deletions; 
    

    hg linesw tip or hg lines 123:456

    Note they behave slightly differently because diff and log behave differently -- for example, log will take a --user parameter while diff will not, and when passing a range, log will show changes commited in the first revision given in the range, while diff will not.

    This has only been tested using bash.

提交回复
热议问题