KiCad PCB EDA Suite
Loading...
Searching...
No Matches
git_backend.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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef GIT_BACKEND_H_
21#define GIT_BACKEND_H_
22
23#include <map>
24#include <import_export.h>
25#include <set>
26#include <utility>
27#include <vector>
28#include <wx/string.h>
29
31
40class KIGIT_COMMON;
41struct RemoteConfig;
42struct git_repository;
43enum class InitResult;
44enum class BranchResult;
45enum class PullResult;
46struct FileStatus;
49enum class RestoreResult;
50enum class PushResult;
51
52// Commit result shared across backend and handlers
63
64// What finishing a merge did to the working files. A partial write leaves the recovery copies
65// as the user's only route back, so the caller must keep them.
72
73
75{
76public:
77 virtual ~GIT_BACKEND() = default;
78
79 virtual void Init() = 0;
80 virtual void Shutdown() = 0;
81
82 // Clone, Push, PerformFetch and PerformPull take the action lock themselves. Every other
83 // method here expects the caller to hold it.
84
93
94 // Whether the libgit2 library is available/initialized enough for use
95 virtual bool IsLibraryAvailable() = 0;
96
97 virtual bool Clone( GIT_CLONE_HANDLER* aHandler ) = 0;
98
100 const std::vector<wxString>& aFiles,
101 const wxString& aMessage,
102 const wxString& aAuthorName,
103 const wxString& aAuthorEmail ) = 0;
104
105 virtual CommitResult Amend( GIT_COMMIT_HANDLER* aHandler, const std::vector<wxString>& aFiles,
106 const wxString& aMessage, const wxString& aAuthorName,
107 const wxString& aAuthorEmail ) = 0;
108
109 virtual PushResult Push( GIT_PUSH_HANDLER* aHandler, bool aForce = false ) = 0;
110
111 virtual std::map<wxString, FileStatus> GetFileStatus( GIT_STATUS_HANDLER* aHandler, const wxString& aPathspec,
112 bool aChangedOnly ) = 0;
113
114 virtual wxString GetCurrentBranchName( GIT_STATUS_HANDLER* aHandler ) = 0;
115
116 virtual void UpdateRemoteStatus( GIT_STATUS_HANDLER* aHandler,
117 const std::set<wxString>& aLocalChanges,
118 const std::set<wxString>& aRemoteChanges,
119 std::map<wxString, FileStatus>& aFileStatus ) = 0;
120
121 virtual wxString GetWorkingDirectory( GIT_STATUS_HANDLER* aHandler ) = 0;
122
123 virtual bool GetConfigString( GIT_CONFIG_HANDLER* aHandler, const wxString& aKey,
124 wxString& aValue ) = 0;
125
126 virtual bool IsRepository( GIT_INIT_HANDLER* aHandler, const wxString& aPath ) = 0;
127 virtual InitResult InitializeRepository( GIT_INIT_HANDLER* aHandler, const wxString& aPath ) = 0;
128 virtual bool SetupRemote( GIT_INIT_HANDLER* aHandler, const RemoteConfig& aConfig ) = 0;
129
130 virtual BranchResult SwitchToBranch( GIT_BRANCH_HANDLER* aHandler, const wxString& aBranchName ) = 0;
131
132 virtual bool PerformFetch( GIT_PULL_HANDLER* aHandler, bool aSkipLock ) = 0;
133 virtual PullResult PerformPull( GIT_PULL_HANDLER* aHandler ) = 0;
134
137 virtual git_repository* GetRepositoryForFile( const char* aFilename, wxString* aError,
138 wxString* aTrustCommand ) = 0;
139 virtual int CreateBranch( git_repository* aRepo, const wxString& aBranchName, const wxString& aFrom ) = 0;
140 virtual bool RemoveVCS( git_repository*& aRepo, const wxString& aProjectPath,
141 bool aRemoveGitDir, wxString* aErrors ) = 0;
142
143 virtual bool DeleteBranch( git_repository* aRepo, const wxString& aBranchName ) = 0;
144
145 virtual bool StashSave( git_repository* aRepo, const wxString& aMessage ) = 0;
146 virtual bool StashApply( git_repository* aRepo, size_t aIndex ) = 0;
147 virtual bool StashPop( git_repository* aRepo, size_t aIndex ) = 0;
148 virtual bool StashDrop( git_repository* aRepo, size_t aIndex ) = 0;
149
150 virtual bool CreateTag( git_repository* aRepo, const wxString& aName, const wxString& aMessage ) = 0;
151 virtual bool DeleteTag( git_repository* aRepo, const wxString& aName ) = 0;
152 virtual bool CheckoutTag( git_repository* aRepo, const wxString& aName ) = 0;
153
154 virtual bool AddRemote( git_repository* aRepo, const wxString& aName, const wxString& aUrl ) = 0;
155 virtual bool SetRemoteUrl( git_repository* aRepo, const wxString& aName, const wxString& aUrl ) = 0;
156 virtual bool RemoveRemote( git_repository* aRepo, const wxString& aName ) = 0;
157
158 virtual bool SetUserConfig( git_repository* aRepo, const wxString& aName, const wxString& aEmail ) = 0;
159
160 virtual RestoreResult RestoreVersion( KIGIT_COMMON& aCommon, const wxString& aCommitHash,
161 KIGIT_ERROR_MESSAGE& aError ) = 0;
162
163 virtual bool DiscardChanges( git_repository* aRepo, const std::vector<wxString>& aPaths, wxString& aError ) = 0;
164
165 virtual bool IsPathInHead( git_repository* aRepo, const wxString& aPath ) = 0;
166
168 virtual bool AbandonOperation( git_repository* aRepo, wxString& aError ) = 0;
169
170 virtual bool GetMergeConflicts( git_repository* aRepo, const wxString& aStageDir, wxString& aHeadOid,
171 wxString& aTheirsOid, std::vector<KIGIT_CONFLICT_SIDES>& aConflicts,
172 wxString& aError ) = 0;
173
174 virtual MergeCommitResult CreateMergedCommit( git_repository* aRepo, const wxString& aExpectedHeadOid,
175 const wxString& aTheirsOid,
176 const std::vector<std::pair<wxString, wxString>>& aResolvedFiles,
177 KIGIT_ERROR_MESSAGE& aError ) = 0;
178
179protected:
181};
182
184APIEXPORT void SetGitBackend( GIT_BACKEND* aBackend );
185
186#endif
virtual RestoreResult RestoreVersion(KIGIT_COMMON &aCommon, const wxString &aCommitHash, KIGIT_ERROR_MESSAGE &aError)=0
virtual InitResult InitializeRepository(GIT_INIT_HANDLER *aHandler, const wxString &aPath)=0
virtual bool CreateTag(git_repository *aRepo, const wxString &aName, const wxString &aMessage)=0
virtual bool IsLibraryAvailable()=0
virtual bool CheckoutTag(git_repository *aRepo, const wxString &aName)=0
virtual int CreateBranch(git_repository *aRepo, const wxString &aBranchName, const wxString &aFrom)=0
virtual bool GetConfigString(GIT_CONFIG_HANDLER *aHandler, const wxString &aKey, wxString &aValue)=0
virtual PushResult Push(GIT_PUSH_HANDLER *aHandler, bool aForce=false)=0
virtual bool DeleteTag(git_repository *aRepo, const wxString &aName)=0
virtual void Shutdown()=0
KIGIT_ORPHAN_REGISTRY m_orphanRegistry
virtual bool SetRemoteUrl(git_repository *aRepo, const wxString &aName, const wxString &aUrl)=0
virtual bool AbandonOperation(git_repository *aRepo, wxString &aError)=0
Drop a merge, rebase, cherry-pick or revert left in progress and return to the last commit.
virtual ~GIT_BACKEND()=default
virtual bool GetMergeConflicts(git_repository *aRepo, const wxString &aStageDir, wxString &aHeadOid, wxString &aTheirsOid, std::vector< KIGIT_CONFLICT_SIDES > &aConflicts, wxString &aError)=0
virtual void Init()=0
KIGIT_ORPHAN_REGISTRY & OrphanRegistry()
Return the process-wide orphan thread registry owned by this backend.
Definition git_backend.h:92
virtual PullResult PerformPull(GIT_PULL_HANDLER *aHandler)=0
virtual wxString GetWorkingDirectory(GIT_STATUS_HANDLER *aHandler)=0
virtual bool IsRepository(GIT_INIT_HANDLER *aHandler, const wxString &aPath)=0
virtual bool DeleteBranch(git_repository *aRepo, const wxString &aBranchName)=0
virtual bool AddRemote(git_repository *aRepo, const wxString &aName, const wxString &aUrl)=0
virtual bool StashPop(git_repository *aRepo, size_t aIndex)=0
virtual MergeCommitResult CreateMergedCommit(git_repository *aRepo, const wxString &aExpectedHeadOid, const wxString &aTheirsOid, const std::vector< std::pair< wxString, wxString > > &aResolvedFiles, KIGIT_ERROR_MESSAGE &aError)=0
virtual bool Clone(GIT_CLONE_HANDLER *aHandler)=0
virtual bool StashApply(git_repository *aRepo, size_t aIndex)=0
virtual bool SetUserConfig(git_repository *aRepo, const wxString &aName, const wxString &aEmail)=0
virtual bool IsPathInHead(git_repository *aRepo, const wxString &aPath)=0
virtual bool DiscardChanges(git_repository *aRepo, const std::vector< wxString > &aPaths, wxString &aError)=0
virtual bool StashSave(git_repository *aRepo, const wxString &aMessage)=0
virtual BranchResult SwitchToBranch(GIT_BRANCH_HANDLER *aHandler, const wxString &aBranchName)=0
virtual git_repository * GetRepositoryForFile(const char *aFilename, wxString *aError, wxString *aTrustCommand)=0
aError receives why git refused to open the repository, and aTrustCommand the command that trusts it ...
virtual bool StashDrop(git_repository *aRepo, size_t aIndex)=0
virtual bool RemoveVCS(git_repository *&aRepo, const wxString &aProjectPath, bool aRemoveGitDir, wxString *aErrors)=0
virtual wxString GetCurrentBranchName(GIT_STATUS_HANDLER *aHandler)=0
virtual bool PerformFetch(GIT_PULL_HANDLER *aHandler, bool aSkipLock)=0
virtual std::map< wxString, FileStatus > GetFileStatus(GIT_STATUS_HANDLER *aHandler, const wxString &aPathspec, bool aChangedOnly)=0
virtual void UpdateRemoteStatus(GIT_STATUS_HANDLER *aHandler, const std::set< wxString > &aLocalChanges, const std::set< wxString > &aRemoteChanges, std::map< wxString, FileStatus > &aFileStatus)=0
virtual CommitResult Commit(GIT_COMMIT_HANDLER *aHandler, const std::vector< wxString > &aFiles, const wxString &aMessage, const wxString &aAuthorName, const wxString &aAuthorEmail)=0
virtual CommitResult Amend(GIT_COMMIT_HANDLER *aHandler, const std::vector< wxString > &aFiles, const wxString &aMessage, const wxString &aAuthorName, const wxString &aAuthorEmail)=0
virtual bool RemoveRemote(git_repository *aRepo, const wxString &aName)=0
virtual bool SetupRemote(GIT_INIT_HANDLER *aHandler, const RemoteConfig &aConfig)=0
The project's git session.
Registry of background git cleanup threads that outlive the owning project or dialog.
APIEXPORT void SetGitBackend(GIT_BACKEND *aBackend)
CommitResult
Definition git_backend.h:54
@ SuccessIndexStale
Committed, but the staged list was left as another program had it. Never retry on this.
Definition git_backend.h:58
APIEXPORT GIT_BACKEND * GetGitBackend()
MergeCommitResult
Definition git_backend.h:67
InitResult
PullResult
PushResult
#define APIEXPORT
Macros which export functions from a DLL/DSO.
RestoreResult
A summary the user can act on, with the raw text that explains it kept apart for the details.