Add support for registering custom merge drivers. by maskmaster · Pull Request #2107 · libgit2/libgit2sharp · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
255 changes: 255 additions & 0 deletions LibGit2Sharp.Tests/MergeDriverFixture.cs
8 changes: 8 additions & 0 deletions LibGit2Sharp/Core/GitBuf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ public void Dispose()
Proxy.git_buf_dispose(this);
}
}

[StructLayout(LayoutKind.Sequential)]
unsafe struct git_buf
{
public IntPtr ptr;
public UIntPtr asize;
public UIntPtr size;
}
}
3 changes: 2 additions & 1 deletion LibGit2Sharp/Core/GitErrorCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal enum GitErrorCategory
Filesystem,
Patch,
Worktree,
Sha1
Sha1,
MergeDriver
}
}
57 changes: 57 additions & 0 deletions LibGit2Sharp/Core/GitMergeDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Runtime.InteropServices;

namespace LibGit2Sharp.Core
{
[StructLayout(LayoutKind.Sequential)]
internal struct GitMergeDriver
{
/** The `version` should be set to `GIT_MERGE_DRIVER_VERSION`. */
public uint version;

/** Called when the merge driver is first used for any file. */
[MarshalAs(UnmanagedType.FunctionPtr)]
public git_merge_driver_init_fn initialize;

/** Called when the merge driver is unregistered from the system. */
[MarshalAs(UnmanagedType.FunctionPtr)]
public git_merge_driver_shutdown_fn shutdown;

/**
* Called to merge the contents of a conflict. If this function
* returns `GIT_PASSTHROUGH` then the default (`text`) merge driver
* will instead be invoked. If this function returns
* `GIT_EMERGECONFLICT` then the file will remain conflicted.
*/
[MarshalAs(UnmanagedType.FunctionPtr)]
public git_merge_driver_apply_fn apply;

internal delegate int git_merge_driver_init_fn(IntPtr merge_driver);
internal delegate void git_merge_driver_shutdown_fn(IntPtr merge_driver);

/** Called when the merge driver is invoked due to a file level merge conflict. */
internal delegate int git_merge_driver_apply_fn(
IntPtr merge_driver,
IntPtr path_out,
UIntPtr mode_out,
IntPtr merged_out,
IntPtr driver_name,
IntPtr merge_driver_source
);
}

/// <summary>
/// The file source being merged
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct git_merge_driver_source
{
public git_repository* repository;
readonly char *default_driver;
readonly IntPtr file_opts;

public git_index_entry* ancestor;
public git_index_entry* ours;
public git_index_entry* theirs;
}
}
13 changes: 13 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Loading