diff --git a/Lib/NativeBinaries/amd64/git2-a2012c4.dll b/Lib/NativeBinaries/amd64/git2-a2012c4.dll new file mode 100644 index 000000000..495a3d663 Binary files /dev/null and b/Lib/NativeBinaries/amd64/git2-a2012c4.dll differ diff --git a/Lib/NativeBinaries/amd64/git2-e0902fb.pdb b/Lib/NativeBinaries/amd64/git2-a2012c4.pdb similarity index 53% rename from Lib/NativeBinaries/amd64/git2-e0902fb.pdb rename to Lib/NativeBinaries/amd64/git2-a2012c4.pdb index bdef63b09..7aa644b1a 100644 Binary files a/Lib/NativeBinaries/amd64/git2-e0902fb.pdb and b/Lib/NativeBinaries/amd64/git2-a2012c4.pdb differ diff --git a/Lib/NativeBinaries/amd64/git2-e0902fb.dll b/Lib/NativeBinaries/amd64/git2-e0902fb.dll deleted file mode 100644 index f4931dbdd..000000000 Binary files a/Lib/NativeBinaries/amd64/git2-e0902fb.dll and /dev/null differ diff --git a/Lib/NativeBinaries/x86/git2-a2012c4.dll b/Lib/NativeBinaries/x86/git2-a2012c4.dll new file mode 100644 index 000000000..59dcdeb8e Binary files /dev/null and b/Lib/NativeBinaries/x86/git2-a2012c4.dll differ diff --git a/Lib/NativeBinaries/x86/git2-e0902fb.pdb b/Lib/NativeBinaries/x86/git2-a2012c4.pdb similarity index 53% rename from Lib/NativeBinaries/x86/git2-e0902fb.pdb rename to Lib/NativeBinaries/x86/git2-a2012c4.pdb index d466f239a..0a873ee0a 100644 Binary files a/Lib/NativeBinaries/x86/git2-e0902fb.pdb and b/Lib/NativeBinaries/x86/git2-a2012c4.pdb differ diff --git a/Lib/NativeBinaries/x86/git2-e0902fb.dll b/Lib/NativeBinaries/x86/git2-e0902fb.dll deleted file mode 100644 index b0c55e6cf..000000000 Binary files a/Lib/NativeBinaries/x86/git2-e0902fb.dll and /dev/null differ diff --git a/LibGit2Sharp.Tests/FilterFixture.cs b/LibGit2Sharp.Tests/FilterFixture.cs index 2db1e2ed0..451bbf73f 100644 --- a/LibGit2Sharp.Tests/FilterFixture.cs +++ b/LibGit2Sharp.Tests/FilterFixture.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using LibGit2Sharp.Core; using LibGit2Sharp.Tests.TestHelpers; using Xunit; @@ -13,7 +12,7 @@ public class FilterFixture : BaseFixture private const int GitPassThrough = -30; readonly Func, int> checkPassThrough = (source, attr) => GitPassThrough; - readonly Func successCallback = (reader, writer) => 0; + readonly Func successCallback = (reader, writer) => 0; readonly Func, int> checkSuccess = (source, attr) => 0; private const string FilterName = "the-filter"; @@ -106,7 +105,7 @@ public void ApplyCallbackMadeWhenCheckCallbackReturnsZero() { bool called = false; - Func applyCallback = (reader, writer) => + Func applyCallback = (reader, writer) => { called = true; return 0; //successCallback @@ -131,7 +130,7 @@ public void ApplyCallbackNotMadeWhenCheckCallbackReturnsPassThrough() { bool called = false; - Func applyCallback = (reader, writer) => + Func applyCallback = (reader, writer) => { called = true; return 0; @@ -271,7 +270,7 @@ public void WhenStagingFileApplyIsCalledWithCleanForCorrectPath() string repoPath = InitNewRepository(); bool called = false; - Func clean = (reader, writer) => + Func clean = (reader, writer) => { called = true; return GitPassThrough; @@ -297,7 +296,7 @@ public void CleanFilterWritesOutputToObjectTree() string repoPath = InitNewRepository(); - Func cleanCallback = SubstitutionCipherFilter.RotateByThirteenPlaces; + Func cleanCallback = SubstitutionCipherFilter.RotateByThirteenPlaces; var filter = new FakeFilter(FilterName + 16, attributes, checkSuccess, cleanCallback); @@ -327,7 +326,7 @@ public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory() const string branchName = "branch"; string repoPath = InitNewRepository(); - Func smudgeCallback = SubstitutionCipherFilter.RotateByThirteenPlaces; + Func smudgeCallback = SubstitutionCipherFilter.RotateByThirteenPlaces; var filter = new FakeFilter(FilterName + 17, attributes, checkSuccess, null, smudgeCallback); GlobalSettings.RegisterFilter(filter); @@ -341,6 +340,54 @@ public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory() GlobalSettings.DeregisterFilter(filter.Name); } + [Fact] + public void FilterStreamsAreCoherent() + { + string repoPath = InitNewRepository(); + + bool? inputCanWrite = null, inputCanRead = null, inputCanSeek = null; + bool? outputCanWrite = null, outputCanRead = null, outputCanSeek = null; + + Func assertor = (input, output) => + { + inputCanRead = input.CanRead; + inputCanWrite = input.CanWrite; + inputCanSeek = input.CanSeek; + + outputCanRead = output.CanRead; + outputCanWrite = output.CanWrite; + outputCanSeek = output.CanSeek; + + return GitPassThrough; + }; + + var filter = new FakeFilter(FilterName + 18, attributes, checkSuccess, assertor, assertor); + + GlobalSettings.RegisterFilter(filter); + + using (var repo = CreateTestRepository(repoPath)) + { + StageNewFile(repo); + } + + GlobalSettings.DeregisterFilter(filter.Name); + + Assert.True(inputCanRead.HasValue); + Assert.True(inputCanWrite.HasValue); + Assert.True(inputCanSeek.HasValue); + Assert.True(outputCanRead.HasValue); + Assert.True(outputCanWrite.HasValue); + Assert.True(outputCanSeek.HasValue); + + Assert.True(inputCanRead.Value); + Assert.False(inputCanWrite.Value); + Assert.False(inputCanSeek.Value); + + Assert.False(outputCanRead.Value); + Assert.True(outputCanWrite.Value); + Assert.False(outputCanSeek.Value); + } + private FileInfo CheckoutFileForSmudge(string repoPath, string branchName, string content) { FileInfo expectedPath; @@ -394,14 +441,14 @@ public EmptyFilter(string name, IEnumerable attributes) class FakeFilter : Filter { private readonly Func, int> checkCallBack; - private readonly Func cleanCallback; - private readonly Func smudgeCallback; + private readonly Func cleanCallback; + private readonly Func smudgeCallback; private readonly Func initCallback; public FakeFilter(string name, IEnumerable attributes, Func, int> checkCallBack = null, - Func cleanCallback = null, - Func smudgeCallback = null, + Func cleanCallback = null, + Func smudgeCallback = null, Func initCallback = null) : base(name, attributes) { @@ -416,12 +463,12 @@ protected override int Check(IEnumerable attributes, FilterSource filter return checkCallBack != null ? checkCallBack(filterSource, attributes) : base.Check(attributes, filterSource); } - protected override int Clean(string path, GitBufReader input, GitBufWriter output) + protected override int Clean(string path, Stream input, Stream output) { return cleanCallback != null ? cleanCallback(input, output) : base.Clean(path, input, output); } - protected override int Smudge(string path, GitBufReader input, GitBufWriter output) + protected override int Smudge(string path, Stream input, Stream output) { return smudgeCallback != null ? smudgeCallback(input, output) : base.Smudge(path, input, output); } diff --git a/LibGit2Sharp.Tests/SubstitutionCipherFilterFixture.cs b/LibGit2Sharp.Tests/SubstitutionCipherFilterFixture.cs index 01cb95f62..65fb32a53 100644 --- a/LibGit2Sharp.Tests/SubstitutionCipherFilterFixture.cs +++ b/LibGit2Sharp.Tests/SubstitutionCipherFilterFixture.cs @@ -96,4 +96,4 @@ private static Blob CommitOnBranchAndReturnDatabaseBlob(Repository repo, string return blob; } } -} \ No newline at end of file +} diff --git a/LibGit2Sharp.Tests/TestHelpers/SubstitutionCipherFilter.cs b/LibGit2Sharp.Tests/TestHelpers/SubstitutionCipherFilter.cs index 8dac4524b..25a90be4c 100644 --- a/LibGit2Sharp.Tests/TestHelpers/SubstitutionCipherFilter.cs +++ b/LibGit2Sharp.Tests/TestHelpers/SubstitutionCipherFilter.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; +using System.IO; using System.Text; -using LibGit2Sharp.Core; namespace LibGit2Sharp.Tests.TestHelpers { @@ -21,34 +21,41 @@ protected override int Check(IEnumerable attributes, FilterSource filter return base.Check(attributes, filterSource); } - protected override int Clean(string path, GitBufReader input, GitBufWriter output) + protected override int Clean(string path, Stream input, Stream output) { CleanCalledCount++; return RotateByThirteenPlaces(input, output); } - protected override int Smudge(string path, GitBufReader input, GitBufWriter output) + protected override int Smudge(string path, Stream input, Stream output) { SmudgeCalledCount++; return RotateByThirteenPlaces(input, output); } - public static int RotateByThirteenPlaces(GitBufReader input, GitBufWriter output) + public static int RotateByThirteenPlaces(Stream input, Stream output) { - var inputString = Encoding.UTF8.GetString(input.ReadAll()); - char[] array = inputString.ToCharArray(); - char value; - for (int i = 0; i < inputString.Length; i++) + + using (var streamReader = new StreamReader(input, Encoding.UTF8)) { - value = inputString[i]; - if ((value >= 'a' && value <= 'm') || (value >= 'A' && value <= 'M')) - array[i] = (char)(value + 13); - else if ((value >= 'n' && value <= 'z') || (value >= 'N' && value <= 'Z')) - array[i] = (char)(value - 13); + var inputString = streamReader.ReadToEnd(); + char[] array = inputString.ToCharArray(); + for (int i = 0; i < inputString.Length; i++) + { + var value = inputString[i]; + if ((value >= 'a' && value <= 'm') || (value >= 'A' && value <= 'M')) + array[i] = (char)(value + 13); + else if ((value >= 'n' && value <= 'z') || (value >= 'N' && value <= 'Z')) + array[i] = (char)(value - 13); + } + + using (var streamWriter = new StreamWriter(output, Encoding.UTF8)) + { + streamWriter.Write(array); + } + + return 0; } - var outputString = new string(array); - output.Write(Encoding.UTF8.GetBytes(outputString)); - return 0; } } -} \ No newline at end of file +} diff --git a/LibGit2Sharp/Core/GitBufReadStream.cs b/LibGit2Sharp/Core/GitBufReadStream.cs new file mode 100644 index 000000000..a8b36d16b --- /dev/null +++ b/LibGit2Sharp/Core/GitBufReadStream.cs @@ -0,0 +1,48 @@ +using System; +using System.Globalization; +using System.IO; +using LibGit2Sharp.Core.Handles; + +namespace LibGit2Sharp.Core +{ + /// + /// Reads data from a pointer + /// + internal class GitBufReadStream : UnmanagedMemoryStream + { + internal GitBufReadStream(IntPtr gitBufPointer) + : this(gitBufPointer.MarshalAs()) + { } + + private unsafe GitBufReadStream(GitBuf gitBuf) + : base((byte*)gitBuf.ptr, + ConvertToLong(gitBuf.size), + ConvertToLong(gitBuf.asize), + FileAccess.Read) + { } + + private static long ConvertToLong(UIntPtr len) + { + if (len.ToUInt64() > long.MaxValue) + { + throw new InvalidOperationException( + string.Format( + CultureInfo.InvariantCulture, + "Provided length ({0}) exceeds long.MaxValue ({1}).", + len.ToUInt64(), long.MaxValue)); + } + + return (long)len.ToUInt64(); + } + + public override long Seek(long offset, SeekOrigin loc) + { + throw new NotSupportedException(); + } + + public override bool CanSeek + { + get { return false; } + } + } +} diff --git a/LibGit2Sharp/Core/GitBufWriteStream.cs b/LibGit2Sharp/Core/GitBufWriteStream.cs new file mode 100644 index 000000000..daf031d8b --- /dev/null +++ b/LibGit2Sharp/Core/GitBufWriteStream.cs @@ -0,0 +1,91 @@ +using System; +using System.IO; +using LibGit2Sharp.Core.Handles; + +namespace LibGit2Sharp.Core +{ + internal class GitBufWriteStream : Stream + { + private readonly IntPtr gitBufPointer; + + internal GitBufWriteStream(IntPtr gitBufPointer) + { + this.gitBufPointer = gitBufPointer; + + //Preallocate the buffer + Proxy.git_buf_grow(gitBufPointer, 1024); + } + + public override void Flush() + { + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotSupportedException(); + } + + public override void SetLength(long value) + { + throw new NotSupportedException(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + throw new NotSupportedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + AutoGrowBuffer(count); + + Proxy.git_buf_put(gitBufPointer, buffer, offset, count); + } + + private void AutoGrowBuffer(int count) + { + var gitBuf = gitBufPointer.MarshalAs(); + + var asize = (uint)gitBuf.asize; + var size = (uint)gitBuf.size; + + var isBufferLargeEnoughToHoldTheNewData = (asize - size) > count; + var filledBufferPercentage = (100.0 * size / asize); + + if (isBufferLargeEnoughToHoldTheNewData && filledBufferPercentage < 90) + { + return; + } + + var targetSize = (uint)(1.5 * (asize + count)); + + Proxy.git_buf_grow(gitBufPointer, targetSize); + } + + public override bool CanRead + { + get { return false; } + } + + public override bool CanSeek + { + get { return false; } + } + + public override bool CanWrite + { + get { return true; } + } + + public override long Length + { + get { throw new NotSupportedException(); } + } + + public override long Position + { + get { throw new NotSupportedException(); } + set { throw new NotSupportedException(); } + } + } +} diff --git a/LibGit2Sharp/Core/NativeDllName.cs b/LibGit2Sharp/Core/NativeDllName.cs index 5127c4e4d..efc4c7e10 100644 --- a/LibGit2Sharp/Core/NativeDllName.cs +++ b/LibGit2Sharp/Core/NativeDllName.cs @@ -2,6 +2,6 @@ namespace LibGit2Sharp.Core { internal static class NativeDllName { - public const string Name = "git2-e0902fb"; + public const string Name = "git2-a2012c4"; } } diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 289e5e5d8..6fb1cd513 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -219,10 +219,10 @@ internal static extern int git_branch_remote_name( [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string canonical_branch_name); [DllImport(libgit2)] - internal static extern int git_buf_grow(GitBuf buffer, UIntPtr targetSize); + internal static extern int git_buf_grow(IntPtr buffer, UIntPtr targetSize); [DllImport(libgit2)] - internal static extern int git_buf_set(GitBuf buffer, IntPtr data, UIntPtr targetSize); + internal static extern int git_buf_put(IntPtr buffer, IntPtr data, UIntPtr len); [DllImport(libgit2)] internal static extern int git_remote_rename( diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index b0184628c..629df4a67 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -241,6 +241,33 @@ public static string git_branch_upstream_name(RepositorySafeHandle handle, strin #region git_buf_ + public static void git_buf_grow(IntPtr gitBufPointer, uint target_size) + { + using (ThreadAffinity()) + { + var res = NativeMethods.git_buf_grow(gitBufPointer, (UIntPtr)target_size); + Ensure.ZeroResult(res); + } + } + + public static void git_buf_put(IntPtr gitBufPointer, byte[] data, int offset, int count) + { + using (ThreadAffinity()) + { + unsafe + { + int res; + + fixed (byte* ptr = data) + { + res = NativeMethods.git_buf_put(gitBufPointer, (IntPtr)ptr, (UIntPtr)count); + } + + Ensure.ZeroResult(res); + } + } + } + public static void git_buf_free(GitBuf buf) { NativeMethods.git_buf_free(buf); diff --git a/LibGit2Sharp/Filter.cs b/LibGit2Sharp/Filter.cs index c13dca406..51cdf5c2e 100644 --- a/LibGit2Sharp/Filter.cs +++ b/LibGit2Sharp/Filter.cs @@ -24,17 +24,17 @@ public abstract class Filter : IEquatable /// /// Initializes a new instance of the class. - /// And allocates the filter natively. + /// And allocates the filter natively. /// The unique name with which this filtered is registered with /// A list of filterForAttributes which this filter applies to /// protected Filter(string name, IEnumerable attributes) - : this(name, string.Join(",", attributes)) + : this(name, string.Join(",", attributes)) { } /// /// Initializes a new instance of the class. - /// And allocates the filter natively. + /// And allocates the filter natively. /// The unique name with which this filtered is registered with /// Either a single attribute, or a comma separated list of filterForAttributes for which this filter applies to /// @@ -88,10 +88,10 @@ internal GitFilter ManagedFilter /// /// Initialize callback on filter - /// + /// /// Specified as `filter.initialize`, this is an optional callback invoked /// before a filter is first used. It will be called once at most. - /// + /// /// If non-NULL, the filter's `initialize` callback will be invoked right /// before the first use of the filter, so you can defer expensive /// initialization operations (in case the library is being used in a way @@ -123,7 +123,7 @@ protected virtual int Check(IEnumerable filterForAttributes, FilterSourc /// The git buf input reader /// The git buf output writer /// 0 if successful and -30 to skip and pass through - protected virtual int Clean(string path, GitBufReader input, GitBufWriter output) + protected virtual int Clean(string path, Stream input, Stream output) { return (int)GitErrorCode.PassThrough; } @@ -135,7 +135,7 @@ protected virtual int Clean(string path, GitBufReader input, GitBufWriter output /// The git buf input reader /// The git buf output writer /// 0 if successful and -30 to skip and pass through - protected virtual int Smudge(string path, GitBufReader input, GitBufWriter output) + protected virtual int Smudge(string path, Stream input, Stream output) { return (int)GitErrorCode.PassThrough; } @@ -193,10 +193,10 @@ public override int GetHashCode() /// /// Initialize callback on filter - /// + /// /// Specified as `filter.initialize`, this is an optional callback invoked /// before a filter is first used. It will be called once at most. - /// + /// /// If non-NULL, the filter's `initialize` callback will be invoked right /// before the first use of the filter, so you can defer expensive /// initialization operations (in case libgit2 is being used in a way that doesn't need the filter). @@ -209,15 +209,15 @@ int InitializeCallback(IntPtr gitFilter) /// /// Callback to decide if a given source needs this filter /// Specified as `filter.check`, this is an optional callback that checks if filtering is needed for a given source. - /// - /// It should return 0 if the filter should be applied (i.e. success), GIT_PASSTHROUGH if the filter should + /// + /// It should return 0 if the filter should be applied (i.e. success), GIT_PASSTHROUGH if the filter should /// not be applied, or an error code to fail out of the filter processing pipeline and return to the caller. - /// + /// /// The `attr_values` will be set to the values of any filterForAttributes given in the filter definition. See `git_filter` below for more detail. - /// - /// The `payload` will be a pointer to a reference payload for the filter. This will start as NULL, but `check` can assign to this + /// + /// The `payload` will be a pointer to a reference payload for the filter. This will start as NULL, but `check` can assign to this /// pointer for later use by the `apply` callback. Note that the value should be heap allocated (not stack), so that it doesn't go - /// away before the `apply` callback can use it. If a filter allocates and assigns a value to the `payload`, it will need a `cleanup` + /// away before the `apply` callback can use it. If a filter allocates and assigns a value to the `payload`, it will need a `cleanup` /// callback to free the payload. /// /// @@ -231,24 +231,25 @@ int CheckCallback(GitFilter gitFilter, IntPtr payload, IntPtr filterSourcePtr, I /// /// Callback to actually perform the data filtering - /// - /// Specified as `filter.apply`, this is the callback that actually filters data. + /// + /// Specified as `filter.apply`, this is the callback that actually filters data. /// If it successfully writes the output, it should return 0. Like `check`, - /// it can return GIT_PASSTHROUGH to indicate that the filter doesn't want to run. + /// it can return GIT_PASSTHROUGH to indicate that the filter doesn't want to run. /// Other error codes will stop filter processing and return to the caller. - /// + /// /// The `payload` value will refer to any payload that was set by the `check` callback. It may be read from or written to as needed. /// - int ApplyCallback(GitFilter gitFilter, IntPtr payload, + int ApplyCallback(GitFilter gitFilter, IntPtr payload, IntPtr gitBufferToPtr, IntPtr gitBufferFromPtr, IntPtr filterSourcePtr) { var filterSource = FilterSource.FromNativePtr(filterSourcePtr); - var reader = new GitBufReader(gitBufferFromPtr); - var writer = new GitBufWriter(gitBufferToPtr); - - return filterSource.SourceMode == FilterMode.Clean ? - Clean(filterSource.Path,reader, writer) : - Smudge(filterSource.Path, reader, writer); + using (var reader = new GitBufReadStream(gitBufferFromPtr)) + using (var writer = new GitBufWriteStream(gitBufferToPtr)) + { + return filterSource.SourceMode == FilterMode.Clean ? + Clean(filterSource.Path, reader, writer) : + Smudge(filterSource.Path, reader, writer); + } } } -} \ No newline at end of file +} diff --git a/LibGit2Sharp/GitBufReader.cs b/LibGit2Sharp/GitBufReader.cs deleted file mode 100644 index 0982a6f6b..000000000 --- a/LibGit2Sharp/GitBufReader.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Globalization; -using System.IO; -using LibGit2Sharp.Core; -using LibGit2Sharp.Core.Handles; - -namespace LibGit2Sharp -{ - /// - /// Reads data from a pointer - /// - public class GitBufReader - { - private readonly IntPtr gitBufPointer; - - internal GitBufReader(IntPtr gitBufPointer) - { - this.gitBufPointer = gitBufPointer; - var gitBuf = gitBufPointer.MarshalAs(); - Size = ConvertToLong(gitBuf.size); - Allocated = ConvertToLong(gitBuf.asize); - } - - /// - /// The size of the underlying stream - /// - public long Size { get; private set; } - - /// - /// The allocated size of the underlying stream - /// - public long Allocated { get; private set; } - - /// - /// Reads all bytes from the - /// - /// - public byte[] ReadAll() - { - using (var unmanagedStream = WrapGifBufPointer(gitBufPointer)) - { - var outMessage = new byte[Size]; - unmanagedStream.Read(outMessage, 0, (int)Size); - return outMessage; - } - } - - internal static long ConvertToLong(UIntPtr len) - { - if (len.ToUInt64() > long.MaxValue) - { - throw new InvalidOperationException( - string.Format( - CultureInfo.InvariantCulture, - "Provided length ({0}) exceeds long.MaxValue ({1}).", - len.ToUInt64(), long.MaxValue)); - } - - return (long)len.ToUInt64(); - } - - private unsafe static Stream WrapGifBufPointer(IntPtr gitBufPointer) - { - var gitBuf = gitBufPointer.MarshalAs(); - byte* memBytePtr = (byte*)gitBuf.ptr; - long size = ConvertToLong(gitBuf.size); - long length = ConvertToLong(gitBuf.asize); - - return new UnmanagedMemoryStream(memBytePtr, size, length, FileAccess.Read); - } - } -} diff --git a/LibGit2Sharp/GitBufWriter.cs b/LibGit2Sharp/GitBufWriter.cs deleted file mode 100644 index ee31daa7a..000000000 --- a/LibGit2Sharp/GitBufWriter.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using LibGit2Sharp.Core; -using LibGit2Sharp.Core.Handles; - -namespace LibGit2Sharp -{ - /// - /// Writes data to a pointer - /// - public class GitBufWriter - { - private readonly IntPtr gitBufPointer; - private readonly GitBuf gitBuf; - - internal GitBufWriter(IntPtr gitBufPointer) - { - this.gitBufPointer = gitBufPointer; - this.gitBuf = gitBufPointer.MarshalAs(); - } - - /// - /// Write bytes to the pointer - /// - /// The bytes to write - public void Write(byte[] bytes) - { - IntPtr reverseBytesPointer = Marshal.AllocHGlobal(bytes.Length); - Marshal.Copy(bytes, 0, reverseBytesPointer, bytes.Length); - - var size = (UIntPtr)bytes.LongLength; - var allocatedSize = (UIntPtr)bytes.LongLength + 1; - NativeMethods.git_buf_set(gitBuf, reverseBytesPointer, size); - gitBuf.size = size; - gitBuf.asize = allocatedSize; - - Marshal.StructureToPtr(gitBuf, gitBufPointer, true); - } - } -} \ No newline at end of file diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 1f6b502e4..7aca3a454 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -68,6 +68,8 @@ + + @@ -82,8 +84,6 @@ - - diff --git a/LibGit2Sharp/libgit2_hash.txt b/LibGit2Sharp/libgit2_hash.txt index 4a8fde8aa..f35b5ca25 100644 --- a/LibGit2Sharp/libgit2_hash.txt +++ b/LibGit2Sharp/libgit2_hash.txt @@ -1 +1 @@ -e0902fbce7d14631bd02091c1c70cde3e68f78ab +a2012c43899e6616366b47d7741b3f035e825e84 diff --git a/libgit2 b/libgit2 index e0902fbce..a2012c438 160000 --- a/libgit2 +++ b/libgit2 @@ -1 +1 @@ -Subproject commit e0902fbce7d14631bd02091c1c70cde3e68f78ab +Subproject commit a2012c43899e6616366b47d7741b3f035e825e84 diff --git a/nuget.package/build/LibGit2Sharp.props b/nuget.package/build/LibGit2Sharp.props index 8ffc28d6e..85e0a5907 100644 --- a/nuget.package/build/LibGit2Sharp.props +++ b/nuget.package/build/LibGit2Sharp.props @@ -1,20 +1,20 @@  - - NativeBinaries\amd64\git2-e0902fb.dll + + NativeBinaries\amd64\git2-a2012c4.dll PreserveNewest - - NativeBinaries\amd64\git2-e0902fb.pdb + + NativeBinaries\amd64\git2-a2012c4.pdb PreserveNewest - - NativeBinaries\x86\git2-e0902fb.dll + + NativeBinaries\x86\git2-a2012c4.dll PreserveNewest - - NativeBinaries\x86\git2-e0902fb.pdb + + NativeBinaries\x86\git2-a2012c4.pdb PreserveNewest