开发者

Can Subversion report the percentage of code changed over time?

I would like to know on a line by line basis, what percentage of source code within a subversion repository has been modified between two commits.

For example. say revision 2100 has 150,000 lines of code -- but revision 2600 has 165,000 lines of code where 8,000 lines of the original 150,000 code where modified. I would report this as 142,000 / 165,000 = 86% the same, 14% "new". I don't care to separate Javadoc, XML, comments, or unit tests....just lump them al开发者_如何转开发l together as "source".

Any idea how to do this?


I just did this today using the free open-source tool CLOC. It allows you to compare two directories recursively, so all you need to do is have both versions checked out and run the program on it.

It also gives summaries for separate languages and total, for example:

Language                      files          blank        comment           code
--------------------------------------------------------------------------------
SUM:
 same                          1556              0          76662         165546
 modified                       137              0            159            570
 added                            2            241            257           1250
 removed                         30            591            906           2271

As you can see from the 'blank' statistic there, it's not perfect, but it definitely gives you a ballpark.


The metric you are looking for(I believe) is code churn.

There is a previous SO question on that!


I don't know of a simple way to do it, but you could parse diffs generated from the source files. By using the -r option to diff you can specify what range you want, i.e. 2100:2600. Using a unified diff, the number of changed (deleted or edited) lines would likely be the number of lines in your diff starting with '-'. Comparing them to total lines should get you close to your answer. This is of course only an approximation. If you have worked with patches for a while you'll know that simply reordering some lines will generate a diff showing more lines changed than you might expect, so take the number returned with a grain of salt.

Wikipedia has a short description of the formats. Default for svn should be a unified diff.


You could use diff as wds says, and do some bash / awk / sed scripting to obtain different reports. I don't know of a specific tool for this, but coding it would be a simple and fun task.


SVN has no built-in tools to do this. There are commercial tools like Fisheye which can generate various reports of repository activity, as well as provide browsing/searching capabilities. You could look at this and see if it meets your needs.

The other option would be to use "svn log" and "svn diff", combined with some scripting to tell you what you are looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜