FC noob here. I have two VB.net files, old.vb and new.vb. The former has 33997 lines, and the latter 34956. The differences are:
- a small utility method was moved to a new Module at the top from its former location around line 15k
- three new methods were added in the body, all in a single block around line 7500
- another two methods were added in a single block around line 12000
- a single method was added near the end, around line 28000
- some very minor changes like WS and spelling in comments, all single-line edits
The customer has a reporting system based on an Excel workflow and has asked for diffs to be recorded in Excel. I started by copying the files into a worksheet side-by side, and then intended to color them to indicate the changes, as well as insert blank lines where required to get the code to line up again. For the list of diffs, I intended to use FC.
For testing, I ran the diffs manually in Notepad++'s Compare tool, which produced a list of about a dozen changes that were lines up exactly like I want. Excellent!
So then I did this:
FC /a /n /w /lb 50000 c:\old.vb c:\new.vb > c:\temp\changes.txt
This produces a list of 257 changes. Only the first item, the moved routine, is listed as a single block. All of the rest are fragments where FC has lined up similar lines of code in totally unrelated parts of the file.
For instance, in the new file I inserted a 25 line method called ReportExpenseImport directly above one called ReportManagementFees. Here is the diff it reports:
here is the second diff, where I have inserted a new method above an existing one:
***** C:\old.vb
7480: End Sub
7481: #If True Then
7482: '----------------------------------------------------------------------------------
7483: Friend Sub ReportManagementFees(Props As List(Of Property))
7484: '
7485: 'WRITES A REPORT OF WHERE THE MANAGEMENT FEES COME FROM
7486: Dim DbF As DBFactory
7487: Dim DS As RecordSet
7488: Dim SQL As String
7489: Dim WS As WorkSheet
***** C:\NEW.VB
7497: End Sub
7498: ''----------------------------------------------------------------------------------
7499: 'Public Sub ReportMissingExpenses(RptId As Integer, Props As List(Of Property))
7500: ' '
7501: ' 'WRITES A REPORT COMPARING THE ACCOUNTS TO THE
7502: ' 'EXPENSES
7503: ' Dim DbA As DBFactory
7504: ' Dim DS As RecordSet
7505: ' Dim WS As WorkSheet
7506: ' Dim R As Integer
7507: ' Dim SQL As String
ReportMissingExpenses is the next method in the file, after ReportManagementFees. So it's matching one old routine with another old one and the actual inserted block isn't listed anywhere that I can see. It seems to be matching on small subsets of the file, wherever there is similar code even a couple of lines long? My feeling is:
I have not set the command line switches properly, perhaps /lb? I tried a number of different values here - too small and I get a resync and the compare fails entirely, anything above that limit (around 1000 lines) and I get the results above. I used 50k in this particular run as that is larger than either file, but even 250000 doesn't change the outcome.
I am misinterpreting the results. Each "break" in FC's output has a start and end line, which as noted above, seem to be misaligned. But perhaps I simply don't understand what it's saying? But in this case, why would it list ~250 changes when there's really only a couple of blocks being added?
I suspect (1) is the issue, but the documentation is rather sparse. There are very few threads on the topic here on SO and all of the 3rd party sites just scrape MS.
Alternately, if someone is familiar with a better command line tool, I'm happy to try it.
WinMerge is almost the solution.
WinMerge rapidly performed a perfect compare on the two files. I opened the two files and saved the "merge report" to a temp file, and then opened that in VBA as a String(). Each array entry represents a possible diff, but you have to filter out the many informational lines and look for the "command lines" that start with a digit. In my case, there were 1018 lines in the merge file, but only 15 command lines.
The command lines are of the form line1[,line2][a|d|c]line1[,line2]. For instance, if there are new lines added to the newer file, you will get something like "1234a2345,3456". This means 3456-2345 = 1111 have been added to file 2, so to make the two files line up again, you insert 1111 cells below line 1234 in file 1.
It takes a few seconds to do all the inserts, but once complete I ended up with a recreation of the original merge display in Excel.
The almost is that I haven't figured out save out the merge file using the command line. The documentation is rather limited and many entries are marked "TBD". However, since the inner engine appears to be GNU, and the format of the merge report is identical across modern implementations, the same VBA code will work with any modern diff (which, it appears, FC is not).