Skip to content

Commit

Permalink
Marshal the libgit2 note functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yorah authored and nulltoken committed May 22, 2012
1 parent a3af35d commit a400fa5
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
11 changes: 11 additions & 0 deletions LibGit2Sharp/Core/GitNoteData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Runtime.InteropServices;

namespace LibGit2Sharp.Core
{
[StructLayout(LayoutKind.Sequential)]
internal class GitNoteData
{
public GitOid BlobOid;
public GitOid TargetOid;
}
}
11 changes: 11 additions & 0 deletions LibGit2Sharp/Core/Handles/NoteSafeHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace LibGit2Sharp.Core.Handles
{
internal class NoteSafeHandle : SafeHandleBase
{
protected override bool ReleaseHandle()
{
NativeMethods.git_note_free(handle);
return true;
}
}
}
51 changes: 51 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,57 @@ public static extern int git_merge_base(
GitObjectSafeHandle one,
GitObjectSafeHandle two);

[DllImport(libgit2)]
public static extern int git_note_create(
out GitOid noteOid,
RepositorySafeHandle repo,
SignatureSafeHandle author,
SignatureSafeHandle committer,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref,
ref GitOid oid,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string note);

[DllImport(libgit2)]
public static extern void git_note_free(IntPtr note);

[DllImport(libgit2)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
public static extern string git_note_message(NoteSafeHandle note);

[DllImport(libgit2)]
public static extern OidSafeHandle git_note_oid(NoteSafeHandle note);

[DllImport(libgit2)]
public static extern int git_note_read(
out NoteSafeHandle note,
RepositorySafeHandle repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref,
ref GitOid oid);

[DllImport(libgit2)]
public static extern int git_note_remove(
RepositorySafeHandle repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref,
SignatureSafeHandle author,
SignatureSafeHandle committer,
ref GitOid oid);

[DllImport(libgit2)]
public static extern int git_note_default_ref(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] out string notes_ref,
RepositorySafeHandle repo);

internal delegate int notes_foreach_callback(
GitNoteData noteData,
IntPtr payload);

[DllImport(libgit2)]
public static extern int git_note_foreach(
RepositorySafeHandle repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref,
notes_foreach_callback callback,
IntPtr payload);

[DllImport(libgit2)]
public static extern int git_odb_exists(ObjectDatabaseSafeHandle odb, ref GitOid id);

Expand Down
2 changes: 2 additions & 0 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@
<Compile Include="Core\GitBranchType.cs" />
<Compile Include="Core\GitDiff.cs" />
<Compile Include="Core\GitError.cs" />
<Compile Include="Core\GitNoteData.cs" />
<Compile Include="Core\GitObjectExtensions.cs" />
<Compile Include="Core\Handles\GitErrorSafeHandle.cs" />
<Compile Include="Core\Handles\NoteSafeHandle.cs" />
<Compile Include="Core\Handles\ObjectDatabaseSafeHandle.cs" />
<Compile Include="Core\Handles\DiffListSafeHandle.cs" />
<Compile Include="Core\Handles\GitObjectSafeHandle.cs" />
Expand Down

0 comments on commit a400fa5

Please sign in to comment.