Search code examples
c#.netexceltfsunified-diff

Read Unified Diff & extract to excel


I have extracted the Code difference in Unified format from TFS. Now I want to read this diff text (unified format) and then extract it to an excel in a customized format. So what I need is like a parser which can read the diff text and get me the deleted/added changes, line number etc. Here is what I want to achieve, let's say TFS generated the following difference

@@ -212,8 +223,8 @@
          </XYZ>
           <modules>
            Some text ABC
              -        <New_tag_part1>AAAAAAA</New_tag_part1>
              -        <New_tag_part2>BBBBBBB </New_tag_part2>
              +        <New_tag_part1> CCCCCC </New_tag_part1>
              +        <New_tag_part2> DDDDDD </New_tag_part2>

Now I want to read this text & then move it to an excel which might have columns like this Changes_Added Changes_Deleted Line-No I have tried to use ParseDiff nuget package but due to lack of documentation I am not sure whether it can read the unified diff text or how to use it. Is there any standard parsers available in .Net/C# which I can use? If not any alternatives would be appreciated.


Solution

  • ParseDiff do read the unified diff text. The method to use it is included in the test code in its source code on GitHub, you can refer to this link for details:https://github.com/jkingry/ParseDiff/blob/master/src/ParseDiff.Tests/TestDiff.cs