Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff'ing using the TFS API

Does anyone know if it is possible to use the TFS Difference.DiffFiles() methods on files that are not under source control? I know when I am in the source control UI I can select local paths that let me move outside of the workspace. I have made some efforts towards getting this to work but I am not sure how to read the DiffSegment results.

    options.Flags = DiffOptionFlags.None;
    options.OutputType = DiffOutputType.Unified;
    options.TargetEncoding = Console.OutputEncoding;
    options.SourceEncoding = Console.OutputEncoding;
    options.StreamWriter = new StreamWriter(memStream);
    options.StreamWriter.AutoFlush = true;

    DiffSegment seg = Difference.DiffFiles(pathA, Encoding.UTF8.WindowsCodePage, pathB, Encoding.UTF8.WindowsCodePage, options);

In some lite testing I can seem to see segments that get added but the OriginalStart seems to match the ModifiedStart so I just may not want to do this. If anyone has recommendations on a decent Diff API I'm open.

like image 960
hal9000 Avatar asked Feb 27 '12 23:02

hal9000


1 Answers

tfs api most definitely allows you to compare two local files. I don't think you need most of the DiffOptionFlags, you can just do the following:

DiffSegment segment = Difference.DiffFiles(
    file1, 
    FileType.Detect(file1, null), 
    file2, 
    FileType.Detect(file2, null), 
    new DiffOptions());

As Mohamed describes briefly here.

Russell describes in details what to do with DiffSegment here.

For example I did the following

do
{
    Console.WriteLine(segment.Type + " " + segment.OriginalStart + " " + Segment.OriginalLength);
} while ((segment = segment.Next) != null);

Hope this helps!

like image 98
MichalMa Avatar answered Nov 16 '22 03:11

MichalMa