예제 #1
0
파일: DiffHelper.cs 프로젝트: Gvin/Diplom
 public static ArrayList GetDifference(TextFile source, TextFile destination)
 {
     var engine = new DiffEngine();
     engine.ProcessDiff(source, destination, DiffEngineLevel.FastImperfect);
     return engine.DiffReport();
 }
예제 #2
0
        private List<Change> GetFileChanges(String repositoryPath, String commitPath, RepositoryFile file)
        {
            var result = new List<Change>();

            var sourcePath = file.GetFileRealPath(repositoryPath);
            var destinationPath = file.GetFileRealPath(commitPath);

            TextFile sourceFile;
            TextFile destinationFile;
            if (System.IO.File.Exists(destinationPath))
            {
                destinationFile = new TextFile(destinationPath);
            }
            else
            {
                destinationFile = new TextFile();
                DataManager.GetInstance().MarkFileAsDeleted(file);
            }

            sourceFile = new TextFile(sourcePath);

            var difference = DiffHelper.GetDifference(sourceFile, destinationFile);

            foreach (DiffResultSpan diffResultSpan in difference)
            {
                switch (diffResultSpan.Status)
                {
                    case DiffResultSpanStatus.DeleteSource:
                        for (int i = 0; i < diffResultSpan.Length; i++)
                        {
                            var change = new Change(file, ChangeType.Remove, diffResultSpan.SourceIndex,
                                                    ((TextLine) sourceFile.GetByIndex(diffResultSpan.SourceIndex + i)).
                                                        Line);
                            result.Add(change);
                        }
                        break;
                    case DiffResultSpanStatus.AddDestination:
                        for (int i = 0; i < diffResultSpan.Length; i++)
                        {
                            var change = new Change(file, ChangeType.Add, diffResultSpan.DestIndex,
                                                    ((TextLine)destinationFile.GetByIndex(diffResultSpan.DestIndex + i)).
                                                        Line);
                            result.Add(change);
                        }
                        break;
                    case DiffResultSpanStatus.Replace:
                        for (int i = 0; i < diffResultSpan.Length; i++)
                        {
                            var change = new Change(file, ChangeType.Update, diffResultSpan.SourceIndex,
                                                    ((TextLine)sourceFile.GetByIndex(diffResultSpan.SourceIndex + i)).
                                                        Line);
                            result.Add(change);
                        }
                        break;
                }
            }

            return result;
        }