How would you measure inserted / changed / removed code lines (LoC)?

谁都会走 提交于 2019-11-30 21:09:33

问题


My question concerns LoC metrics. I have to provide statistics of inserted, changed and removed lines. My users use ClearCase and the example below based on it, however I believe that my question is general.

Please have a look on the following example (taken from ClearCase documents). It compares two file versions, /main/1 (on the left side) and /main/3 (right side).

    ******************************** (file summary) 
    <<< file 1: util.c@@/main/1
    >>> file 2: util.c@@/main/3
    ********************************
    ----------[after 15]------|-------[inserted 16]------ (header) 
                              | char *s;        (difference) 
                              |-
    ---------[changed 18]-----|----[changed to 19-21]---- (header) 
    return ctime(&clock);     | s = ctime(&clock); (difference) 
                           -  | s[ strlen(s)-1 ] = '\0';
                              | return s;
                              |-

There's no doubt that 1 line was INSERTED (line 16).

My question refers to the change on line 18: how many lines do you count here?

  • 3 CHANGED lines?
  • 1 CHANGED line?
  • 1 CHANGED line and 2 INSERTED lines?
  • Do you think something else...?

Please let me know what you think about (and why...). Thank you.


回答1:


This example is from the cleartool diff man page, and that diff is not your usual diff format.

For ClearCase:

---------[changed X]----------|----------[changed to Y]---------

One or more lines changed in place.

  • X indicates which lines in the first file were changed.
  • Y indicates where the replacement lines occur in the second file.

So here:

  • 1 line changed
  • replaced by 3 lines

There is no direct equivalent with the diff unified format used by the other tools (like git), which means this question, using the default cleartool format, is specific to ClearCase.

If the cleartool diff used the -diff_format option, that would causes both the headers and differences to be reported in the style of the UNIX and Linux diff utility, which would let a more common interpretation of that diff.


Whe it comes to LOC and diff, a good reference is CLOC, which will give a diff loc focusing on lines whic are:

  • same
  • modified
  • added
  • removed

In your case:

  • 1 line modified
  • 2 lines added



回答2:


Most SCM systems let you scan files as they are submitted as part of a pre- or post- commit hook. You could run any scanning tool you like and record the statistics somewhere, perhaps as an attribute on the file.



来源:https://stackoverflow.com/questions/16107657/how-would-you-measure-inserted-changed-removed-code-lines-loc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!