diff --git a/LibGit2Sharp/CommitLog.cs b/LibGit2Sharp/CommitLog.cs index 4a6ab1de3..e243d0ce1 100644 --- a/LibGit2Sharp/CommitLog.cs +++ b/LibGit2Sharp/CommitLog.cs @@ -96,13 +96,14 @@ public IEnumerable QueryBy(string path) /// /// The file's path. /// The options used to control which commits will be returned. + /// Additional options to define comparison behavior. /// A list of file history entries, ready to be enumerated. - public IEnumerable QueryBy(string path, CommitFilter filter) + public IEnumerable QueryBy(string path, CommitFilter filter, CompareOptions compareOptions = null) { Ensure.ArgumentNotNull(path, "path"); Ensure.ArgumentNotNull(filter, "filter"); - return new FileHistory(repo, path, filter); + return new FileHistory(repo, path, filter, compareOptions); } private class CommitEnumerator : IEnumerator diff --git a/LibGit2Sharp/Core/FileHistory.cs b/LibGit2Sharp/Core/FileHistory.cs index 5c10a1a24..75852a300 100644 --- a/LibGit2Sharp/Core/FileHistory.cs +++ b/LibGit2Sharp/Core/FileHistory.cs @@ -37,6 +37,11 @@ internal class FileHistory : IEnumerable /// private readonly CommitFilter _queryFilter; + /// + /// Options to define comparison behavior. + /// + private readonly CompareOptions _compareOptions; + #endregion #region Constructors @@ -49,7 +54,7 @@ internal class FileHistory : IEnumerable /// The file's path relative to the repository's root. /// If any of the parameters is null. internal FileHistory(Repository repo, string path) - : this(repo, path, new CommitFilter()) + : this(repo, path, new CommitFilter(), new CompareOptions()) { } /// @@ -62,9 +67,10 @@ internal FileHistory(Repository repo, string path) /// The repository. /// The file's path relative to the repository's root. /// The filter to be used in querying the commit log. + /// Additional options to define comparison behavior. /// If any of the parameters is null. /// When an unsupported commit sort strategy is specified. - internal FileHistory(Repository repo, string path, CommitFilter queryFilter) + internal FileHistory(Repository repo, string path, CommitFilter queryFilter, CompareOptions compareOptions) { Ensure.ArgumentNotNull(repo, "repo"); Ensure.ArgumentNotNull(path, "path"); @@ -80,6 +86,7 @@ internal FileHistory(Repository repo, string path, CommitFilter queryFilter) _repo = repo; _path = path; _queryFilter = queryFilter; + _compareOptions = compareOptions; } #endregion @@ -94,7 +101,7 @@ internal FileHistory(Repository repo, string path, CommitFilter queryFilter) /// A . public IEnumerator GetEnumerator() { - return FullHistory(_repo, _path, _queryFilter).GetEnumerator(); + return FullHistory(_repo, _path, _queryFilter, _compareOptions).GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() @@ -110,8 +117,9 @@ IEnumerator IEnumerable.GetEnumerator() /// The repository. /// The file's path relative to the repository's root. /// The filter to be used in querying the commits log. + /// Additional options to define comparison behavior. /// A collection of instances. - private static IEnumerable FullHistory(IRepository repo, string path, CommitFilter filter) + private static IEnumerable FullHistory(IRepository repo, string path, CommitFilter filter, CompareOptions compareOptions) { var map = new Dictionary(); @@ -132,7 +140,7 @@ private static IEnumerable FullHistory(IRepository repo, string path, } else { - DetermineParentPaths(repo, currentCommit, currentPath, map); + DetermineParentPaths(repo, currentCommit, currentPath, map, compareOptions); if (parentCount != 1) { @@ -153,17 +161,17 @@ private static IEnumerable FullHistory(IRepository repo, string path, } } - private static void DetermineParentPaths(IRepository repo, Commit currentCommit, string currentPath, IDictionary map) + private static void DetermineParentPaths(IRepository repo, Commit currentCommit, string currentPath, IDictionary map, CompareOptions compareOptions) { foreach (var parentCommit in currentCommit.Parents.Where(parentCommit => !map.ContainsKey(parentCommit))) { - map.Add(parentCommit, ParentPath(repo, currentCommit, currentPath, parentCommit)); + map.Add(parentCommit, ParentPath(repo, currentCommit, currentPath, parentCommit, compareOptions)); } } - private static string ParentPath(IRepository repo, Commit currentCommit, string currentPath, Commit parentCommit) + private static string ParentPath(IRepository repo, Commit currentCommit, string currentPath, Commit parentCommit, CompareOptions compareOptions) { - using (var treeChanges = repo.Diff.Compare(parentCommit.Tree, currentCommit.Tree)) + using (var treeChanges = repo.Diff.Compare(parentCommit.Tree, currentCommit.Tree, compareOptions)) { var treeEntryChanges = treeChanges.FirstOrDefault(c => c.Path == currentPath); return treeEntryChanges != null && treeEntryChanges.Status == ChangeKind.Renamed diff --git a/LibGit2Sharp/IQueryableCommitLog.cs b/LibGit2Sharp/IQueryableCommitLog.cs index ab8a92136..62dffa2a0 100644 --- a/LibGit2Sharp/IQueryableCommitLog.cs +++ b/LibGit2Sharp/IQueryableCommitLog.cs @@ -27,8 +27,9 @@ public interface IQueryableCommitLog : ICommitLog /// /// The file's path. /// The options used to control which commits will be returned. + /// Additional options to define comparison behavior. /// A list of file history entries, ready to be enumerated. - IEnumerable QueryBy(string path, CommitFilter filter); + IEnumerable QueryBy(string path, CommitFilter filter, CompareOptions compareOptions = null); } }