Beispiel #1
0
        private static TreeComparisonHandleRetriever WorkdirAndIndexToTree(Repository repo)
        {
            TreeComparisonHandleRetriever comparisonHandleRetriever = (h, o) =>
            {
                DiffListSafeHandle diff = null, diff2 = null;

                try
                {
                    diff  = Proxy.git_diff_tree_to_index(repo.Handle, repo.Index.Handle, h, o);
                    diff2 = Proxy.git_diff_index_to_workdir(repo.Handle, repo.Index.Handle, o);
                    Proxy.git_diff_merge(diff, diff2);
                }
                catch
                {
                    diff.SafeDispose();
                    throw;
                }
                finally
                {
                    diff2.SafeDispose();
                }

                return(diff);
            };

            return(comparisonHandleRetriever);
        }
Beispiel #2
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>
 /// <returns>A <see cref = "TreeChanges"/> containing the changes between the <paramref name = "oldTree"/> and the <paramref name = "newTree"/>.</returns>
 public TreeChanges Compare(Tree oldTree, Tree newTree)
 {
     using (DiffListSafeHandle diff = BuildDiffListFromTrees(oldTree.Id, newTree.Id))
     {
         return(new TreeChanges(diff));
     }
 }
Beispiel #3
0
        internal TreeChanges(DiffListSafeHandle diff, bool skipPatchBuilding = false)
        {
            Proxy.git_diff_foreach(diff, FileCallback, null, DataCallback);

            if (!skipPatchBuilding)
            {
                Proxy.git_diff_print_patch(diff, PrintCallBack);
            }
        }
Beispiel #4
0
        /// <summary>
        ///   Show changes between a <see cref = "Tree"/> and a selectable target.
        /// </summary>
        /// <param name = "oldTree">The <see cref = "Tree"/> to compare from.</param>
        /// <param name = "diffTarget">The target to compare to.</param>
        /// <returns>A <see cref = "TreeChanges"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns>
        public TreeChanges Compare(Tree oldTree, DiffTarget diffTarget)
        {
            var comparer = handleRetrieverDispatcher[diffTarget](repo);

            using (DiffListSafeHandle dl = BuildDiffListFromTreeAndComparer(repo, oldTree.Id, comparer))
            {
                return(new TreeChanges(dl));
            }
        }
Beispiel #5
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));
                }
        }
Beispiel #6
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));
         }
 }
Beispiel #7
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));
                }
        }
Beispiel #8
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));
                }
        }
Beispiel #9
0
 public static extern int git_diff_print_patch(
     DiffListSafeHandle diff,
     IntPtr data,
     git_diff_data_fn printCallback);
Beispiel #10
0
 public static extern int git_diff_foreach(
     DiffListSafeHandle diff,
     IntPtr callbackData,
     git_diff_file_fn fileCallback,
     git_diff_hunk_fn hunkCallback,
     git_diff_data_fn lineCallback);
Beispiel #11
0
 public static extern int git_diff_workdir_to_tree(
     RepositorySafeHandle repo,
     GitDiffOptions options,
     GitObjectSafeHandle oldTree,
     out DiffListSafeHandle diff);
Beispiel #12
0
 public static extern int git_diff_workdir_to_index(
     RepositorySafeHandle repo,
     GitDiffOptions options,
     out DiffListSafeHandle diff);
Beispiel #13
0
 public static extern int git_diff_merge(
     DiffListSafeHandle onto,
     DiffListSafeHandle from);
Beispiel #14
0
 internal TreeChanges(DiffListSafeHandle diff)
 {
     Proxy.git_diff_foreach(diff, FileCallback, null, DataCallback);
     Proxy.git_diff_print_patch(diff, PrintCallBack);
 }
Beispiel #15
0
 internal static extern int git_diff_tree_to_index(
     out DiffListSafeHandle diff,
     RepositorySafeHandle repo,
     GitObjectSafeHandle oldTree,
     IndexSafeHandle index,
     GitDiffOptions options);
Beispiel #16
0
 internal static extern int git_diff_index_to_workdir(
     out DiffListSafeHandle diff,
     RepositorySafeHandle repo,
     IndexSafeHandle index,
     GitDiffOptions options);
Beispiel #17
0
 internal static extern int git_diff_print_patch(
     DiffListSafeHandle diff,
     git_diff_data_cb printCallback,
     IntPtr payload);
Beispiel #18
0
 internal static extern int git_diff_tree_to_workdir(
     out DiffListSafeHandle diff,
     RepositorySafeHandle repo,
     GitObjectSafeHandle oldTree,
     GitDiffOptions options);
Beispiel #19
0
 internal TreeChanges(DiffListSafeHandle diff)
 {
     Proxy.git_diff_print_patch(diff, PrintCallBack);
 }
Beispiel #20
0
 internal TreeChanges(DiffListSafeHandle diff)
 {
     Ensure.Success(NativeMethods.git_diff_print_patch(diff, IntPtr.Zero, PrintCallBack));
 }