KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kigit_merge_blob_utils.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 */
20
21#ifndef KIGIT_MERGE_BLOB_UTILS_H
22#define KIGIT_MERGE_BLOB_UTILS_H
23
24#include <kicommon.h>
25
26#include <git2.h>
27#include <git2/sys/merge.h>
28
29#include <string>
30
31
32namespace KIGIT
33{
34
39KICOMMON_API std::string BlobToString( git_blob* aBlob );
40
41
49KICOMMON_API int WriteToGitBuf( git_buf* aBuf, const std::string& aContent );
50
51
54{
55 std::string ancestor;
56 std::string ours;
57 std::string theirs;
58};
59
60
69KICOMMON_API int LoadMergeBlobs( const git_merge_driver_source* aSource, MERGE_BLOBS& aBlobs );
70
71
78KICOMMON_API bool TryTrivialMerge( const MERGE_BLOBS& aBlobs, git_buf* aResult, int* aRc );
79
80
87template <typename DRIVER>
88int ApplyMergeDriver( const git_merge_driver_source* aSrc, const char** aPathOut,
89 unsigned int* aModeOut, git_buf* aMergedOut )
90{
91 if( !aSrc || !aPathOut || !aModeOut || !aMergedOut )
92 return -1;
93
94 DRIVER driver( const_cast<git_merge_driver_source*>( aSrc ), aMergedOut );
95 int rc = driver.Merge();
96
97 if( rc == 0 || rc == GIT_EMERGECONFLICT )
98 {
99 if( const git_index_entry* oursEntry = git_merge_driver_source_ours( aSrc ) )
100 {
101 *aPathOut = oursEntry->path;
102 *aModeOut = oursEntry->mode;
103 }
104 }
105
106 return rc;
107}
108
109} // namespace KIGIT
110
111#endif // KIGIT_MERGE_BLOB_UTILS_H
#define KICOMMON_API
Definition kicommon.h:27
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.
int ApplyMergeDriver(const git_merge_driver_source *aSrc, const char **aPathOut, unsigned int *aModeOut, git_buf *aMergedOut)
Shared libgit2 merge-driver apply callback shim.
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.