-
Notifications
You must be signed in to change notification settings - Fork 903
Custom filter Streams #946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ammeep
merged 27 commits into
register-custom-filters
from
dahlbyk/register-custom-filters
Feb 13, 2015
Merged
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2c0b022
Implement GitBufReadStream and GitBufWriteStream
dahlbyk 09dc86e
Use Streams for Filter
dahlbyk 4a0ddd1
fixup! Use Streams for Filter
dahlbyk 703a8f7
Drop useless import
nulltoken 08f2ff4
Drop unused native method
nulltoken d2da645
Add missing trailing newlines
nulltoken e0177f5
Drop trailing whitechars
nulltoken 849a417
Update libgit2 to a2012c4
nulltoken fbfc5d1
leverage git_buf_put()
nulltoken 3e8bb70
Ensure filter streams expose properties that makes sense
nulltoken 7336dab
fixup! leverage git_buf_put()
nulltoken 91c1a79
cleanup
nulltoken 1a3e4c9
Don't crash the test runner
nulltoken a803a1f
Revert "Drop unused native method"
nulltoken 5e02299
push down into proxy
nulltoken 3b84e2d
IntPtr all the things!
nulltoken 616ab06
fixup! Don't crash the test runner
nulltoken 1238c81
fixup! Ensure filter streams expose properties that makes sense
nulltoken 1adcff1
Reduce the number of reallocations
nulltoken 89d9908
Fixes following @ammeep's review
nulltoken 8eb623b
Drop unused var
nulltoken bf51ca9
Alternative proposal
nulltoken 2b2c0f8
Drop leftover code
nulltoken 10df3b1
Kill useless allocation
nulltoken 21a6381
Merge pull request #948 from libgit2/ntk/filters_stream_rebound
fat16 2b0b714
Merge branch 'register-custom-filters' into dahlbyk/register-custom-f…
ammeep e070901
:fire: not used
ammeep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using LibGit2Sharp.Core.Handles; | ||
|
||
namespace LibGit2Sharp.Core | ||
{ | ||
/// <summary> | ||
/// Reads data from a <see cref="GitBuf"/> pointer | ||
/// </summary> | ||
internal class GitBufReadStream : UnmanagedMemoryStream | ||
{ | ||
private readonly GitBuf gitBuf; | ||
|
||
internal GitBufReadStream(IntPtr gitBufPointer) | ||
: this(gitBufPointer.MarshalAs<GitBuf>()) | ||
{ } | ||
|
||
private unsafe GitBufReadStream(GitBuf gitBuf) | ||
: base((byte*)gitBuf.ptr, | ||
ConvertToLong(gitBuf.size), | ||
ConvertToLong(gitBuf.asize), | ||
FileAccess.Read) | ||
{ | ||
this.gitBuf = gitBuf; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
|
||
if (disposing && gitBuf != default(GitBuf)) | ||
gitBuf.Dispose(); | ||
} | ||
|
||
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(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using LibGit2Sharp.Core.Handles; | ||
|
||
namespace LibGit2Sharp.Core | ||
{ | ||
/// <summary> | ||
/// Writes data to a <see cref="GitBuf"/> pointer | ||
/// </summary> | ||
internal class GitBufWriteStream : MemoryStream | ||
{ | ||
private readonly IntPtr gitBufPointer; | ||
|
||
internal GitBufWriteStream(IntPtr gitBufPointer) | ||
{ | ||
this.gitBufPointer = gitBufPointer; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
using (var gitBuf = gitBufPointer.MarshalAs<GitBuf>()) | ||
WriteTo(gitBuf); | ||
|
||
base.Dispose(disposing); | ||
} | ||
|
||
private void WriteTo(GitBuf gitBuf) | ||
{ | ||
if (!base.CanSeek) | ||
{ | ||
// Already closed; already written | ||
return; | ||
} | ||
|
||
Seek(0, SeekOrigin.Begin); | ||
|
||
var length = (int)Length; | ||
var bytes = new byte[length]; | ||
Read(bytes, 0, length); | ||
|
||
IntPtr reverseBytesPointer = Marshal.AllocHGlobal(length); | ||
Marshal.Copy(bytes, 0, reverseBytesPointer, bytes.Length); | ||
|
||
var size = (UIntPtr)length; | ||
var allocatedSize = (UIntPtr)length; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In @ammeep's original implementation this was |
||
NativeMethods.git_buf_set(gitBuf, reverseBytesPointer, size); | ||
gitBuf.size = size; | ||
gitBuf.asize = allocatedSize; | ||
|
||
Marshal.StructureToPtr(gitBuf, gitBufPointer, true); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need to 🔥 this.
You can't dispose of the underlying git_buf. Libgit2 allocates two of these for the entire filter chain and swaps the input and output as it moves between filters in the registry. It also free's the buffers after the filter registry has been executed. This is why the tests are failing on this branch 😄