示例#1
0
        /// <summary>
        /// Perform 3-way diff, this is done by comparing the changes to local and remote. This may
        /// result in conflicts if the changes overlap
        /// </summary>
        /// <param name="ancestor">
        /// A common version of the file that both local and remote derived from
        /// </param>
        /// <param name="local">
        /// One version derived from the ancestor. The local and remote parameters are symmetric and
        /// can be swapped
        /// </param>
        /// <param name="remote">
        /// One version derived from the ancestor. The local and remote parameters are symmetric and
        /// can be swapped
        /// </param>
        /// <returns>
        /// An object that contains a list of all the conflicts that were detected as well as all
        /// the changes and the trees
        /// </returns>
        public static Diff3Result Compare(SyntaxTree ancestor, SyntaxTree local, SyntaxTree remote)
        {
            var localChanges  = Diff.Compare(ancestor, local).CacheEnumerable();
            var remoteChanges = Diff.Compare(ancestor, remote).CacheEnumerable();

            return(new Diff3Result
            {
                Conflicts = GetConflicts(localChanges, remoteChanges, ancestor, local, remote),
                Local = localChanges,
                Remote = remoteChanges,
                AncestorTree = ancestor,
                LocalTree = local,
                RemoteTree = remote,
            });
        }
示例#2
0
        //Given the base class and a file that contains another version of the file
        private static IEnumerable <Diff> DiffClassVersion(ClassDeclarationSyntax b, RepoFile f)
        {
            var ancestorDecs = f.BaseTree
                               .GetRoot()
                               .DescendantNodes()
                               .OfType <ClassDeclarationSyntax>();

            var remoteDecs = f.HeadTree
                             .GetRoot()
                             .DescendantNodes()
                             .OfType <ClassDeclarationSyntax>();

            var merged = MergeClassDeclarationSyntaxes(ancestorDecs, remoteDecs)
                         .FirstOrDefault(t => AreSameClass(t.Item1, b));

            return(Diff.Compare(merged.Item1, merged.Item2)
                   .Where(d => TriviaCompare.IsSemanticChange(d.Ancestor.Node, d.Changed.Node)));
        }