diff options
author | Brendan Forster <brendan@github.com> | 2015-05-14 13:55:36 +0300 |
---|---|---|
committer | Brendan Forster <brendan@github.com> | 2015-05-14 13:55:36 +0300 |
commit | a63afb6b17757159a057793b3b09492c5dd3fdd1 (patch) | |
tree | 0ff66b4f79a10c331459b32c896a81b9759c30a8 | |
parent | a4edcc149c29849d0e1e3df5c61ecb04eee5e089 (diff) |
introduced IndexUpdateOptionsindex-updated-api
-rw-r--r-- | LibGit2Sharp.Tests/IndexFixture.cs | 21 | ||||
-rw-r--r-- | LibGit2Sharp.sln.DotSettings | 1 | ||||
-rw-r--r-- | LibGit2Sharp/Handlers.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp/Index.cs | 48 | ||||
-rw-r--r-- | LibGit2Sharp/IndexCallbacks.cs | 13 |
5 files changed, 68 insertions, 17 deletions
diff --git a/LibGit2Sharp.Tests/IndexFixture.cs b/LibGit2Sharp.Tests/IndexFixture.cs index a2c1a5e1..58830272 100644 --- a/LibGit2Sharp.Tests/IndexFixture.cs +++ b/LibGit2Sharp.Tests/IndexFixture.cs @@ -520,12 +520,17 @@ namespace LibGit2Sharp.Tests var count = 0; Touch(repo.Info.WorkingDirectory, fileName, "rewrite the file\n"); - IndexUpdaterHandler callback = (file, pathspec) => + + var options = new IndexUpdateOptions { - count++; - return 0; + IndexUpdateHandler = (file, pathspec) => + { + count++; + return 0; + } }; - repo.Index.Update(callback); + + repo.Index.Update(options); Assert.Equal(1, count); } @@ -547,8 +552,12 @@ namespace LibGit2Sharp.Tests var first = repo.Index[fileName].Id; Touch(repo.Info.WorkingDirectory, fileName, "rewrite the file\n"); - IndexUpdaterHandler callback = (file, pathspec) => 1; - repo.Index.Update(callback); + + var options = new IndexUpdateOptions + { + IndexUpdateHandler = (file, pathspec) => 1 + }; + repo.Index.Update(options); var second = repo.Index[fileName].Id; Assert.Equal(first, second); diff --git a/LibGit2Sharp.sln.DotSettings b/LibGit2Sharp.sln.DotSettings index ce4b3194..8fe8fc7b 100644 --- a/LibGit2Sharp.sln.DotSettings +++ b/LibGit2Sharp.sln.DotSettings @@ -10,6 +10,7 @@ <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean> <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHING_EMPTY_BRACES/@EntryValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean> </wpf:ResourceDictionary> diff --git a/LibGit2Sharp/Handlers.cs b/LibGit2Sharp/Handlers.cs index 5aa2db78..6bace4a7 100644 --- a/LibGit2Sharp/Handlers.cs +++ b/LibGit2Sharp/Handlers.cs @@ -120,7 +120,7 @@ namespace LibGit2Sharp.Handlers /// <returns> /// 0 to update the file, a positive number to skip the file, or a negative number to signal an error /// </returns> - public delegate int IndexUpdaterHandler(string path, string pathSpec); + public delegate int IndexUpdateHandler(string path, string pathSpec); /// <summary> /// The stages of pack building. diff --git a/LibGit2Sharp/Index.cs b/LibGit2Sharp/Index.cs index 14248a46..1a7bc036 100644 --- a/LibGit2Sharp/Index.cs +++ b/LibGit2Sharp/Index.cs @@ -240,11 +240,34 @@ namespace LibGit2Sharp /// Update files for a given pathspec /// </summary> /// <param name="pathSpec"> - /// Limit the scope of paths to update to the provided pathspecs + /// Limit the scope of paths to update to the provided pathspec /// </param> public virtual void Update(string pathSpec) { - Proxy.git_index_update_all(Handle, new[] { pathSpec }, null); + Update(new[] { pathSpec }); + } + + /// <summary> + /// Update files for a given pathspec + /// </summary> + /// <param name="options"> + /// Optional parameters to provide</param> + public virtual void Update(IndexUpdateOptions options) + { + Update(new[] { "*" }, options); + } + + /// <summary> + /// Update files for a given pathspec + /// </summary> + /// <param name="pathSpec"> + /// Limit the scope of paths to update to the provided pathspec + /// </param> + /// <param name="options"> + /// Optional parameters to provide</param> + public virtual void Update(string pathSpec, IndexUpdateOptions options) + { + Update(new [] { pathSpec }, options); } /// <summary> @@ -255,21 +278,28 @@ namespace LibGit2Sharp /// </param> public virtual void Update(IEnumerable<string> pathSpecs) { - Proxy.git_index_update_all(Handle, pathSpecs, null); + Update(pathSpecs, null); } /// <summary> - /// Update files based on a given callback + /// Update files for a given set of pathspecs /// </summary> - /// <param name="indexUpdaterHandler"> - /// Callback to process file programatically + /// <param name="pathSpecs"> + /// Limit the scope of paths to update to the provided pathspecs /// </param> - public virtual void Update(IndexUpdaterHandler indexUpdaterHandler) + /// <param name="options"></param> + public virtual void Update(IEnumerable<string> pathSpecs, IndexUpdateOptions options) { - var callback = IndexCallbacks.ToCallback(indexUpdaterHandler); + Ensure.ArgumentNotNullOrEmptyEnumerable(pathSpecs, "pathSpecs"); + + if (options == null) + { + options = new IndexUpdateOptions(); + } - Proxy.git_index_update_all(Handle, new[] { "*" }, callback); + var nativeCallback = IndexCallbacks.ToCallback(options.IndexUpdateHandler); + Proxy.git_index_update_all(Handle, pathSpecs, nativeCallback); } private void UpdatePhysicalIndex() diff --git a/LibGit2Sharp/IndexCallbacks.cs b/LibGit2Sharp/IndexCallbacks.cs index a9efa0ff..b81f1279 100644 --- a/LibGit2Sharp/IndexCallbacks.cs +++ b/LibGit2Sharp/IndexCallbacks.cs @@ -9,7 +9,7 @@ namespace LibGit2Sharp { internal class IndexCallbacks { - public static NativeMethods.git_index_matched_path_cb ToCallback(IndexUpdaterHandler handler) + public static NativeMethods.git_index_matched_path_cb ToCallback(IndexUpdateHandler handler) { NativeMethods.git_index_matched_path_cb cb = (path, pathSpec, intPtr) => { @@ -22,4 +22,15 @@ namespace LibGit2Sharp return cb; } } + + /// <summary> + /// Options for updating foo bar baz + /// </summary> + public class IndexUpdateOptions + { + /// <summary> + /// Callback for matching paths + /// </summary> + public IndexUpdateHandler IndexUpdateHandler { get; set; } + } } |