1

Currently I am trying to obtain the number of changed lines between two version of a source files, I currently do this by splitting the string I get from the Streamwriter.

        var rev1 = new DiffItemVersionedFile(versionControl, path, VersionSpec.ParseSingleSpec(latestVersion, null));
        var rev2 = new DiffItemVersionedFile(versionControl, path, VersionSpec.ParseSingleSpec(previousVersion, null));
        var stream = new MemoryStream();

        var writer = new StreamWriter(stream);
        {
            var options = new DiffOptions();

            options.Flags = DiffOptionFlags.EnablePreambleHandling;

            options.OutputType = DiffOutputType.Unified;
            options.TargetEncoding = Encoding.UTF8;
            options.SourceEncoding = Encoding.UTF8;
            options.StreamWriter = writer;
            Difference.DiffFiles(versionControl, rev1, rev2, options, path, true);

            writer.Flush();
            var diff = Encoding.UTF8.GetString(stream.ToArray());                
        }

That's what I'm currently obtaining from the Stream, formating looks a bit awkward, but there should be a more easy way to do this, since there usally is a structured object behind thats accesable.

$/MainProject/Development/Client/SubFolder1/SubFolder2/interface/uEPagesShopInterfaceVariantenVorlagen.pas

CodeLines

@@ -994,7 +995,7 @@

moreCode

  • deletedLine
  • addedLine

    more code
    @@ -1692,6 +1693,8 @@
    some code

  • addedLine
  • addedLine some more code
joachim
  • 652
  • 2
  • 7
  • 23
  • You may want to have a look at [this answer](http://stackoverflow.com/questions/24887238/how-to-compare-two-rich-text-box-contents-and-highlight-the-characters-that-are/24970638?s=1|0.2731#24970638); it point to a very nice and powerful tool. Wrinting a good Diff is tough and not necessary. – TaW Feb 24 '15 at 10:28
  • What are you trying to achieve? – MrHinsh - Martin Hinshelwood Feb 24 '15 at 18:18
  • I would like to determine the complexity of 2 versions of a source file, based on a few parameters one of them would be the lines of code changed. – joachim Feb 25 '15 at 09:00

1 Answers1

0

May be this is what you are looking for:

http://www.codeproject.com/Articles/6943/A-Generic-Reusable-Diff-Algorithm-in-C-II

MehaJain
  • 55
  • 1
  • 10