KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kigit_trivial_merge_base.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_TRIVIAL_MERGE_BASE_H
22#define KIGIT_TRIVIAL_MERGE_BASE_H
23
25
26
36template <typename DERIVED>
38{
39public:
40 KIGIT_TRIVIAL_MERGE_BASE( git_merge_driver_source* aSource, git_buf* aBuf ) :
41 m_mergeDriver( aSource ),
42 m_result( aBuf )
43 {}
44
45 int Merge()
46 {
48
49 if( int rc = KIGIT::LoadMergeBlobs( m_mergeDriver, blobs ); rc != 0 )
50 return rc;
51
52 int rc = 0;
53
54 if( KIGIT::TryTrivialMerge( blobs, m_result, &rc ) )
55 return rc;
56
57 if( KIGIT::WriteToGitBuf( m_result, blobs.ours ) != 0 )
58 return -1;
59
60 return GIT_EMERGECONFLICT;
61 }
62
63 static int Apply( const git_merge_driver_source* aSrc, const char** aPathOut,
64 unsigned int* aModeOut, git_buf* aMergedOut )
65 {
66 return KIGIT::ApplyMergeDriver<DERIVED>( aSrc, aPathOut, aModeOut, aMergedOut );
67 }
68
69private:
70 git_merge_driver_source* m_mergeDriver;
71 git_buf* m_result;
72};
73
74#endif // KIGIT_TRIVIAL_MERGE_BASE_H
KIGIT_TRIVIAL_MERGE_BASE(git_merge_driver_source *aSource, git_buf *aBuf)
git_merge_driver_source * m_mergeDriver
static int Apply(const git_merge_driver_source *aSrc, const char **aPathOut, unsigned int *aModeOut, git_buf *aMergedOut)
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.
Decoded ancestor/ours/theirs blob contents for a 3-way merge driver.