Add RawContentStream.#324
Conversation
LibGit2Sharp/Core/Proxy.cs
Outdated
There was a problem hiding this comment.
I'd rather keep the Proxy method and its current signature. This would allow Blob.cs to stay unmodified.
Regarding the Proxy implementation, could you please implement it so a pointer to the NativeMethods.git_blob_rawcontent method is passed to the RawContentStream ctor?
There was a problem hiding this comment.
But I need the ObjectSafeWrapepr and the pointer in the class. How do I retrieve it with the current signature?
|
Keeping the Proxy method and its current signature is impossibru, or it would force me to create the ObjectSafeWrapper two times, which is not a good idea. |
How about this? public static UnmanagedMemoryStream git_blob_rawcontent_stream(RepositorySafeHandle repo, ObjectId id, Int64 size)
{
return new RawContentStream(id, repo, NativeMethods.git_blob_rawcontent, size);
} |
|
Still the problem persists, you want me to create 2 ObjectSafeWrappers if the current signature is to stays. using (var obj = new ObjectSafeWrapper(id, repo))
{
IntPtr ptr = NativeMethods.git_blob_rawcontent(obj.ObjectPtr); |
I'm sorry. I don't follow you. You already create an ObjectSafeWrapper in the RawContentStream``. Why don't you use it? Provided the public static UnmanagedMemoryStream git_blob_rawcontent_stream(RepositorySafeHandle repo, ObjectId id, Int64 size)
{
return new RawContentStream(id, repo, NativeMethods.git_blob_rawcontent, size);
}The RawContentStream could be as follows, with only one using System;
using System.IO;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;
namespace LibGit2Sharp
{
internal class RawContentStream : UnmanagedMemoryStream
{
private readonly ObjectSafeWrapper wrapper;
public RawContentStream(ObjectId id, RepositorySafeHandle repo,
Func<GitObjectSafeHandle, IntPtr> bytePtrProvider, long length) :
this(new ObjectSafeWrapper(id, repo), bytePtrProvider,length)
{
}
unsafe RawContentStream(ObjectSafeWrapper wrapper,
Func<GitObjectSafeHandle, IntPtr> bytePrv, long length)
: base((byte *)(bytePrv(wrapper.ObjectPtr)).ToPointer(), length)
{
this.wrapper = wrapper;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
wrapper.SafeDispose();
}
}
}Or am I missing something? |
|
Ok I understood now |
|
No, still the same, please show me the content of your proposed git_blob_rawcontent_stream. The signature has to be changed to take the ObjectSafeWrapper at least as an argument, otherwise the creation of 2 ObjectSafeWrappers will still exist. |
See the comment above 😉 |
Holds the rawcontent objectsafe wrapper.
|
These indirections confused me. As an additional note, the contract here dictates that the stream can be accessed and disposed only in the using (repo) block, otherwise it might return nasty exceptions and bring the entire application down. |
|
Very neat addition. Thanks! |
Holds the rawcontent objectsafe wrapper.
Some context: eb304fb#commitcomment-2459256