Moved lines detection

Post your new features ideas and suggestions here.
Post Reply
tostme
Posts: 5
Joined: Thu Jun 19, 2008 10:25 am

Moved lines detection

Post by tostme »

Hi,

Here is one more question about moved lines. I know detecting moved lines in source code is not a trivial algorithm, but I hope you can improve it a little.

In my case when I compare two source code files it detects most of moved lines okay, but there are two little problems:

1. If a continuous block of code with several methods (with empty lines between them) was moved, then Compare It detects every method as a separate move block. I would really like to see it as a single move block. That is if I moved 50 lines of code with three methods, then instead of one move block for 50 lines Compare It shows me three separate move blocks.

2. Some lines are not detected as moved. For example, if I moved a whole class down, then it could be that the beginning of the class and the first method are not detected as a moved block.

If you want I can provide my files.

grigsoft
Site Admin
Posts: 1673
Joined: Tue Sep 23, 2003 7:37 pm
Contact:

Post by grigsoft »

Detecting moved lines is not a problem itself, it just takes some time. Currently only full changes blocks are searched. Otherwise it would be necessary to search for each individual line + each combination of them, which would take time. Maybe there is a reason to add some depth level, similar to that of partial match, so it would be possible to choose if you want to spend more time and search for all moved blocks\lines.
Merging of moved blocks, separated with blank lines could be useful, I will try to implement this. Thank you for suggestion!

tostme
Posts: 5
Joined: Thu Jun 19, 2008 10:25 am

Post by tostme »

Here is an example. This whole method (and actually many more code above and below it) were moved (or basically the class and the file were renamed). I inserted "---" to show boundaries of detected move blocks. Ideally I would want to see it all as a single moved block. Lines starting with "xxx" are not detected as moved.

-------------------------
/// <summary>
/// This code was copied and modified from Rotor.
/// Performs a binary search without boxing elements of the array.
/// </summary>
public static int BinarySearch(int[] array, int index, int length, int value)
{
Debug.Assert(array != null);
-------------------------
xxx
-------------------------
int lb = array.GetLowerBound(0);
Debug.Assert((index >= lb) && (length >= 0));
-------------------------
xxx
-------------------------
Debug.Assert(array.Length - index >= length);
Debug.Assert(array.Rank == 1);
-------------------------
xxx
-------------------------
int lo = index;
int hi = index + length - 1;
-------------------------
xxx
-------------------------
xxx while (lo <= hi)
xxx {
xxx int i = (lo + hi) >> 1;
xxx
-------------------------
int v = array;
-------------------------
xxx
-------------------------
if (v == value) return i;
if (v < value)
{
lo = i + 1;
}
else
{
hi = i - 1;
}
}
-------------------------
xxx
xxx return ~lo;
xxx }
xxx


So as you can see I could be facing a hundred moves instead of where I would expect just one :)

grigsoft
Site Admin
Posts: 1673
Joined: Tue Sep 23, 2003 7:37 pm
Contact:

Post by grigsoft »

Thank you! Yes, I understand the problem. I will try to fix that.

Post Reply