-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce blob FilteringOptions for content stream
Get the content of a blob as it would be checked out to the working directory via the filters.
- Loading branch information
Edward Thomson
committed
Oct 18, 2013
1 parent
4d4ebe2
commit 31291fe
Showing
9 changed files
with
249 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,18 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace LibGit2Sharp.Core.Handles | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal class GitBuf : IDisposable | ||
{ | ||
public IntPtr ptr; | ||
public UIntPtr asize; | ||
public UIntPtr size; | ||
|
||
public void Dispose() | ||
{ | ||
Proxy.git_buf_free(this); | ||
} | ||
} | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -1,30 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using LibGit2Sharp.Core.Handles; | ||
|
||
namespace LibGit2Sharp.Core | ||
{ | ||
internal class RawContentStream : UnmanagedMemoryStream | ||
{ | ||
private readonly ObjectSafeWrapper wrapper; | ||
private readonly GitObjectSafeHandle handle; | ||
private readonly ICollection<IDisposable> linkedResources; | ||
|
||
internal RawContentStream(ObjectId id, RepositorySafeHandle repo, | ||
Func<GitObjectSafeHandle, IntPtr> bytePtrProvider, long length) | ||
: this(new ObjectSafeWrapper(id, repo), bytePtrProvider, length) | ||
internal unsafe RawContentStream( | ||
GitObjectSafeHandle handle, | ||
Func<GitObjectSafeHandle, IntPtr> bytePtrProvider, | ||
Func<GitObjectSafeHandle, long> sizeProvider, | ||
ICollection<IDisposable> linkedResources = null) | ||
: base((byte*)Wrap(handle, bytePtrProvider, linkedResources).ToPointer(), | ||
Wrap(handle, sizeProvider, linkedResources)) | ||
{ | ||
this.handle = handle; | ||
this.linkedResources = linkedResources; | ||
} | ||
|
||
unsafe RawContentStream(ObjectSafeWrapper wrapper, | ||
Func<GitObjectSafeHandle, IntPtr> bytePtrProvider, long length) | ||
: base((byte*)bytePtrProvider(wrapper.ObjectPtr).ToPointer(), length) | ||
private static T Wrap<T>( | ||
GitObjectSafeHandle handle, | ||
Func<GitObjectSafeHandle, T> provider, | ||
IEnumerable<IDisposable> linkedResources) | ||
{ | ||
this.wrapper = wrapper; | ||
T value; | ||
|
||
try | ||
{ | ||
value = provider(handle); | ||
} | ||
catch | ||
{ | ||
Dispose(handle, linkedResources); | ||
throw; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
private static void Dispose( | ||
GitObjectSafeHandle handle, | ||
IEnumerable<IDisposable> linkedResources) | ||
{ | ||
handle.SafeDispose(); | ||
|
||
if (linkedResources == null) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (IDisposable linkedResource in linkedResources) | ||
{ | ||
linkedResource.Dispose(); | ||
} | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
wrapper.SafeDispose(); | ||
Dispose(handle, linkedResources); | ||
} | ||
} | ||
} | ||
} |
This file contains 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,27 @@ | ||
using LibGit2Sharp.Core; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
/// <summary> | ||
/// Allows callers to specify how blob content filters will be applied. | ||
/// </summary> | ||
public sealed class FilteringOptions | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FilteringOptions"/> class. | ||
/// </summary> | ||
/// <param name="hintPath">The path that a file would be checked out as</param> | ||
public FilteringOptions(string hintPath) | ||
{ | ||
Ensure.ArgumentNotNull(hintPath, "hintPath"); | ||
|
||
this.HintPath = hintPath; | ||
} | ||
|
||
/// <summary> | ||
/// The path to "hint" to the filters will be used to apply | ||
/// attributes. | ||
/// </summary> | ||
public string HintPath { get; private set; } | ||
} | ||
} |
This file contains 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