From a400fa557ccddc40cbaa87c64210ae68ac941d6d Mon Sep 17 00:00:00 2001 From: yorah Date: Sat, 28 Apr 2012 18:18:30 +0200 Subject: Marshal the libgit2 note functions --- LibGit2Sharp/Core/GitNoteData.cs | 11 +++++++ LibGit2Sharp/Core/Handles/NoteSafeHandle.cs | 11 +++++++ LibGit2Sharp/Core/NativeMethods.cs | 51 +++++++++++++++++++++++++++++ LibGit2Sharp/LibGit2Sharp.csproj | 2 ++ 4 files changed, 75 insertions(+) create mode 100644 LibGit2Sharp/Core/GitNoteData.cs create mode 100644 LibGit2Sharp/Core/Handles/NoteSafeHandle.cs (limited to 'LibGit2Sharp') diff --git a/LibGit2Sharp/Core/GitNoteData.cs b/LibGit2Sharp/Core/GitNoteData.cs new file mode 100644 index 00000000..6592ab8c --- /dev/null +++ b/LibGit2Sharp/Core/GitNoteData.cs @@ -0,0 +1,11 @@ +using System.Runtime.InteropServices; + +namespace LibGit2Sharp.Core +{ + [StructLayout(LayoutKind.Sequential)] + internal class GitNoteData + { + public GitOid BlobOid; + public GitOid TargetOid; + } +} diff --git a/LibGit2Sharp/Core/Handles/NoteSafeHandle.cs b/LibGit2Sharp/Core/Handles/NoteSafeHandle.cs new file mode 100644 index 00000000..22e8fcff --- /dev/null +++ b/LibGit2Sharp/Core/Handles/NoteSafeHandle.cs @@ -0,0 +1,11 @@ +namespace LibGit2Sharp.Core.Handles +{ + internal class NoteSafeHandle : SafeHandleBase + { + protected override bool ReleaseHandle() + { + NativeMethods.git_note_free(handle); + return true; + } + } +} diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index ffe53751..a6b9bb3e 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -339,6 +339,57 @@ namespace LibGit2Sharp.Core 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); diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index fc6bbd76..b6b79caf 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -62,8 +62,10 @@ + + -- cgit v1.2.3