示例#1
0
        private DiffSafeHandle BuildDiffList(ObjectId oldTreeId, ObjectId newTreeId, TreeComparisonHandleRetriever comparisonHandleRetriever,
                                             DiffModifiers diffOptions, IEnumerable <string> paths, ExplicitPathsOptions explicitPathsOptions,
                                             CompareOptions compareOptions)
        {
            var matchedPaths = new MatchedPathsAggregator();
            var filePaths    = repo.ToFilePaths(paths);

            using (GitDiffOptions options = BuildOptions(diffOptions, filePaths, matchedPaths, compareOptions))
            {
                var diffList = comparisonHandleRetriever(oldTreeId, newTreeId, options);

                if (explicitPathsOptions != null)
                {
                    try
                    {
                        DispatchUnmatchedPaths(explicitPathsOptions, filePaths, matchedPaths);
                    }
                    catch
                    {
                        diffList.Dispose();
                        throw;
                    }
                }

                DetectRenames(diffList, compareOptions);

                return(diffList);
            }
        }
示例#2
0
 internal ContentChanges(Repository repo, Blob oldBlob, Blob newBlob, GitDiffOptions options)
 {
     Proxy.git_diff_blobs(repo.Handle,
                          oldBlob != null ? oldBlob.Id : null,
                          newBlob != null ? newBlob.Id : null,
                          options, FileCallback, HunkCallback, LineCallback);
 }
示例#3
0
 /// <summary>
 ///   Show changes between two <see cref = "Blob"/>s.
 /// </summary>
 /// <param name = "oldBlob">The <see cref = "Blob"/> you want to compare from.</param>
 /// <param name = "newBlob">The <see cref = "Blob"/> you want to compare to.</param>
 /// <returns>A <see cref = "ContentChanges"/> containing the changes between the <paramref name = "oldBlob"/> and the <paramref name = "newBlob"/>.</returns>
 public virtual ContentChanges Compare(Blob oldBlob, Blob newBlob)
 {
     using (GitDiffOptions options = BuildOptions(DiffOptions.None))
     {
         return(new ContentChanges(repo, oldBlob, newBlob, options));
     }
 }
示例#4
0
 /// <summary>
 /// Show changes between two <see cref="Blob"/>s.
 /// </summary>
 /// <param name="oldBlob">The <see cref="Blob"/> you want to compare from.</param>
 /// <param name="newBlob">The <see cref="Blob"/> you want to compare to.</param>
 /// <param name="compareOptions">Additional options to define comparison behavior.</param>
 /// <returns>A <see cref="ContentChanges"/> containing the changes between the <paramref name="oldBlob"/> and the <paramref name="newBlob"/>.</returns>
 public virtual ContentChanges Compare(Blob oldBlob, Blob newBlob, CompareOptions compareOptions = null)
 {
     using (GitDiffOptions options = BuildOptions(DiffModifiers.None, compareOptions: compareOptions))
     {
         return(new ContentChanges(repo, oldBlob, newBlob, options));
     }
 }
示例#5
0
 internal ContentChanges(Repository repo, Blob oldBlob, Blob newBlob, GitDiffOptions options)
 {
     using (var osw1 = new ObjectSafeWrapper(oldBlob.Id, repo))
         using (var osw2 = new ObjectSafeWrapper(newBlob.Id, repo))
         {
             Ensure.Success(NativeMethods.git_diff_blobs(osw1.ObjectPtr, osw2.ObjectPtr, options, IntPtr.Zero, FileCallback, HunkCallback, LineCallback));
         }
 }
示例#6
0
        private static GitDiffOptions BuildOptions(DiffModifiers diffOptions, FilePath[] filePaths = null, MatchedPathsAggregator matchedPathsAggregator = null, CompareOptions compareOptions = null)
        {
            var options = new GitDiffOptions();

            options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_TYPECHANGE;

            compareOptions         = compareOptions ?? new CompareOptions();
            options.ContextLines   = (ushort)compareOptions.ContextLines;
            options.InterhunkLines = (ushort)compareOptions.InterhunkLines;

            if (diffOptions.HasFlag(DiffModifiers.IncludeUntracked))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNTRACKED |
                                 GitDiffOptionFlags.GIT_DIFF_RECURSE_UNTRACKED_DIRS |
                                 GitDiffOptionFlags.GIT_DIFF_SHOW_UNTRACKED_CONTENT;
            }

            if (diffOptions.HasFlag(DiffModifiers.IncludeIgnored))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_IGNORED |
                                 GitDiffOptionFlags.GIT_DIFF_RECURSE_IGNORED_DIRS;
            }

            if (diffOptions.HasFlag(DiffModifiers.IncludeUnmodified) || compareOptions.IncludeUnmodified ||
                (compareOptions.Similarity != null &&
                 (compareOptions.Similarity.RenameDetectionMode == RenameDetectionMode.CopiesHarder ||
                  compareOptions.Similarity.RenameDetectionMode == RenameDetectionMode.Exact)))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNMODIFIED;
            }

            if (compareOptions.Algorithm == DiffAlgorithm.Patience)
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_PATIENCE;
            }
            else if (compareOptions.Algorithm == DiffAlgorithm.Minimal)
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_MINIMAL;
            }

            if (diffOptions.HasFlag(DiffModifiers.DisablePathspecMatch))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_DISABLE_PATHSPEC_MATCH;
            }

            if (matchedPathsAggregator != null)
            {
                options.NotifyCallback = matchedPathsAggregator.OnGitDiffNotify;
            }

            if (filePaths != null)
            {
                options.PathSpec = GitStrArrayManaged.BuildFrom(filePaths);
            }

            return(options);
        }
示例#7
0
        /// <summary>
        ///   Show changes between the working directory and the index.
        /// </summary>
        /// <param name = "paths">The list of paths (either files or directories) that should be compared.</param>
        /// <param name = "includeUntracked">If true, include untracked files from the working dir as additions. Otherwise ignore them.</param>
        /// <returns>A <see cref = "TreeChanges"/> containing the changes between the working directory and the index.</returns>
        public virtual TreeChanges Compare(IEnumerable <string> paths = null, bool includeUntracked = false)
        {
            var comparer = WorkdirToIndex(repo);

            using (GitDiffOptions options = BuildOptions(includeUntracked ? DiffOptions.IncludeUntracked : DiffOptions.None, paths))
                using (DiffListSafeHandle dl = BuildDiffListFromComparer(null, comparer, options))
                {
                    return(new TreeChanges(dl));
                }
        }
示例#8
0
 /// <summary>
 ///   Show changes between two <see cref = "Tree"/>s.
 /// </summary>
 /// <param name = "oldTree">The <see cref = "Tree"/> you want to compare from.</param>
 /// <param name = "newTree">The <see cref = "Tree"/> you want to compare to.</param>
 /// <param name = "paths">The list of paths (either files or directories) that should be compared.</param>
 /// <returns>A <see cref = "TreeChanges"/> containing the changes between the <paramref name = "oldTree"/> and the <paramref name = "newTree"/>.</returns>
 public virtual TreeChanges Compare(Tree oldTree, Tree newTree, IEnumerable <string> paths = null)
 {
     using (GitDiffOptions options = BuildOptions(DiffOptions.None, paths))
         using (DiffListSafeHandle diff = BuildDiffListFromTrees(
                    oldTree != null ? oldTree.Id : null,
                    newTree != null ? newTree.Id : null,
                    options))
         {
             return(new TreeChanges(diff));
         }
 }
示例#9
0
        private DiffListSafeHandle BuildDiffListFromTrees(ObjectId oldTree, ObjectId newTree)
        {
            using (var osw1 = new ObjectSafeWrapper(oldTree, repo))
                using (var osw2 = new ObjectSafeWrapper(newTree, repo))
                {
                    DiffListSafeHandle diff;
                    GitDiffOptions     options = DefaultOptions;
                    Ensure.Success(NativeMethods.git_diff_tree_to_tree(repo.Handle, options, osw1.ObjectPtr, osw2.ObjectPtr, out diff));

                    return(diff);
                }
        }
示例#10
0
        /// <summary>
        ///   Show changes between a <see cref = "Tree"/> and the Index, the Working Directory, or both.
        /// </summary>
        /// <param name = "oldTree">The <see cref = "Tree"/> to compare from.</param>
        /// <param name = "diffTargets">The targets to compare to.</param>
        /// <param name = "paths">The list of paths (either files or directories) that should be compared.</param>
        /// <returns>A <see cref = "TreeChanges"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns>
        public virtual TreeChanges Compare(Tree oldTree, DiffTargets diffTargets, IEnumerable <string> paths = null)
        {
            var comparer = handleRetrieverDispatcher[diffTargets](repo);

            DiffOptions diffOptions = diffTargets.HasFlag(DiffTargets.WorkingDirectory) ?
                                      DiffOptions.IncludeUntracked : DiffOptions.None;

            using (GitDiffOptions options = BuildOptions(diffOptions, paths))
                using (DiffListSafeHandle dl = BuildDiffListFromTreeAndComparer(
                           oldTree != null ? oldTree.Id : null,
                           comparer, options))
                {
                    return(new TreeChanges(dl));
                }
        }
示例#11
0
        private static GitDiffOptions BuildOptions(DiffModifiers diffOptions, FilePath[] filePaths = null, MatchedPathsAggregator matchedPathsAggregator = null, CompareOptions compareOptions = null)
        {
            var options = new GitDiffOptions();

            options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_TYPECHANGE;

            compareOptions         = compareOptions ?? new CompareOptions();
            options.ContextLines   = (ushort)compareOptions.ContextLines;
            options.InterhunkLines = (ushort)compareOptions.InterhunkLines;

            if (diffOptions.HasFlag(DiffModifiers.IncludeUntracked))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNTRACKED |
                                 GitDiffOptionFlags.GIT_DIFF_RECURSE_UNTRACKED_DIRS |
                                 GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNTRACKED_CONTENT;
            }

            if (diffOptions.HasFlag(DiffModifiers.IncludeIgnored))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_IGNORED |
                                 GitDiffOptionFlags.GIT_DIFF_RECURSE_IGNORED_DIRS;
            }

            if (diffOptions.HasFlag(DiffModifiers.IncludeUnmodified))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNMODIFIED;
            }

            if (diffOptions.HasFlag(DiffModifiers.DisablePathspecMatch))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_DISABLE_PATHSPEC_MATCH;
            }

            if (matchedPathsAggregator != null)
            {
                options.NotifyCallback = matchedPathsAggregator.OnGitDiffNotify;
            }

            if (filePaths == null)
            {
                return(options);
            }

            options.PathSpec = GitStrArrayIn.BuildFrom(filePaths);
            return(options);
        }
示例#12
0
        private DiffHandle BuildDiffList(
            ObjectId oldTreeId,
            ObjectId newTreeId,
            TreeComparisonHandleRetriever comparisonHandleRetriever,
            DiffModifiers diffOptions,
            IEnumerable <string> paths,
            ExplicitPathsOptions explicitPathsOptions,
            CompareOptions compareOptions)
        {
            var filePaths = repo.ToFilePaths(paths);

            MatchedPathsAggregator matchedPaths = null;

            // We can't match paths unless we've got something to match
            // against and we're told to do so.
            if (filePaths != null && explicitPathsOptions != null)
            {
                if (explicitPathsOptions.OnUnmatchedPath != null || explicitPathsOptions.ShouldFailOnUnmatchedPath)
                {
                    matchedPaths = new MatchedPathsAggregator();
                }
            }

            using (GitDiffOptions options = BuildOptions(diffOptions, filePaths, matchedPaths, compareOptions))
            {
                var diffList = comparisonHandleRetriever(oldTreeId, newTreeId, options);

                if (matchedPaths != null)
                {
                    try
                    {
                        DispatchUnmatchedPaths(explicitPathsOptions, filePaths, matchedPaths);
                    }
                    catch
                    {
                        diffList.Dispose();
                        throw;
                    }
                }

                DetectRenames(diffList, compareOptions);

                return(diffList);
            }
        }
示例#13
0
        private TreeChanges BuildTreeChangesFromComparer(
            ObjectId oldTreeId, ObjectId newTreeId, TreeComparisonHandleRetriever comparisonHandleRetriever,
            DiffOptions diffOptions, IEnumerable <string> paths = null, ExplicitPathsOptions explicitPathsOptions = null, CompareOptions compareOptions = null)
        {
            var matchedPaths = new MatchedPathsAggregator();
            var filePaths    = ToFilePaths(repo, paths);

            using (GitDiffOptions options = BuildOptions(diffOptions, filePaths, matchedPaths, compareOptions))
                using (DiffListSafeHandle diffList = comparisonHandleRetriever(oldTreeId, newTreeId, options))
                {
                    if (explicitPathsOptions != null)
                    {
                        DispatchUnmatchedPaths(explicitPathsOptions, filePaths, matchedPaths);
                    }

                    return(new TreeChanges(diffList));
                }
        }
示例#14
0
        private GitDiffOptions BuildOptions(DiffOptions diffOptions, IEnumerable <string> paths = null)
        {
            var options = new GitDiffOptions();

            options.Flags       |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_TYPECHANGE;
            options.ContextLines = 3;

            if (diffOptions.HasFlag(DiffOptions.IncludeUntracked))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNTRACKED |
                                 GitDiffOptionFlags.GIT_DIFF_RECURSE_UNTRACKED_DIRS |
                                 GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNTRACKED_CONTENT;
            }

            if (paths == null)
            {
                return(options);
            }

            options.PathSpec = GitStrArrayIn.BuildFrom(ToFilePaths(repo, paths));
            return(options);
        }
示例#15
0
 private DiffListSafeHandle BuildDiffListFromTrees(ObjectId oldTree, ObjectId newTree, GitDiffOptions options)
 {
     return(Proxy.git_diff_tree_to_tree(repo.Handle, oldTree, newTree, options));
 }
示例#16
0
 private static DiffListSafeHandle BuildDiffListFromComparer(ObjectId treeId, TreeComparisonHandleRetriever comparisonHandleRetriever, GitDiffOptions options)
 {
     return(comparisonHandleRetriever(treeId, options));
 }
示例#17
0
        private static DiffListSafeHandle BuildDiffListFromComparer(GitObjectSafeHandle handle, TreeComparisonHandleRetriever comparisonHandleRetriever)
        {
            GitDiffOptions options = DefaultOptions;

            return(comparisonHandleRetriever(handle, options));
        }