diff options
author | Paul Betts <paul@paulbetts.org> | 2012-03-23 01:57:47 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-04-28 20:03:07 +0400 |
commit | 03fd60f72c4dc049adc816041fc6ed814669ce05 (patch) | |
tree | 38983a6eda6e860482222b34ecca9a1ed5b8814e | |
parent | 23a2c65bbac8080ca9034b75824092451fa6a20b (diff) |
Marshal the libgit2 diff functions
-rw-r--r-- | LibGit2Sharp/Core/Handles/DiffListSafeHandle.cs | 11 | ||||
-rw-r--r-- | LibGit2Sharp/Core/NativeMethods.cs | 82 | ||||
-rw-r--r-- | LibGit2Sharp/LibGit2Sharp.csproj | 1 |
3 files changed, 94 insertions, 0 deletions
diff --git a/LibGit2Sharp/Core/Handles/DiffListSafeHandle.cs b/LibGit2Sharp/Core/Handles/DiffListSafeHandle.cs new file mode 100644 index 00000000..c49c4e9a --- /dev/null +++ b/LibGit2Sharp/Core/Handles/DiffListSafeHandle.cs @@ -0,0 +1,11 @@ +namespace LibGit2Sharp.Core.Handles +{ + internal class DiffListSafeHandle : SafeHandleBase + { + protected override bool ReleaseHandle() + { + NativeMethods.git_diff_list_free(handle); + return true; + } + } +} diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 864b07d3..031e30e4 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -186,6 +186,88 @@ namespace LibGit2Sharp.Core [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value); [DllImport(libgit2)] + public static extern void git_diff_list_free(IntPtr diff); + + [DllImport(libgit2)] + public static extern int git_diff_tree_to_tree( + RepositorySafeHandle repo, + GitDiffOptions options, + GitObjectSafeHandle oldTree, + GitObjectSafeHandle newTree, + out DiffListSafeHandle diff); + + [DllImport(libgit2)] + public static extern int git_diff_index_to_tree( + RepositorySafeHandle repo, + GitDiffOptions options, + IntPtr oldTree, + out IntPtr diff); + + [DllImport(libgit2)] + public static extern int git_diff_workdir_to_index( + RepositorySafeHandle repo, + GitDiffOptions options, + out IntPtr diff); + + [DllImport(libgit2)] + public static extern int git_diff_workdir_to_tree( + RepositorySafeHandle repo, + GitDiffOptions options, + IntPtr oldTree, + out IntPtr diff); + + [DllImport(libgit2)] + public static extern int git_diff_merge(IntPtr onto, IntPtr from); + + internal delegate int git_diff_file_fn( + IntPtr data, + GitDiffDelta delta, + float progress); + + internal delegate int git_diff_hunk_fn( + IntPtr data, + GitDiffDelta delta, + GitDiffRange range, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string header, + IntPtr headerLen); + + internal delegate int git_diff_line_fn( + IntPtr data, + GitDiffDelta delta, + GitDiffLineOrigin lineOrigin, + IntPtr content, + IntPtr contentLen); + + [DllImport(libgit2)] + public static extern int git_diff_foreach( + DiffListSafeHandle diff, + IntPtr callbackData, + git_diff_file_fn fileCallback, + git_diff_hunk_fn hunkCallback, + git_diff_line_fn lineCallback); + + internal delegate int git_diff_output_fn( + IntPtr data, + GitDiffLineOrigin lineOrigin, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string formattedOutput); + + [DllImport(libgit2)] + public static extern int git_diff_print_patch( + DiffListSafeHandle diff, + IntPtr data, + git_diff_output_fn printCallback); + + [DllImport(libgit2)] + public static extern int git_diff_blobs( + RepositorySafeHandle repository, + IntPtr oldBlob, + IntPtr newBlob, + GitDiffOptions options, + object data, + git_diff_hunk_fn hunkCallback, + git_diff_line_fn lineCallback); + + [DllImport(libgit2)] public static extern int git_index_add( IndexSafeHandle index, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path, diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index c0732c84..e606fcaa 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -62,6 +62,7 @@ <Compile Include="Core\GitDiff.cs" /> <Compile Include="Core\GitObjectExtensions.cs" /> <Compile Include="Core\Handles\ObjectDatabaseSafeHandle.cs" /> + <Compile Include="Core\Handles\DiffListSafeHandle.cs" /> <Compile Include="Core\Handles\GitObjectSafeHandle.cs" /> <Compile Include="Core\Handles\IndexEntrySafeHandle.cs" /> <Compile Include="Core\Handles\NotOwnedSafeHandleBase.cs" /> |