8000 Marshal the libgit2 diff functions · gitextensions/libgit2sharp@03fd60f · GitHub
[go: up one dir, main page]

Skip to content

Commit 03fd60f

Browse files
anaisbettsnulltoken
authored andcommitted
Marshal the libgit2 diff functions
1 parent 23a2c65 commit 03fd60f

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace LibGit2Sharp.Core.Handles
2+
{
3+
internal class DiffListSafeHandle : SafeHandleBase
4+
{
5+
protected override bool ReleaseHandle()
6+
{
7+
NativeMethods.git_diff_list_free(handle);
8+
return true;
9+
}
10+
}
11+
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,88 @@ public static extern int git_config_set_string(
185185
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name,
186186
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value);
187187

188+
[DllImport(libgit2)]
189+
public static extern void git_diff_list_free(IntPtr diff);
190+
191+
[DllImport(libgit2)]
192+
public static extern int git_diff_tree_to_tree(
193+
RepositorySafeHandle repo,
194+
GitDiffOptions options,
195+
GitObjectSafeHandle oldTree,
196+
GitObjectSafeHandle newTree,
197+
out DiffListSafeHandle diff);
198+
199+
[DllImport(libgit2)]
200+
public static extern int git_diff_index_to_tree(
201+
RepositorySafeHandle repo,
202+
GitDiffOptions options,
203+
IntPtr oldTree,
204+
out IntPtr diff);
205+
206+
[DllImport(libgit2)]
207+
public static extern int git_diff_workdir_to_index(
208+
RepositorySafeHandle repo,
209+
GitDiffOptions options,
210+
out IntPtr diff);
211+
212+
[DllImport(libgit2)]
213+
public static extern int git_diff_workdir_to_tree(
214+
RepositorySafeHandle repo,
215+
GitDiffOptions options,
216+
IntPtr oldTree,
217+
out IntPtr diff);
218+
219+
[DllImport(libgit2)]
220+
public static extern int git_diff_merge(IntPtr onto, IntPtr from);
221+
222+
internal delegate int git_diff_file_fn(
223+
IntPtr data,
224+
GitDiffDelta delta,
225+
float progress);
226+
227+
internal delegate int git_diff_hunk_fn(
228+
IntPtr data,
229+
GitDiffDelta delta,
230+
GitDiffRange range,
231+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string header,
232+
IntPtr headerLen);
233+
234+
internal delegate int git_diff_line_fn(
235+
IntPtr data,
236+
GitDiffDelta delta,
237+
GitDiffLineOrigin lineOrigin,
238+
IntPtr content,
239+
IntPtr contentLen);
240+
241+
[DllImport(libgit2)]
242+
public static extern int git_diff_foreach(
243+
DiffListSafeHandle diff,
244+
IntPtr callbackData,
245+
git_diff_file_fn fileCallback,
246+
git_diff_hunk_fn hunkCallback,
247+
git_diff_line_fn lineCallback);
248+
249+
internal delegate int git_diff_output_fn(
250+
IntPtr data,
251+
GitDiffLineOrigin lineOrigin,
252+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string formattedOutput);
253+
254+
[DllImport(libgit2)]
255+
public static extern int git_diff_print_patch(
256+
DiffListSafeHandle diff,
257+
IntPtr data,
258+
git_diff_output_fn printCallback);
259+
260+
[DllImport(libgit2)]
261+
public static extern int git_diff_blobs(
262+
RepositorySafeHandle repository,
263+
IntPtr oldBlob,
264+
IntPtr newBlob,
265+
GitDiffOptions options,
266+
object data,
267+
git_diff_hunk_fn hunkCallback,
268+
git_diff_line_fn lineCallback);
269+
188270
[DllImport(libgit2)]
189271
public static extern int git_index_add(
190272
IndexSafeHandle index,

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="Core\GitDiff.cs" />
6363
<Compile Include="Core\GitObjectExtensions.cs" />
6464
<Compile Include="Core\Handles\ObjectDatabaseSafeHandle.cs" />
65+
<Compile Include="Core\Handles\DiffListSafeHandle.cs" />
6566
<Compile Include="Core\Handles\GitObjectSafeHandle.cs" />
6667
<Compile Include="Core\Handles\IndexEntrySafeHandle.cs" />
6768
<Compile Include="Core\Handles\NotOwnedSafeHandleBase.cs" />

0 commit comments

Comments
 (0)