diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-06-10 17:34:11 +0300 |
---|---|---|
committer | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-08-25 21:31:16 +0300 |
commit | 974237c4f49dd20624467559b6b6efa5b36169be (patch) | |
tree | f887d68dbec37b83e3b5a8a11f9cbc7fac1b34c0 | |
parent | 8a673bb0e52919616606af55f465dbc0729f76c5 (diff) |
Introduce blame options for rename tracking
-rw-r--r-- | LibGit2Sharp/BlameHunkCollection.cs | 10 | ||||
-rw-r--r-- | LibGit2Sharp/BlameOptions.cs | 12 | ||||
-rw-r--r-- | LibGit2Sharp/Core/GitBlame.cs | 1 | ||||
-rw-r--r-- | LibGit2Sharp/Core/GitDiff.cs | 7 | ||||
-rw-r--r-- | LibGit2Sharp/Core/NativeMethods.cs | 7 | ||||
-rw-r--r-- | LibGit2Sharp/Core/Proxy.cs | 8 | ||||
-rw-r--r-- | LibGit2Sharp/Diff.cs | 3 | ||||
-rw-r--r-- | LibGit2Sharp/DiffModifiers.cs | 11 |
8 files changed, 53 insertions, 6 deletions
diff --git a/LibGit2Sharp/BlameHunkCollection.cs b/LibGit2Sharp/BlameHunkCollection.cs index 35b94552..1ee64b40 100644 --- a/LibGit2Sharp/BlameHunkCollection.cs +++ b/LibGit2Sharp/BlameHunkCollection.cs @@ -27,11 +27,21 @@ namespace LibGit2Sharp var rawopts = new GitBlameOptions { version = 1, + FindOptions = new GitDiffFindOptions { + Version = 1, + }, flags = options.Strategy.ToGitBlameOptionFlags(), MinLine = (uint)options.MinLine, MaxLine = (uint)options.MaxLine, }; + if (options.FindNoRenames) + rawopts.FindOptions.Flags = GitDiffFindFlags.GIT_DIFF_FIND_NO_RENAMES; + else if (options.FindExactRenames) + rawopts.FindOptions.Flags = GitDiffFindFlags.GIT_DIFF_FIND_EXACT_MATCH_ONLY; + else + rawopts.FindOptions.Flags = GitDiffFindFlags.GIT_DIFF_FIND_RENAMES; + if (options.StartingAt != null) { rawopts.NewestCommit = repo.Committish(options.StartingAt).Oid; diff --git a/LibGit2Sharp/BlameOptions.cs b/LibGit2Sharp/BlameOptions.cs index c39a3f53..dfd0f41d 100644 --- a/LibGit2Sharp/BlameOptions.cs +++ b/LibGit2Sharp/BlameOptions.cs @@ -6,7 +6,7 @@ public enum BlameStrategy { /// <summary> - /// Track renames of the file, but no block movement. + /// Track renames of the file using diff rename detection, but no block movement. /// </summary> Default, @@ -58,5 +58,15 @@ /// If this is set to 0, blame ends with the last line in the file. /// </summary> public int MaxLine { get; set; } + + /// <summary> + /// Disables rename heuristics, only matching renames on unmodified files. + /// </summary> + public bool FindExactRenames { get; set; } + + /// <summary> + /// Fully disable rename checking. + /// </summary> + public bool FindNoRenames { get; set; } } } diff --git a/LibGit2Sharp/Core/GitBlame.cs b/LibGit2Sharp/Core/GitBlame.cs index 9db27d25..8efc7570 100644 --- a/LibGit2Sharp/Core/GitBlame.cs +++ b/LibGit2Sharp/Core/GitBlame.cs @@ -44,6 +44,7 @@ namespace LibGit2Sharp.Core internal class GitBlameOptions { public uint version = 1; + public GitDiffFindOptions FindOptions; public GitBlameOptionFlags flags; public UInt16 MinMatchCharacters; public GitOid NewestCommit; diff --git a/LibGit2Sharp/Core/GitDiff.cs b/LibGit2Sharp/Core/GitDiff.cs index 4d1e9768..d3db05fc 100644 --- a/LibGit2Sharp/Core/GitDiff.cs +++ b/LibGit2Sharp/Core/GitDiff.cs @@ -333,6 +333,9 @@ namespace LibGit2Sharp.Core // turn on all finding features GIT_DIFF_FIND_ALL = (0x0ff), + // does no work trying to find renames + GIT_DIFF_FIND_NO_RENAMES = (1 << 8), + // measure similarity ignoring leading whitespace (default) GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE = 0, // measure similarity ignoring all whitespace @@ -350,9 +353,9 @@ namespace LibGit2Sharp.Core } [StructLayout(LayoutKind.Sequential)] - internal class GitDiffFindOptions + internal struct GitDiffFindOptions { - public uint Version = 1; + public uint Version; public GitDiffFindFlags Flags; public UInt16 RenameThreshold; public UInt16 RenameFromRewriteThreshold; diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index a1b5b5cf..713c2160 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -558,7 +558,12 @@ namespace LibGit2Sharp.Core [DllImport(libgit2)] internal static extern int git_diff_find_similar( DiffSafeHandle diff, - GitDiffFindOptions options); + IntPtr options); + + [DllImport(libgit2)] + internal static extern int git_diff_find_similar( + DiffSafeHandle diff, + ref GitDiffFindOptions options); [DllImport(libgit2)] internal static extern UIntPtr git_diff_num_deltas(DiffSafeHandle diff); diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index 11b3ca20..7a3fc792 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -798,12 +798,18 @@ namespace LibGit2Sharp.Core } } - public static void git_diff_find_similar(DiffSafeHandle diff, GitDiffFindOptions options) + public static void git_diff_find_similar(DiffSafeHandle diff, IntPtr options) { int res = NativeMethods.git_diff_find_similar(diff, options); Ensure.ZeroResult(res); } + public static void git_diff_find_similar(DiffSafeHandle diff, GitDiffFindOptions options) + { + int res = NativeMethods.git_diff_find_similar(diff, ref options); + Ensure.ZeroResult(res); + } + public static int git_diff_num_deltas(DiffSafeHandle diff) { return (int)NativeMethods.git_diff_num_deltas(diff); diff --git a/LibGit2Sharp/Diff.cs b/LibGit2Sharp/Diff.cs index 1e8d283c..8cc96e26 100644 --- a/LibGit2Sharp/Diff.cs +++ b/LibGit2Sharp/Diff.cs @@ -544,7 +544,7 @@ namespace LibGit2Sharp var similarityOptions = (compareOptions == null) ? null : compareOptions.Similarity; if (similarityOptions == null || similarityOptions.RenameDetectionMode == RenameDetectionMode.Default) { - Proxy.git_diff_find_similar(diffList, null); + Proxy.git_diff_find_similar(diffList, IntPtr.Zero); return; } @@ -555,6 +555,7 @@ namespace LibGit2Sharp var opts = new GitDiffFindOptions { + Version = 1, RenameThreshold = (ushort)similarityOptions.RenameThreshold, RenameFromRewriteThreshold = (ushort)similarityOptions.RenameFromRewriteThreshold, CopyThreshold = (ushort)similarityOptions.CopyThreshold, diff --git a/LibGit2Sharp/DiffModifiers.cs b/LibGit2Sharp/DiffModifiers.cs index af9ccb75..2dd05e43 100644 --- a/LibGit2Sharp/DiffModifiers.cs +++ b/LibGit2Sharp/DiffModifiers.cs @@ -36,5 +36,16 @@ namespace LibGit2Sharp /// diffing against the working directory. /// </summary> IncludeIgnored = (1 << 4), + + /// <summary> + /// Specifies that no rename heuristics will be used when checking for + /// renames, renames being matched only on unmodified renamed files. + /// </summary> + FindExactRenames = (1 << 5), + + /// <summary> + /// Specifies that no renames will be searched for when running blame. + /// </summary> + FindNoRenames = (1 << 6), } } |