简体   繁体   English

计算两个版本之间的代码行

[英]count lines of code between two versions

Is there any way to compare lines of code between two clearcase versions , or for that matter whatever the version controller , I want to compare two different version say compare main branch with the development branch. 有什么方法可以比较两个Clearcase版本之间的代码行,或者无论哪种版本控制器,我想比较两个不同的版本,比如说比较主分支和开发分支。 I'm looking this topic for Java 我正在为Java寻找此主题

如果需要比较+查看+编辑行,则VonC对WinMerge的建议非常好, 但是如果需要比较行数(计数),则最好使用像ProjectCodeMeterCLOC这样的sloc diff工具。

While you can use any diff/merge tool (like WinMerge on Windows) to get a comparison on an all set of files, I would recommend using: 虽然您可以使用任何差异/合并工具(例如Windows上的WinMerge )对所有文件进行比较,但我建议使用:

  • two ClearCase views with the right configuration to select the right versions 两个具有正确配置的ClearCase视图以选择正确的版本
  • two dynamic views in order to quickly get all the relevant versions (snapshot views would be too long to load) 两个动态视图以快速获取所有相关版本(快照视图加载太长)

there are loads of merge/diff tools. 有很多合并/差异工具。 i use meld which has great visualisation and handling of file and directory comparision 我使用具有出色的可视化和文件和目录比较处理能力的融合

If the only thing you want to do is to count lines and you are using svn I suggest you to run 如果您唯一想做的就是计数行数,而您正在使用svn,建议您运行

svn blame -r N:M | wc -l

I cannot check that this command line is working right now but the idea is to use svn blame between 2 interesting revisions (N and M) and then run wc -l (line count). 我无法检查此命令行现在是否正常运行,但是我的想法是在2个有趣的修订版(N和M)之间使用svn blame ,然后运行wc -l (行数)。

I believe that every source control has command similar to svn blame . 我相信每个源代码控制都具有类似于svn blame命令。

You can as VonC suggest use two different views. 您可以像VonC建议的那样使用两种不同的观点。 Alternatively you can use the file@@version syntax to access both versions directly if you know exactly what you are looking for. 另外,如果您确切知道要查找的内容,则可以使用file@@version语法直接访问两个版本。 Two views are probably the best option if you are going to automate something (which implementing something in java suggests to me). 如果要自动执行某些操作(在Java中实现某些操作会提示我),则两个视图可能是最佳选择。

When you say "compare lines of code between two clearcase versions" I assume you are looking for something other than the standard cleartool diff (btw, KDiff3 is an excellent diff utility which have clearcase integration, I highly reccommend it), and assume it is more in the "count number of lines" direction you are looking. 当您说“比较两个clearcase版本之间的代码行”时,我假设您正在寻找除标准cleartool diff之外的其他东西(顺便说一句, KDiff3是一个出色的diff实用程序,具有clearcase集成,我强烈推荐它),并假设它是您正在寻找“行数计数”方向的更多信息。

However just counting difference in lines will only give limited information, usually it is also interesting to know if the lines that constitutes the difference are mostly added or removed. 但是,仅对行之间的差异进行计数将仅提供有限的信息,通常还很有趣的是,了解构成差异的行是否主要是添加还是删除。 To give this kind of information you can use diffstat (see this answer for example output). 要提供此类信息,您可以使用diffstat (请参见此答案以获取示例输出)。

At my last job I wrote a java gui for running 在上一份工作中,我写了一个Java gui来运行

diff -u file@@/main/branch1/LABEL1 file@@/main/branch2/LABEL2 | diffstat

given two labels, iterating over several files, but I then depended on bash, diff and diffstat from cygwin, I am not aware of any pure java alternatives here. 给定两个标签,遍历几个文件,但是然后我依赖cygwin的bash,diff和diffstat,因此我不知道这里有任何纯Java替代方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM