计算存储库中随时间变化的代码行数

发布于 2024-09-06 02:35:24 字数 174 浏览 1 评论 0原文

有没有办法获取 Mercurial 存储库中特定时间段内更改的代码行数?类似于 statsvn 所做的事情会很棒,但是任何计算其中更改的代码行数的东西6 个月就可以了(包括 hg log 参数的巧妙组合)。

Is there a way to obtain the number of changed lines of code over a certain time period in a mercurial repository? Something along the lines of what statsvn does would be great, but anything counting the number of changed lines of code within 6 months will do (including a clever combination of arguments to hg log).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

渡你暖光 2024-09-13 02:35:24

hg 流失扩展 就是您想要的。

您可以通过 hg 活动汞图表

The hg churn extension is what you want.

You can get visual results with hg activity or hg chart.

零時差 2024-09-13 02:35:24

编辑hg diffhg log 都支持 --stat 选项,只能为您执行此操作更好更快。


我创建了一个名为 lines 的别名来为我计算更改的行数(不一定是代码行数)。尝试将此别名放入您的 .hgrc 文件中:

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

然后首先传递修订版本,然后传递任何可选参数:

hglinestiphglines123:456 -u brian

有时您想知道更改的行数(不包括仅空格的更改)。这需要在下面使用 diff -w 而不是 log -p。我为此设置了一个 linesw 别名:

#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; 

hglineswtiphglines123:456

请注意,它们的行为略有不同,因为 diff< /code> 和 log 的行为不同 - 例如,log 将采用 --user 参数,而 diff不会,并且在传递范围时,log 将显示在范围内给定的第一个修订版中提交的更改,而 diff 则不会。

这仅使用 bash 进行过测试。

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.

写给空气的情书 2024-09-13 02:35:24

我需要这样做,并花了相当多的时间来研究 hg churn 扩展和类似的解决方案。

最后,我发现最适合我的是 CLOC(计算代码行数):http://cloc.sourceforge.net/

您可以给它两个包含项目的两个版本的文件夹,它会计算所有相同、修改、添加、删除的行。它可以识别多种语言并逐项列出代码、注释和空行。

为了使用它,我将代码的两个版本从 Hg 提取到两个并行文件夹中,然后使用 cloc --diff --ignore-whitespace

I needed to do this, and spent quite a bit of time with the hg churn extension and similar solutions.

In the end, I found that what worked best for me was CLOC (Count Lines of Code): http://cloc.sourceforge.net/

You can give it two folders containing two versions of a project, and it will count all of the lines that are the same, modified, added, removed. It recognises multiple languages and itemises code, comments and blank lines.

To use it, I pulled out the two versions of my code from Hg into two parallel folders, and then used cloc --diff --ignore-whitespace

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文