27#include <git2/buffer.h>
28#include <git2/deprecated.h>
41 const char* raw =
static_cast<const char*
>( git_blob_rawcontent( aBlob ) );
42 std::size_t size = git_blob_rawsize( aBlob );
43 return std::string( raw, size );
52 if( git_buf_grow( aBuf, aContent.size() + 1 ) != 0 || !aBuf->ptr )
55 std::memcpy( aBuf->ptr, aContent.data(), aContent.size() );
56 aBuf->ptr[aContent.size()] =
'\0';
57 aBuf->size = aContent.size();
64 git_repository* repo =
const_cast<git_repository*
>( git_merge_driver_source_repo( aSource ) );
65 const git_index_entry* ancestor = git_merge_driver_source_ancestor( aSource );
66 const git_index_entry* ours = git_merge_driver_source_ours( aSource );
67 const git_index_entry* theirs = git_merge_driver_source_theirs( aSource );
69 if( !ours || !theirs )
70 return GIT_PASSTHROUGH;
72 git_blob* ancestorBlob =
nullptr;
73 git_blob* oursBlob =
nullptr;
74 git_blob* theirsBlob =
nullptr;
76 if( ancestor && git_blob_lookup( &ancestorBlob, repo, &ancestor->id ) != 0 )
81 if( git_blob_lookup( &oursBlob, repo, &ours->id ) != 0 )
86 if( git_blob_lookup( &theirsBlob, repo, &theirs->id ) != 0 )
int WriteToGitBuf(git_buf *aBuf, const std::string &aContent)
Allocate a libgit2-owned buffer big enough for aContent and copy the bytes plus a trailing NUL.
bool TryTrivialMerge(const MERGE_BLOBS &aBlobs, git_buf *aResult, int *aRc)
Resolve the trivial 3-way cases (identical sides, or one side unchanged from the ancestor).
int LoadMergeBlobs(const git_merge_driver_source *aSource, MERGE_BLOBS &aBlobs)
Look up the ancestor/ours/theirs blobs of a merge-driver source and decode them into aBlobs.
std::unique_ptr< git_blob, decltype([](git_blob *aBlob) { git_blob_free(aBlob); })> GitBlobPtr
A unique pointer for git_blob objects with automatic cleanup.
std::string BlobToString(git_blob *aBlob)
Copy a libgit2 blob's raw bytes into a std::string.
Decoded ancestor/ours/theirs blob contents for a 3-way merge driver.
std::string ancestor
Empty when there is no common ancestor.