From 9173dda1c4c1f9b4bf565f9be8e045bedc8ebd2f Mon Sep 17 00:00:00 2001 From: Kevin David Date: Fri, 23 Oct 2015 10:10:23 -0400 Subject: [PATCH 1/8] PackBuilderOptions: switch to immutable struct --- LibGit2Sharp.Tests/PackBuilderFixture.cs | 23 +------- LibGit2Sharp/ObjectDatabase.cs | 3 +- LibGit2Sharp/PackBuilder.cs | 68 +++++++++--------------- 3 files changed, 27 insertions(+), 67 deletions(-) diff --git a/LibGit2Sharp.Tests/PackBuilderFixture.cs b/LibGit2Sharp.Tests/PackBuilderFixture.cs index 44e358158..88951496c 100644 --- a/LibGit2Sharp.Tests/PackBuilderFixture.cs +++ b/LibGit2Sharp.Tests/PackBuilderFixture.cs @@ -114,28 +114,12 @@ public void ExceptionIfPathDoesNotExist() [Fact] public void ExceptionIfPathEqualsNull() { - PackBuilderOptions pbo; - Assert.Throws(() => { - pbo = new PackBuilderOptions(null); + new PackBuilderOptions(null); }); } - [Fact] - public void ExceptionIfOptionsEqualsNull() - { - string orgRepoPath = SandboxPackBuilderTestRepo(); - - using (Repository orgRepo = new Repository(orgRepoPath)) - { - Assert.Throws(() => - { - orgRepo.ObjectDatabase.Pack(null); - }); - } - } - [Fact] public void ExceptionIfBuildDelegateEqualsNull() { @@ -154,12 +138,9 @@ public void ExceptionIfBuildDelegateEqualsNull() [Fact] public void ExceptionIfNegativeNumberOfThreads() { - string orgRepoPath = SandboxPackBuilderTestRepo(); - PackBuilderOptions packBuilderOptions = new PackBuilderOptions(orgRepoPath); - Assert.Throws(() => { - packBuilderOptions.MaximumNumberOfThreads = -1; + new PackBuilderOptions(Path.GetTempPath(), -1); }); } diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index 0adb09afd..db260ca18 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -682,7 +682,6 @@ public virtual PackBuilderResults Pack(PackBuilderOptions options, ActionPacking results private PackBuilderResults InternalPack(PackBuilderOptions options, Action packDelegate) { - Ensure.ArgumentNotNull(options, "options"); Ensure.ArgumentNotNull(packDelegate, "packDelegate"); PackBuilderResults results = new PackBuilderResults(); @@ -696,7 +695,7 @@ private PackBuilderResults InternalPack(PackBuilderOptions options, Action /// Packing options of the . /// - public sealed class PackBuilderOptions + public struct PackBuilderOptions { - private string path; - private int nThreads; + /// + /// Directory where the pack and index files will be written. + /// + public readonly string PackDirectory; /// - /// Constructor + /// Maximum number of threads that will be used during pack building. /// - /// Directory path to write the pack and index files to it - /// The default value for maximum number of threads to spawn is 0 which ensures using all available CPUs. - /// if packDirectory is null or empty - /// if packDirectory doesn't exist - public PackBuilderOptions(string packDirectory) - { - PackDirectoryPath = packDirectory; - MaximumNumberOfThreads = 0; - } + public readonly int MaximumNumberOfThreads; /// - /// Directory path to write the pack and index files to it. + /// Options to write a new packfile and index to a directory with the default number of threads. /// - public string PackDirectoryPath + public PackBuilderOptions(string packDirectory) + : this(packDirectory, 0) { - set - { - Ensure.ArgumentNotNullOrEmptyString(value, "packDirectory"); - - if (!Directory.Exists(value)) - { - throw new DirectoryNotFoundException("The Directory " + value + " does not exist."); - } - - path = value; - } - get - { - return path; - } } /// - /// Maximum number of threads to spawn. - /// The default value is 0 which ensures using all available CPUs. + /// Options to write a new packfile and index to a directory. /// - public int MaximumNumberOfThreads + /// Directory path to write the pack and index files to it + /// Maximum number of threads to spawn. The default value is 0 which ensures using all available CPUs. + /// if packDirectory is null or empty + /// if packDirectory doesn't exist + /// If is less than zero. + public PackBuilderOptions(string packDirectory, int maxThreads) { - set + Ensure.ArgumentNotNullOrEmptyString(packDirectory, "packDirectory"); + Ensure.ArgumentPositiveInt32(maxThreads, "maxThreads"); + if (!Directory.Exists(packDirectory)) { - if (value < 0) - { - throw new ArgumentException("Argument can not be negative", "value"); - } - - nThreads = value; - } - get - { - return nThreads; + throw new DirectoryNotFoundException("The Directory " + packDirectory + " does not exist."); } + + PackDirectory = packDirectory; + MaximumNumberOfThreads = maxThreads; } } } From 6f0ab8234bb98751758ba398e656a92e1941a99b Mon Sep 17 00:00:00 2001 From: Kevin David Date: Sat, 24 Oct 2015 10:28:08 -0400 Subject: [PATCH 2/8] PackBuilder: introduce WriteTo Consequently, add new PackBuilderOptions overload which takes an output stream --- LibGit2Sharp.Tests/PackBuilderFixture.cs | 33 +++++++++- LibGit2Sharp/Core/NativeMethods.cs | 7 +++ LibGit2Sharp/Core/Proxy.cs | 7 +++ LibGit2Sharp/ObjectDatabase.cs | 11 +++- LibGit2Sharp/PackBuilder.cs | 76 +++++++++++++++++++++++- 5 files changed, 130 insertions(+), 4 deletions(-) diff --git a/LibGit2Sharp.Tests/PackBuilderFixture.cs b/LibGit2Sharp.Tests/PackBuilderFixture.cs index 88951496c..164e5dbdc 100644 --- a/LibGit2Sharp.Tests/PackBuilderFixture.cs +++ b/LibGit2Sharp.Tests/PackBuilderFixture.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Text; using LibGit2Sharp.Tests.TestHelpers; using Xunit; @@ -116,7 +117,16 @@ public void ExceptionIfPathEqualsNull() { Assert.Throws(() => { - new PackBuilderOptions(null); + new PackBuilderOptions(packDirectory: null); + }); + } + + [Fact] + public void ExceptionIfStreamIsNull() + { + Assert.Throws(() => + { + new PackBuilderOptions(outputPackStream: null); }); } @@ -179,5 +189,26 @@ public void ExceptionIfAddRecursivelyNullObjectID() }); } } + + [Fact] + public void WriteToStreamWritesAllObjects() + { + var testRepoPath = SandboxPackBuilderTestRepo(); + using (var testRepo = new Repository(testRepoPath)) + { + using (var packOutput = new MemoryStream()) + { + PackBuilderResults results = testRepo.ObjectDatabase.Pack( + new PackBuilderOptions(packOutput)); + + const string packHeader = "PACK"; + Assert.Equal( + packHeader, + Encoding.UTF8.GetString(packOutput.GetBuffer(), 0, packHeader.Length)); + + Assert.Equal(testRepo.ObjectDatabase.Count(), results.WrittenObjectsCount); + } + } + } } } diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 0e3d6b3fc..d4a71f5f1 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -937,6 +937,13 @@ internal static extern int git_patch_line_stats( /* Push network progress notification function */ internal delegate int git_push_transfer_progress(uint current, uint total, UIntPtr bytes, IntPtr payload); internal delegate int git_packbuilder_progress(int stage, uint current, uint total, IntPtr payload); + internal delegate int git_packbuilder_foreach_callback(IntPtr buf, UIntPtr size, IntPtr payload); + + [DllImport(libgit2)] + internal static extern int git_packbuilder_foreach( + PackBuilderSafeHandle packbuilder, + git_packbuilder_foreach_callback foreachCallback, + IntPtr payload); [DllImport(libgit2)] internal static extern void git_packbuilder_free(IntPtr packbuilder); diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index dec711d24..fd65cecd1 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -1572,6 +1572,13 @@ public static void git_packbuilder_insert(PackBuilderSafeHandle packbuilder, Obj Ensure.ZeroResult(res); } + public static int git_packbuilder_foreach( + PackBuilderSafeHandle packbuilder, + NativeMethods.git_packbuilder_foreach_callback callback) + { + return NativeMethods.git_packbuilder_foreach(packbuilder, callback, IntPtr.Zero); + } + internal static void git_packbuilder_insert_commit(PackBuilderSafeHandle packbuilder, ObjectId targetId) { GitOid oid = targetId.Oid; diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index db260ca18..f7f9621dc 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -694,8 +694,15 @@ private PackBuilderResults InternalPack(PackBuilderOptions options, Action + /// Write the new pack to the . The index will not be + /// written, so the caller is responsible for indexing objects in the new pack. + /// + /// The output pack stream. + internal void WriteTo(Stream outputStream) + { + Ensure.ArgumentNotNull(outputStream, "outputStream"); + + // 64K is optimal buffer size per https://technet.microsoft.com/en-us/library/cc938632.aspx + const int defaultBufferSize = 64 * 1024; + + Proxy.git_packbuilder_foreach(packBuilderHandle, (IntPtr buf, UIntPtr size, IntPtr payload) => + { + try + { + long objectSize = (long)size; + unsafe + { + using (var input = new UnmanagedMemoryStream((byte*)buf.ToPointer(), objectSize)) + { + input.CopyTo( + outputStream, + objectSize > defaultBufferSize ? defaultBufferSize : (int)objectSize); + } + } + } + catch (Exception ex) + { + Log.Write(LogLevel.Error, "PackBuilder.WriteTo callback exception"); + Log.Write(LogLevel.Error, ex.ToString()); + Proxy.giterr_set_str(GitErrorCategory.Callback, ex); + return (int)GitErrorCode.Error; + } + + return (int)GitErrorCode.Ok; + }); + } + /// /// Sets number of threads to spawn. /// @@ -143,9 +182,16 @@ public struct PackBuilderOptions { /// /// Directory where the pack and index files will be written. + /// null if is specified instead. /// public readonly string PackDirectory; + /// + /// Stream where the pack will be output to. + /// null if is specified instead. + /// + public readonly Stream OutputPackStream; + /// /// Maximum number of threads that will be used during pack building. /// @@ -159,6 +205,14 @@ public PackBuilderOptions(string packDirectory) { } + /// + /// Options to write a new packfile and index to a directory with the default number of threads. + /// + public PackBuilderOptions(Stream outputPackStream) + : this(outputPackStream, 0) + { + } + /// /// Options to write a new packfile and index to a directory. /// @@ -168,15 +222,35 @@ public PackBuilderOptions(string packDirectory) /// if packDirectory doesn't exist /// If is less than zero. public PackBuilderOptions(string packDirectory, int maxThreads) + : this(packDirectory, null, maxThreads) { Ensure.ArgumentNotNullOrEmptyString(packDirectory, "packDirectory"); - Ensure.ArgumentPositiveInt32(maxThreads, "maxThreads"); if (!Directory.Exists(packDirectory)) { throw new DirectoryNotFoundException("The Directory " + packDirectory + " does not exist."); } + } + + /// + /// Options to write a new packfile to an output + /// + /// Output stream to write the new pack to. + /// Maximum number of threads to spawn. The default value is 0 which ensures using all available CPUs. + /// if packDirectory is null or empty + /// if packDirectory doesn't exist + /// If is less than zero. + public PackBuilderOptions(Stream outputPackStream, int maxThreads) + : this(null, outputPackStream, maxThreads) + { + Ensure.ArgumentNotNull(outputPackStream, "outputStream"); + } + + private PackBuilderOptions(string packDirectory, Stream outputPackStream, int maxThreads) + { + Ensure.ArgumentPositiveInt32(maxThreads, "maxThreads"); PackDirectory = packDirectory; + OutputPackStream = outputPackStream; MaximumNumberOfThreads = maxThreads; } } From 7b98e9c9b5665d829a7c8ba9367cea661040f560 Mon Sep 17 00:00:00 2001 From: Kevin David Date: Mon, 26 Oct 2015 09:55:29 -0400 Subject: [PATCH 3/8] squash! PackBuilderOptions: switch to immutable struct Just kidding, use an immutable class instead. --- LibGit2Sharp.Tests/PackBuilderFixture.cs | 14 ++++++++++++++ LibGit2Sharp/ObjectDatabase.cs | 1 + LibGit2Sharp/PackBuilder.cs | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/LibGit2Sharp.Tests/PackBuilderFixture.cs b/LibGit2Sharp.Tests/PackBuilderFixture.cs index 164e5dbdc..6968e6045 100644 --- a/LibGit2Sharp.Tests/PackBuilderFixture.cs +++ b/LibGit2Sharp.Tests/PackBuilderFixture.cs @@ -130,6 +130,20 @@ public void ExceptionIfStreamIsNull() }); } + [Fact] + public void ExceptionIfOptionsEqualsNull() + { + string orgRepoPath = SandboxPackBuilderTestRepo(); + + using (Repository orgRepo = new Repository(orgRepoPath)) + { + Assert.Throws(() => + { + orgRepo.ObjectDatabase.Pack(null); + }); + } + } + [Fact] public void ExceptionIfBuildDelegateEqualsNull() { diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index f7f9621dc..b0490e291 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -682,6 +682,7 @@ public virtual PackBuilderResults Pack(PackBuilderOptions options, ActionPacking results private PackBuilderResults InternalPack(PackBuilderOptions options, Action packDelegate) { + Ensure.ArgumentNotNull(options, "options"); Ensure.ArgumentNotNull(packDelegate, "packDelegate"); PackBuilderResults results = new PackBuilderResults(); diff --git a/LibGit2Sharp/PackBuilder.cs b/LibGit2Sharp/PackBuilder.cs index 9c58f7a0f..004bdc655 100644 --- a/LibGit2Sharp/PackBuilder.cs +++ b/LibGit2Sharp/PackBuilder.cs @@ -178,7 +178,7 @@ public struct PackBuilderResults /// /// Packing options of the . /// - public struct PackBuilderOptions + public sealed class PackBuilderOptions { /// /// Directory where the pack and index files will be written. From 4473c9253c6a63ee012d40bc635431ba207bb4ec Mon Sep 17 00:00:00 2001 From: Kevin David Date: Wed, 4 Nov 2015 17:08:39 -0500 Subject: [PATCH 4/8] squash! squash! PackBuilderOptions: switch to immutable struct --- LibGit2Sharp.Tests/PackBuilderFixture.cs | 94 ++++++++++++++---------- LibGit2Sharp/ObjectDatabase.cs | 59 ++++++++------- LibGit2Sharp/PackBuilder.cs | 86 +++++++--------------- 3 files changed, 113 insertions(+), 126 deletions(-) diff --git a/LibGit2Sharp.Tests/PackBuilderFixture.cs b/LibGit2Sharp.Tests/PackBuilderFixture.cs index 6968e6045..77f4586b4 100644 --- a/LibGit2Sharp.Tests/PackBuilderFixture.cs +++ b/LibGit2Sharp.Tests/PackBuilderFixture.cs @@ -37,20 +37,26 @@ internal void TestIfSameRepoAfterPacking(Action packDe string orgRepoPath = SandboxPackBuilderTestRepo(); string mrrRepoPath = SandboxPackBuilderTestRepo(); - string mrrRepoPackDirPath = Path.Combine(mrrRepoPath + "/.git/objects"); + string mrrRepoPackDirPath = Path.Combine(mrrRepoPath + ".git", "objects"); DirectoryHelper.DeleteDirectory(mrrRepoPackDirPath); - Directory.CreateDirectory(mrrRepoPackDirPath + "/pack"); - - PackBuilderOptions packBuilderOptions = new PackBuilderOptions(mrrRepoPackDirPath + "/pack"); + string packDir = Path.Combine(mrrRepoPackDirPath, "pack"); + Directory.CreateDirectory(packDir); using (Repository orgRepo = new Repository(orgRepoPath)) { + var packBuilderOptions = new PackBuilderOptions(); + PackBuilderResults results; if (packDelegate != null) - results = orgRepo.ObjectDatabase.Pack(packBuilderOptions, b => packDelegate(orgRepo, b)); + { + packBuilderOptions.PackDelegate = b => packDelegate(orgRepo, b); + results = orgRepo.ObjectDatabase.Pack(packDir, packBuilderOptions); + } else - results = orgRepo.ObjectDatabase.Pack(packBuilderOptions); + { + results = orgRepo.ObjectDatabase.Pack(packDir, packBuilderOptions); + } // written objects count is the same as in objects database Assert.Equal(orgRepo.ObjectDatabase.Count(), results.WrittenObjectsCount); @@ -104,30 +110,38 @@ internal void AddingObjectsTestDelegate(IRepository repo, PackBuilder builder) [Fact] public void ExceptionIfPathDoesNotExist() { - PackBuilderOptions pbo; - - Assert.Throws(() => + using (Repository repo = new Repository(SandboxPackBuilderTestRepo())) { - pbo = new PackBuilderOptions("aaa"); - }); + Assert.Throws(() => + { + repo.ObjectDatabase.Pack("aaa", new PackBuilderOptions()); + }); + } } [Fact] public void ExceptionIfPathEqualsNull() { - Assert.Throws(() => + using (Repository repo = new Repository(SandboxPackBuilderTestRepo())) { - new PackBuilderOptions(packDirectory: null); - }); + Assert.Throws(() => + { + repo.ObjectDatabase.Pack(packDirectory: null, options: new PackBuilderOptions()); + }); + } } [Fact] public void ExceptionIfStreamIsNull() { - Assert.Throws(() => + + using (Repository repo = new Repository(SandboxPackBuilderTestRepo())) { - new PackBuilderOptions(outputPackStream: null); - }); + Assert.Throws(() => + { + repo.ObjectDatabase.Pack(outputPackStream: null, options: new PackBuilderOptions()); + }); + } } [Fact] @@ -137,9 +151,12 @@ public void ExceptionIfOptionsEqualsNull() using (Repository orgRepo = new Repository(orgRepoPath)) { + string packDir = Path.Combine(orgRepoPath, "objects", "pack"); + Directory.CreateDirectory(packDir); + Assert.Throws(() => { - orgRepo.ObjectDatabase.Pack(null); + orgRepo.ObjectDatabase.Pack(packDirectory: packDir, options: null); }); } } @@ -147,16 +164,10 @@ public void ExceptionIfOptionsEqualsNull() [Fact] public void ExceptionIfBuildDelegateEqualsNull() { - string orgRepoPath = SandboxPackBuilderTestRepo(); - PackBuilderOptions packBuilderOptions = new PackBuilderOptions(orgRepoPath); - - using (Repository orgRepo = new Repository(orgRepoPath)) + Assert.Throws(() => { - Assert.Throws(() => - { - orgRepo.ObjectDatabase.Pack(packBuilderOptions, null); - }); - } + (new PackBuilderOptions()).PackDelegate = null; + }); } [Fact] @@ -164,7 +175,7 @@ public void ExceptionIfNegativeNumberOfThreads() { Assert.Throws(() => { - new PackBuilderOptions(Path.GetTempPath(), -1); + (new PackBuilderOptions()).MaximumNumberOfThreads = -1; }); } @@ -172,17 +183,19 @@ public void ExceptionIfNegativeNumberOfThreads() public void ExceptionIfAddNullObjectID() { string orgRepoPath = SandboxPackBuilderTestRepo(); - PackBuilderOptions packBuilderOptions = new PackBuilderOptions(orgRepoPath); + var packBuilderOptions = new PackBuilderOptions(); using (Repository orgRepo = new Repository(orgRepoPath)) { - Assert.Throws(() => + packBuilderOptions.PackDelegate = builder => builder.Add(null); + + using (var ms = new MemoryStream()) { - orgRepo.ObjectDatabase.Pack(packBuilderOptions, builder => + Assert.Throws(() => { - builder.Add(null); + orgRepo.ObjectDatabase.Pack(ms, packBuilderOptions); }); - }); + } } } @@ -190,17 +203,19 @@ public void ExceptionIfAddNullObjectID() public void ExceptionIfAddRecursivelyNullObjectID() { string orgRepoPath = SandboxPackBuilderTestRepo(); - PackBuilderOptions packBuilderOptions = new PackBuilderOptions(orgRepoPath); + var packBuilderOptions = new PackBuilderOptions(); using (Repository orgRepo = new Repository(orgRepoPath)) { - Assert.Throws(() => + packBuilderOptions.PackDelegate = builder => builder.AddRecursively(null); + + using (var ms = new MemoryStream()) { - orgRepo.ObjectDatabase.Pack(packBuilderOptions, builder => + Assert.Throws(() => { - builder.AddRecursively(null); + orgRepo.ObjectDatabase.Pack(ms, packBuilderOptions); }); - }); + } } } @@ -212,8 +227,7 @@ public void WriteToStreamWritesAllObjects() { using (var packOutput = new MemoryStream()) { - PackBuilderResults results = testRepo.ObjectDatabase.Pack( - new PackBuilderOptions(packOutput)); + PackBuilderResults results = testRepo.ObjectDatabase.Pack(packOutput, new PackBuilderOptions()); const string packHeader = "PACK"; Assert.Equal( diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index b0490e291..4353beb22 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -645,45 +645,53 @@ public virtual MergeTreeResult MergeCommits(Commit ours, Commit theirs, MergeTre } /// - /// Packs all the objects in the and write a pack (.pack) and index (.idx) files for them. + /// Packs objects in the and write the resulting pack to + /// the . Note that no index is outputted. /// + /// Stream where the pack will be written to. /// Packing options - /// This method will invoke the default action of packing all objects in an arbitrary order. /// Packing results - public virtual PackBuilderResults Pack(PackBuilderOptions options) + public virtual PackBuilderResults Pack(Stream outputPackStream, PackBuilderOptions options) { - return InternalPack(options, builder => + Ensure.ArgumentNotNull(outputPackStream, "outputPackStream"); + if (!outputPackStream.CanWrite) { - foreach (GitObject obj in repo.ObjectDatabase) - { - builder.Add(obj.Id); - } - }); + throw new ArgumentException("The outputPackStream must be writeable."); + } + + return InternalPack(options, builder => builder.WriteTo(outputPackStream)); + } /// - /// Packs objects in the chosen by the packDelegate action - /// and write a pack (.pack) and index (.idx) files for them + /// Packs objects in the , and write a pack (.pack) and index (.idx) + /// files for them to the /// + /// Output directory for pack and idx files. /// Packing options - /// Packing action /// Packing results - public virtual PackBuilderResults Pack(PackBuilderOptions options, Action packDelegate) + public virtual PackBuilderResults Pack(string packDirectory, PackBuilderOptions options) { - return InternalPack(options, packDelegate); + Ensure.ArgumentNotNullOrEmptyString(packDirectory, "packDirectory"); + if (!Directory.Exists(packDirectory)) + { + throw new DirectoryNotFoundException("The Directory " + packDirectory + " does not exist."); + } + + return InternalPack(options, builder => builder.Write(packDirectory)); } /// - /// Packs objects in the and write a pack (.pack) and index (.idx) files for them. + /// Packs objects in the and use the + /// to write the results. /// For internal use only. /// /// Packing options - /// Packing action + /// Writing action action /// Packing results - private PackBuilderResults InternalPack(PackBuilderOptions options, Action packDelegate) + private PackBuilderResults InternalPack(PackBuilderOptions options, Action writeAction) { Ensure.ArgumentNotNull(options, "options"); - Ensure.ArgumentNotNull(packDelegate, "packDelegate"); PackBuilderResults results = new PackBuilderResults(); @@ -692,19 +700,20 @@ private PackBuilderResults InternalPack(PackBuilderOptions options, Action public sealed class PackBuilderOptions { - /// - /// Directory where the pack and index files will be written. - /// null if is specified instead. - /// - public readonly string PackDirectory; - - /// - /// Stream where the pack will be output to. - /// null if is specified instead. - /// - public readonly Stream OutputPackStream; - - /// - /// Maximum number of threads that will be used during pack building. - /// - public readonly int MaximumNumberOfThreads; - - /// - /// Options to write a new packfile and index to a directory with the default number of threads. - /// - public PackBuilderOptions(string packDirectory) - : this(packDirectory, 0) - { - } - - /// - /// Options to write a new packfile and index to a directory with the default number of threads. - /// - public PackBuilderOptions(Stream outputPackStream) - : this(outputPackStream, 0) - { - } + private int nThreads; + private Action packDelegate; /// - /// Options to write a new packfile and index to a directory. + /// Maximum number of threads to spawn. + /// The default value is 0 which ensures using all available CPUs. /// - /// Directory path to write the pack and index files to it - /// Maximum number of threads to spawn. The default value is 0 which ensures using all available CPUs. - /// if packDirectory is null or empty - /// if packDirectory doesn't exist - /// If is less than zero. - public PackBuilderOptions(string packDirectory, int maxThreads) - : this(packDirectory, null, maxThreads) + public int MaximumNumberOfThreads { - Ensure.ArgumentNotNullOrEmptyString(packDirectory, "packDirectory"); - if (!Directory.Exists(packDirectory)) + set { - throw new DirectoryNotFoundException("The Directory " + packDirectory + " does not exist."); + Ensure.ArgumentPositiveInt32(value, "value"); + nThreads = value; + } + get + { + return nThreads; } } /// - /// Options to write a new packfile to an output + /// Packing action to perform instead of the default, which is to + /// pack all objects in the repository into a single packfile and index, + /// enumerating them in an arbitrary order. /// - /// Output stream to write the new pack to. - /// Maximum number of threads to spawn. The default value is 0 which ensures using all available CPUs. - /// if packDirectory is null or empty - /// if packDirectory doesn't exist - /// If is less than zero. - public PackBuilderOptions(Stream outputPackStream, int maxThreads) - : this(null, outputPackStream, maxThreads) - { - Ensure.ArgumentNotNull(outputPackStream, "outputStream"); - } - - private PackBuilderOptions(string packDirectory, Stream outputPackStream, int maxThreads) + public Action PackDelegate { - Ensure.ArgumentPositiveInt32(maxThreads, "maxThreads"); - - PackDirectory = packDirectory; - OutputPackStream = outputPackStream; - MaximumNumberOfThreads = maxThreads; + set + { + Ensure.ArgumentNotNull(value, "value"); + packDelegate = value; + } + get + { + return packDelegate; + } } } } From 568c5621f78276a9c50258bb7bd5b20c23ea1a66 Mon Sep 17 00:00:00 2001 From: Kevin David Date: Thu, 5 Nov 2015 08:37:52 -0500 Subject: [PATCH 5/8] squash! squash! squash! PackBuilderOptions: switch to immutable struct --- LibGit2Sharp.Tests/PackBuilderFixture.cs | 20 ++++---------------- LibGit2Sharp/ObjectDatabase.cs | 2 +- LibGit2Sharp/PackBuilder.cs | 14 +------------- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/LibGit2Sharp.Tests/PackBuilderFixture.cs b/LibGit2Sharp.Tests/PackBuilderFixture.cs index 77f4586b4..893fc1fe7 100644 --- a/LibGit2Sharp.Tests/PackBuilderFixture.cs +++ b/LibGit2Sharp.Tests/PackBuilderFixture.cs @@ -51,13 +51,10 @@ internal void TestIfSameRepoAfterPacking(Action packDe if (packDelegate != null) { packBuilderOptions.PackDelegate = b => packDelegate(orgRepo, b); - results = orgRepo.ObjectDatabase.Pack(packDir, packBuilderOptions); - } - else - { - results = orgRepo.ObjectDatabase.Pack(packDir, packBuilderOptions); } + results = orgRepo.ObjectDatabase.Pack(packDir, packBuilderOptions); + // written objects count is the same as in objects database Assert.Equal(orgRepo.ObjectDatabase.Count(), results.WrittenObjectsCount); @@ -126,7 +123,7 @@ public void ExceptionIfPathEqualsNull() { Assert.Throws(() => { - repo.ObjectDatabase.Pack(packDirectory: null, options: new PackBuilderOptions()); + repo.ObjectDatabase.Pack(default(string), new PackBuilderOptions()); }); } } @@ -139,7 +136,7 @@ public void ExceptionIfStreamIsNull() { Assert.Throws(() => { - repo.ObjectDatabase.Pack(outputPackStream: null, options: new PackBuilderOptions()); + repo.ObjectDatabase.Pack(default(Stream), new PackBuilderOptions()); }); } } @@ -161,15 +158,6 @@ public void ExceptionIfOptionsEqualsNull() } } - [Fact] - public void ExceptionIfBuildDelegateEqualsNull() - { - Assert.Throws(() => - { - (new PackBuilderOptions()).PackDelegate = null; - }); - } - [Fact] public void ExceptionIfNegativeNumberOfThreads() { diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index 4353beb22..a63fac65b 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -691,7 +691,7 @@ public virtual PackBuilderResults Pack(string packDirectory, PackBuilderOptions /// Packing results private PackBuilderResults InternalPack(PackBuilderOptions options, Action writeAction) { - Ensure.ArgumentNotNull(options, "options"); + options = options ?? new PackBuilderOptions(); PackBuilderResults results = new PackBuilderResults(); diff --git a/LibGit2Sharp/PackBuilder.cs b/LibGit2Sharp/PackBuilder.cs index 661c88e5f..dac73cb82 100644 --- a/LibGit2Sharp/PackBuilder.cs +++ b/LibGit2Sharp/PackBuilder.cs @@ -181,7 +181,6 @@ public struct PackBuilderResults public sealed class PackBuilderOptions { private int nThreads; - private Action packDelegate; /// /// Maximum number of threads to spawn. @@ -205,17 +204,6 @@ public int MaximumNumberOfThreads /// pack all objects in the repository into a single packfile and index, /// enumerating them in an arbitrary order. /// - public Action PackDelegate - { - set - { - Ensure.ArgumentNotNull(value, "value"); - packDelegate = value; - } - get - { - return packDelegate; - } - } + public Action PackDelegate { get; set; } } } From 3a613f23ae54ebd69d269afa3232c37fcfc6568d Mon Sep 17 00:00:00 2001 From: Kevin David Date: Thu, 5 Nov 2015 10:17:50 -0500 Subject: [PATCH 6/8] squash! squash! squash! squash! PackBuilderOptions: switch to immutable struct --- LibGit2Sharp.Tests/PackBuilderFixture.cs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/LibGit2Sharp.Tests/PackBuilderFixture.cs b/LibGit2Sharp.Tests/PackBuilderFixture.cs index 893fc1fe7..1e9888b23 100644 --- a/LibGit2Sharp.Tests/PackBuilderFixture.cs +++ b/LibGit2Sharp.Tests/PackBuilderFixture.cs @@ -141,23 +141,6 @@ public void ExceptionIfStreamIsNull() } } - [Fact] - public void ExceptionIfOptionsEqualsNull() - { - string orgRepoPath = SandboxPackBuilderTestRepo(); - - using (Repository orgRepo = new Repository(orgRepoPath)) - { - string packDir = Path.Combine(orgRepoPath, "objects", "pack"); - Directory.CreateDirectory(packDir); - - Assert.Throws(() => - { - orgRepo.ObjectDatabase.Pack(packDirectory: packDir, options: null); - }); - } - } - [Fact] public void ExceptionIfNegativeNumberOfThreads() { From bed5916d3dd2fc8cbe3c14fe698cf1f63aa828e5 Mon Sep 17 00:00:00 2001 From: Kevin David Date: Thu, 5 Nov 2015 08:44:51 -0500 Subject: [PATCH 7/8] Rename PackBuilder -> PackDefinition Also remove `Builder` from results and options. --- LibGit2Sharp.Tests/PackBuilderFixture.cs | 31 ++++++++++++------------ LibGit2Sharp/ObjectDatabase.cs | 16 ++++++------ LibGit2Sharp/PackBuilder.cs | 12 ++++----- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/LibGit2Sharp.Tests/PackBuilderFixture.cs b/LibGit2Sharp.Tests/PackBuilderFixture.cs index 1e9888b23..4d6a32293 100644 --- a/LibGit2Sharp.Tests/PackBuilderFixture.cs +++ b/LibGit2Sharp.Tests/PackBuilderFixture.cs @@ -27,7 +27,7 @@ public void TestCommitsPerBranchIdsPackDelegate() TestIfSameRepoAfterPacking(AddingObjectsTestDelegate); } - internal void TestIfSameRepoAfterPacking(Action packDelegate) + internal void TestIfSameRepoAfterPacking(Action packDelegate) { // read a repo // pack with the provided action @@ -45,12 +45,12 @@ internal void TestIfSameRepoAfterPacking(Action packDe using (Repository orgRepo = new Repository(orgRepoPath)) { - var packBuilderOptions = new PackBuilderOptions(); + var packBuilderOptions = new PackOptions(); - PackBuilderResults results; + PackResults results; if (packDelegate != null) { - packBuilderOptions.PackDelegate = b => packDelegate(orgRepo, b); + packBuilderOptions.PackBuilder = b => packDelegate(orgRepo, b); } results = orgRepo.ObjectDatabase.Pack(packDir, packBuilderOptions); @@ -72,7 +72,7 @@ internal void TestIfSameRepoAfterPacking(Action packDe } } - internal void AddingObjectIdsTestDelegate(IRepository repo, PackBuilder builder) + internal void AddingObjectIdsTestDelegate(IRepository repo, PackDefinition builder) { foreach (Branch branch in repo.Branches) { @@ -88,7 +88,7 @@ internal void AddingObjectIdsTestDelegate(IRepository repo, PackBuilder builder) } } - internal void AddingObjectsTestDelegate(IRepository repo, PackBuilder builder) + internal void AddingObjectsTestDelegate(IRepository repo, PackDefinition builder) { foreach (Branch branch in repo.Branches) { @@ -111,7 +111,7 @@ public void ExceptionIfPathDoesNotExist() { Assert.Throws(() => { - repo.ObjectDatabase.Pack("aaa", new PackBuilderOptions()); + repo.ObjectDatabase.Pack("aaa", new PackOptions()); }); } } @@ -123,7 +123,7 @@ public void ExceptionIfPathEqualsNull() { Assert.Throws(() => { - repo.ObjectDatabase.Pack(default(string), new PackBuilderOptions()); + repo.ObjectDatabase.Pack(default(string), new PackOptions()); }); } } @@ -131,12 +131,11 @@ public void ExceptionIfPathEqualsNull() [Fact] public void ExceptionIfStreamIsNull() { - using (Repository repo = new Repository(SandboxPackBuilderTestRepo())) { Assert.Throws(() => { - repo.ObjectDatabase.Pack(default(Stream), new PackBuilderOptions()); + repo.ObjectDatabase.Pack(default(Stream), new PackOptions()); }); } } @@ -146,7 +145,7 @@ public void ExceptionIfNegativeNumberOfThreads() { Assert.Throws(() => { - (new PackBuilderOptions()).MaximumNumberOfThreads = -1; + (new PackOptions()).MaximumNumberOfThreads = -1; }); } @@ -154,11 +153,11 @@ public void ExceptionIfNegativeNumberOfThreads() public void ExceptionIfAddNullObjectID() { string orgRepoPath = SandboxPackBuilderTestRepo(); - var packBuilderOptions = new PackBuilderOptions(); + var packBuilderOptions = new PackOptions(); using (Repository orgRepo = new Repository(orgRepoPath)) { - packBuilderOptions.PackDelegate = builder => builder.Add(null); + packBuilderOptions.PackBuilder = builder => builder.Add(null); using (var ms = new MemoryStream()) { @@ -174,11 +173,11 @@ public void ExceptionIfAddNullObjectID() public void ExceptionIfAddRecursivelyNullObjectID() { string orgRepoPath = SandboxPackBuilderTestRepo(); - var packBuilderOptions = new PackBuilderOptions(); + var packBuilderOptions = new PackOptions(); using (Repository orgRepo = new Repository(orgRepoPath)) { - packBuilderOptions.PackDelegate = builder => builder.AddRecursively(null); + packBuilderOptions.PackBuilder = builder => builder.AddRecursively(null); using (var ms = new MemoryStream()) { @@ -198,7 +197,7 @@ public void WriteToStreamWritesAllObjects() { using (var packOutput = new MemoryStream()) { - PackBuilderResults results = testRepo.ObjectDatabase.Pack(packOutput, new PackBuilderOptions()); + PackResults results = testRepo.ObjectDatabase.Pack(packOutput, new PackOptions()); const string packHeader = "PACK"; Assert.Equal( diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index a63fac65b..537297406 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -651,7 +651,7 @@ public virtual MergeTreeResult MergeCommits(Commit ours, Commit theirs, MergeTre /// Stream where the pack will be written to. /// Packing options /// Packing results - public virtual PackBuilderResults Pack(Stream outputPackStream, PackBuilderOptions options) + public virtual PackResults Pack(Stream outputPackStream, PackOptions options) { Ensure.ArgumentNotNull(outputPackStream, "outputPackStream"); if (!outputPackStream.CanWrite) @@ -670,7 +670,7 @@ public virtual PackBuilderResults Pack(Stream outputPackStream, PackBuilderOptio /// Output directory for pack and idx files. /// Packing options /// Packing results - public virtual PackBuilderResults Pack(string packDirectory, PackBuilderOptions options) + public virtual PackResults Pack(string packDirectory, PackOptions options) { Ensure.ArgumentNotNullOrEmptyString(packDirectory, "packDirectory"); if (!Directory.Exists(packDirectory)) @@ -689,18 +689,18 @@ public virtual PackBuilderResults Pack(string packDirectory, PackBuilderOptions /// Packing options /// Writing action action /// Packing results - private PackBuilderResults InternalPack(PackBuilderOptions options, Action writeAction) + private PackResults InternalPack(PackOptions options, Action writeAction) { - options = options ?? new PackBuilderOptions(); + options = options ?? new PackOptions(); - PackBuilderResults results = new PackBuilderResults(); + PackResults results = new PackResults(); - using (PackBuilder builder = new PackBuilder(repo)) + using (PackDefinition builder = new PackDefinition(repo)) { // set pre-build options builder.SetMaximumNumberOfThreads(options.MaximumNumberOfThreads); - if (options.PackDelegate == null) + if (options.PackBuilder == null) { foreach (GitObject obj in repo.ObjectDatabase) { @@ -709,7 +709,7 @@ private PackBuilderResults InternalPack(PackBuilderOptions options, Action - /// Representation of a git PackBuilder. + /// Provides access to repository packing capabilities. /// - public sealed class PackBuilder : IDisposable + public sealed class PackDefinition : IDisposable { private readonly PackBuilderSafeHandle packBuilderHandle; /// /// Constructs a PackBuilder for a . /// - internal PackBuilder(Repository repository) + internal PackDefinition(Repository repository) { Ensure.ArgumentNotNull(repository, "repository"); @@ -167,7 +167,7 @@ internal PackBuilderSafeHandle Handle /// /// The results of pack process of the . /// - public struct PackBuilderResults + public struct PackResults { /// /// Number of objects the PackBuilder has already written out. @@ -178,7 +178,7 @@ public struct PackBuilderResults /// /// Packing options of the . /// - public sealed class PackBuilderOptions + public sealed class PackOptions { private int nThreads; @@ -204,6 +204,6 @@ public int MaximumNumberOfThreads /// pack all objects in the repository into a single packfile and index, /// enumerating them in an arbitrary order. /// - public Action PackDelegate { get; set; } + public Action PackBuilder { get; set; } } } From 5f1995fe6c96380698b01e9c949b5e96d9fa44db Mon Sep 17 00:00:00 2001 From: Kevin David Date: Thu, 5 Nov 2015 10:35:54 -0500 Subject: [PATCH 8/8] squash! Rename PackBuilder -> PackDefinition Finish eradication of `PackBuilder` other than its use when providing an Action to be performed during packing. --- LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 2 +- ...derFixture.cs => PackDefinitionFixture.cs} | 48 +++++++++---------- LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | 8 ++-- LibGit2Sharp/LibGit2Sharp.csproj | 2 +- .../{PackBuilder.cs => PackDefinition.cs} | 24 ++++------ 5 files changed, 39 insertions(+), 45 deletions(-) rename LibGit2Sharp.Tests/{PackBuilderFixture.cs => PackDefinitionFixture.cs} (77%) rename LibGit2Sharp/{PackBuilder.cs => PackDefinition.cs} (90%) diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index 0be3440c6..4ae6101dc 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -64,7 +64,7 @@ - + diff --git a/LibGit2Sharp.Tests/PackBuilderFixture.cs b/LibGit2Sharp.Tests/PackDefinitionFixture.cs similarity index 77% rename from LibGit2Sharp.Tests/PackBuilderFixture.cs rename to LibGit2Sharp.Tests/PackDefinitionFixture.cs index 4d6a32293..db9ecc265 100644 --- a/LibGit2Sharp.Tests/PackBuilderFixture.cs +++ b/LibGit2Sharp.Tests/PackDefinitionFixture.cs @@ -7,7 +7,7 @@ namespace LibGit2Sharp.Tests { - public class PackBuilderFixture : BaseFixture + public class PackDefinitionFixture : BaseFixture { [Fact] public void TestDefaultPackDelegate() @@ -18,16 +18,16 @@ public void TestDefaultPackDelegate() [Fact] public void TestCommitsPerBranchPackDelegate() { - TestIfSameRepoAfterPacking(AddingObjectIdsTestDelegate); + TestIfSameRepoAfterPacking(AddingObjectIdsPackBuilder); } [Fact] public void TestCommitsPerBranchIdsPackDelegate() { - TestIfSameRepoAfterPacking(AddingObjectsTestDelegate); + TestIfSameRepoAfterPacking(AddingObjectsPackBuilder); } - internal void TestIfSameRepoAfterPacking(Action packDelegate) + internal void TestIfSameRepoAfterPacking(Action packBuilder) { // read a repo // pack with the provided action @@ -35,8 +35,8 @@ internal void TestIfSameRepoAfterPacking(Action pac // read new repo // compare - string orgRepoPath = SandboxPackBuilderTestRepo(); - string mrrRepoPath = SandboxPackBuilderTestRepo(); + string orgRepoPath = SandboxPackDefinitionTestRepo(); + string mrrRepoPath = SandboxPackDefinitionTestRepo(); string mrrRepoPackDirPath = Path.Combine(mrrRepoPath + ".git", "objects"); DirectoryHelper.DeleteDirectory(mrrRepoPackDirPath); @@ -45,15 +45,15 @@ internal void TestIfSameRepoAfterPacking(Action pac using (Repository orgRepo = new Repository(orgRepoPath)) { - var packBuilderOptions = new PackOptions(); + var packOptions = new PackOptions(); PackResults results; - if (packDelegate != null) + if (packBuilder != null) { - packBuilderOptions.PackBuilder = b => packDelegate(orgRepo, b); + packOptions.PackBuilder = b => packBuilder(orgRepo, b); } - results = orgRepo.ObjectDatabase.Pack(packDir, packBuilderOptions); + results = orgRepo.ObjectDatabase.Pack(packDir, packOptions); // written objects count is the same as in objects database Assert.Equal(orgRepo.ObjectDatabase.Count(), results.WrittenObjectsCount); @@ -72,7 +72,7 @@ internal void TestIfSameRepoAfterPacking(Action pac } } - internal void AddingObjectIdsTestDelegate(IRepository repo, PackDefinition builder) + internal void AddingObjectIdsPackBuilder(IRepository repo, PackDefinition builder) { foreach (Branch branch in repo.Branches) { @@ -88,7 +88,7 @@ internal void AddingObjectIdsTestDelegate(IRepository repo, PackDefinition build } } - internal void AddingObjectsTestDelegate(IRepository repo, PackDefinition builder) + internal void AddingObjectsPackBuilder(IRepository repo, PackDefinition builder) { foreach (Branch branch in repo.Branches) { @@ -107,7 +107,7 @@ internal void AddingObjectsTestDelegate(IRepository repo, PackDefinition builder [Fact] public void ExceptionIfPathDoesNotExist() { - using (Repository repo = new Repository(SandboxPackBuilderTestRepo())) + using (Repository repo = new Repository(SandboxPackDefinitionTestRepo())) { Assert.Throws(() => { @@ -119,7 +119,7 @@ public void ExceptionIfPathDoesNotExist() [Fact] public void ExceptionIfPathEqualsNull() { - using (Repository repo = new Repository(SandboxPackBuilderTestRepo())) + using (Repository repo = new Repository(SandboxPackDefinitionTestRepo())) { Assert.Throws(() => { @@ -131,7 +131,7 @@ public void ExceptionIfPathEqualsNull() [Fact] public void ExceptionIfStreamIsNull() { - using (Repository repo = new Repository(SandboxPackBuilderTestRepo())) + using (Repository repo = new Repository(SandboxPackDefinitionTestRepo())) { Assert.Throws(() => { @@ -152,18 +152,18 @@ public void ExceptionIfNegativeNumberOfThreads() [Fact] public void ExceptionIfAddNullObjectID() { - string orgRepoPath = SandboxPackBuilderTestRepo(); - var packBuilderOptions = new PackOptions(); + string orgRepoPath = SandboxPackDefinitionTestRepo(); + var packOptions = new PackOptions(); using (Repository orgRepo = new Repository(orgRepoPath)) { - packBuilderOptions.PackBuilder = builder => builder.Add(null); + packOptions.PackBuilder = builder => builder.Add(null); using (var ms = new MemoryStream()) { Assert.Throws(() => { - orgRepo.ObjectDatabase.Pack(ms, packBuilderOptions); + orgRepo.ObjectDatabase.Pack(ms, packOptions); }); } } @@ -172,18 +172,18 @@ public void ExceptionIfAddNullObjectID() [Fact] public void ExceptionIfAddRecursivelyNullObjectID() { - string orgRepoPath = SandboxPackBuilderTestRepo(); - var packBuilderOptions = new PackOptions(); + string orgRepoPath = SandboxPackDefinitionTestRepo(); + var packOptions = new PackOptions(); using (Repository orgRepo = new Repository(orgRepoPath)) { - packBuilderOptions.PackBuilder = builder => builder.AddRecursively(null); + packOptions.PackBuilder = builder => builder.AddRecursively(null); using (var ms = new MemoryStream()) { Assert.Throws(() => { - orgRepo.ObjectDatabase.Pack(ms, packBuilderOptions); + orgRepo.ObjectDatabase.Pack(ms, packOptions); }); } } @@ -192,7 +192,7 @@ public void ExceptionIfAddRecursivelyNullObjectID() [Fact] public void WriteToStreamWritesAllObjects() { - var testRepoPath = SandboxPackBuilderTestRepo(); + var testRepoPath = SandboxPackDefinitionTestRepo(); using (var testRepo = new Repository(testRepoPath)) { using (var packOutput = new MemoryStream()) diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs index c1fbefb7f..84c93bec9 100644 --- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs +++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs @@ -41,7 +41,7 @@ static BaseFixture() private static string SubmoduleTargetTestRepoWorkingDirPath { get; set; } private static string AssumeUnchangedRepoWorkingDirPath { get; set; } public static string SubmoduleSmallTestRepoWorkingDirPath { get; set; } - public static string PackBuilderTestRepoPath { get; private set; } + public static string PackDefinitionTestRepoPath { get; private set; } public static DirectoryInfo ResourcesDirectory { get; private set; } @@ -75,7 +75,7 @@ private static void SetUpTestEnvironment() SubmoduleTargetTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_target_wd"); AssumeUnchangedRepoWorkingDirPath = Path.Combine(sourceRelativePath, "assume_unchanged_wd"); SubmoduleSmallTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_small_wd"); - PackBuilderTestRepoPath = Path.Combine(sourceRelativePath, "packbuilder_testrepo_wd"); + PackDefinitionTestRepoPath = Path.Combine(sourceRelativePath, "packbuilder_testrepo_wd"); CleanupTestReposOlderThan(TimeSpan.FromMinutes(15)); } @@ -176,9 +176,9 @@ public string SandboxSubmoduleSmallTestRepo() return path; } - protected string SandboxPackBuilderTestRepo() + protected string SandboxPackDefinitionTestRepo() { - return Sandbox(PackBuilderTestRepoPath); + return Sandbox(PackDefinitionTestRepoPath); } protected string Sandbox(string sourceDirectoryPath, params string[] additionalSourcePaths) diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index c2fc74e2e..d8ef12665 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -130,7 +130,7 @@ - + diff --git a/LibGit2Sharp/PackBuilder.cs b/LibGit2Sharp/PackDefinition.cs similarity index 90% rename from LibGit2Sharp/PackBuilder.cs rename to LibGit2Sharp/PackDefinition.cs index 719a53b8d..715ad7738 100644 --- a/LibGit2Sharp/PackBuilder.cs +++ b/LibGit2Sharp/PackDefinition.cs @@ -6,14 +6,14 @@ namespace LibGit2Sharp { /// - /// Provides access to repository packing capabilities. + /// Provides access to packing capabilities. /// public sealed class PackDefinition : IDisposable { private readonly PackBuilderSafeHandle packBuilderHandle; /// - /// Constructs a PackBuilder for a . + /// Constructs a for the . /// internal PackDefinition(Repository repository) { @@ -23,7 +23,7 @@ internal PackDefinition(Repository repository) } /// - /// Inserts a single to the PackBuilder. + /// Inserts a single into this . /// For an optimal pack it's mandatory to insert objects in recency order, commits followed by trees and blobs. (quoted from libgit2 API ref) /// /// The object to be inserted. @@ -49,7 +49,7 @@ public void AddRecursively(T gitObject) where T : GitObject } /// - /// Inserts a single object to the PackBuilder by its . + /// Inserts a single object to the by its . /// For an optimal pack it's mandatory to insert objects in recency order, commits followed by trees and blobs. (quoted from libgit2 API ref) /// /// The object ID to be inserted. @@ -75,7 +75,7 @@ public void AddRecursively(ObjectId id) } /// - /// Disposes the PackBuilder object. + /// Releases handles owned by this object. /// void IDisposable.Dispose() { @@ -131,7 +131,7 @@ internal void WriteTo(Stream outputStream) } /// - /// Sets number of threads to spawn. + /// Sets number of threads to spawn during packing. /// /// Returns the number of actual threads to be used. /// The Number of threads to spawn. An argument of 0 ensures using all available CPUs @@ -142,7 +142,7 @@ internal int SetMaximumNumberOfThreads(int nThread) } /// - /// Number of objects the PackBuilder will write out. + /// Number of objects that will be written out during packing. /// internal long ObjectsCount { @@ -150,18 +150,12 @@ internal long ObjectsCount } /// - /// Number of objects the PackBuilder has already written out. - /// This is only correct after the pack file has been written. + /// Total number of objects that have been written out after packing. /// internal long WrittenObjectsCount { get { return Proxy.git_packbuilder_written(packBuilderHandle); } } - - internal PackBuilderSafeHandle Handle - { - get { return packBuilderHandle; } - } } /// @@ -170,7 +164,7 @@ internal PackBuilderSafeHandle Handle public struct PackResults { /// - /// Number of objects the PackBuilder has already written out. + /// Total number of objects that have been written out after packing. /// public long WrittenObjectsCount { get; internal set; } }