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;
43struct git_oid;
44enum class InitResult;
45enum class BranchResult;
46enum class PullResult;
47struct FileStatus;
50enum class RestoreResult;
51enum class PushResult;
52
53// Commit result shared across backend and handlers
64
65// Why undoing the last commit did or did not move the branch
79
80// What finishing a merge did to the working files. A partial write leaves the recovery copies
81// as the user's only route back, so the caller must keep them.
88
89
91{
92public:
93 virtual ~GIT_BACKEND() = default;
94
95 virtual void Init() = 0;
96 virtual void Shutdown() = 0;
97
98 // Clone, Push, PerformFetch and PerformPull take the action lock themselves. Every other
99 // method here expects the caller to hold it.
100
109
110 // Whether the libgit2 library is available/initialized enough for use
111 virtual bool IsLibraryAvailable() = 0;
112
113 virtual bool Clone( GIT_CLONE_HANDLER* aHandler ) = 0;
114
116 const std::vector<wxString>& aFiles,
117 const wxString& aMessage,
118 const wxString& aAuthorName,
119 const wxString& aAuthorEmail ) = 0;
120
121 virtual CommitResult Amend( GIT_COMMIT_HANDLER* aHandler, const std::vector<wxString>& aFiles,
122 const wxString& aMessage, const wxString& aAuthorName,
123 const wxString& aAuthorEmail ) = 0;
124
128 virtual UndoCommitResult UndoLastCommit( GIT_COMMIT_HANDLER* aHandler, const wxString& aExpectedBranch,
129 const git_oid& aExpectedHead, wxString& aMessage ) = 0;
130
131 virtual PushResult Push( GIT_PUSH_HANDLER* aHandler, bool aForce = false ) = 0;
132
133 virtual std::map<wxString, FileStatus> GetFileStatus( GIT_STATUS_HANDLER* aHandler, const wxString& aPathspec,
134 bool aChangedOnly ) = 0;
135
136 virtual wxString GetCurrentBranchName( GIT_STATUS_HANDLER* aHandler ) = 0;
137
138 virtual void UpdateRemoteStatus( GIT_STATUS_HANDLER* aHandler,
139 const std::set<wxString>& aLocalChanges,
140 const std::set<wxString>& aRemoteChanges,
141 std::map<wxString, FileStatus>& aFileStatus ) = 0;
142
143 virtual wxString GetWorkingDirectory( GIT_STATUS_HANDLER* aHandler ) = 0;
144
145 virtual bool GetConfigString( GIT_CONFIG_HANDLER* aHandler, const wxString& aKey,
146 wxString& aValue ) = 0;
147
148 virtual bool IsRepository( GIT_INIT_HANDLER* aHandler, const wxString& aPath ) = 0;
149 virtual InitResult InitializeRepository( GIT_INIT_HANDLER* aHandler, const wxString& aPath ) = 0;
150 virtual bool SetupRemote( GIT_INIT_HANDLER* aHandler, const RemoteConfig& aConfig ) = 0;
151
152 virtual BranchResult SwitchToBranch( GIT_BRANCH_HANDLER* aHandler, const wxString& aBranchName ) = 0;
153
154 virtual bool PerformFetch( GIT_PULL_HANDLER* aHandler, bool aSkipLock ) = 0;
155 virtual PullResult PerformPull( GIT_PULL_HANDLER* aHandler ) = 0;
156
159 virtual git_repository* GetRepositoryForFile( const char* aFilename, wxString* aError,
160 wxString* aTrustCommand ) = 0;
161 virtual int CreateBranch( git_repository* aRepo, const wxString& aBranchName, const wxString& aFrom ) = 0;
162 virtual bool RemoveVCS( git_repository*& aRepo, const wxString& aProjectPath,
163 bool aRemoveGitDir, wxString* aErrors ) = 0;
164
165 virtual bool DeleteBranch( git_repository* aRepo, const wxString& aBranchName ) = 0;
166
167 virtual bool StashSave( git_repository* aRepo, const wxString& aMessage ) = 0;
168 virtual bool StashApply( git_repository* aRepo, size_t aIndex ) = 0;
169 virtual bool StashPop( git_repository* aRepo, size_t aIndex ) = 0;
170 virtual bool StashDrop( git_repository* aRepo, size_t aIndex ) = 0;
171
172 virtual bool CreateTag( git_repository* aRepo, const wxString& aName, const wxString& aMessage ) = 0;
173 virtual bool DeleteTag( git_repository* aRepo, const wxString& aName ) = 0;
174 virtual bool CheckoutTag( git_repository* aRepo, const wxString& aName ) = 0;
175
176 virtual bool AddRemote( git_repository* aRepo, const wxString& aName, const wxString& aUrl ) = 0;
177 virtual bool SetRemoteUrl( git_repository* aRepo, const wxString& aName, const wxString& aUrl ) = 0;
178 virtual bool RemoveRemote( git_repository* aRepo, const wxString& aName ) = 0;
179
180 virtual bool SetUserConfig( git_repository* aRepo, const wxString& aName, const wxString& aEmail ) = 0;
181
182 virtual RestoreResult RestoreVersion( KIGIT_COMMON& aCommon, const wxString& aCommitHash,
183 KIGIT_ERROR_MESSAGE& aError ) = 0;
184
185 virtual bool DiscardChanges( git_repository* aRepo, const std::vector<wxString>& aPaths, wxString& aError ) = 0;
186
187 virtual bool IsPathInHead( git_repository* aRepo, const wxString& aPath ) = 0;
188
190 virtual bool AbandonOperation( git_repository* aRepo, wxString& aError ) = 0;
191
192 virtual bool GetMergeConflicts( git_repository* aRepo, const wxString& aStageDir, wxString& aHeadOid,
193 wxString& aTheirsOid, std::vector<KIGIT_CONFLICT_SIDES>& aConflicts,
194 wxString& aError ) = 0;
195
196 virtual MergeCommitResult CreateMergedCommit( git_repository* aRepo, const wxString& aExpectedHeadOid,
197 const wxString& aTheirsOid,
198 const std::vector<std::pair<wxString, wxString>>& aResolvedFiles,
199 KIGIT_ERROR_MESSAGE& aError ) = 0;
200
201protected:
203};
204
206APIEXPORT void SetGitBackend( GIT_BACKEND* aBackend );
207
208#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.
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 UndoCommitResult UndoLastCommit(GIT_COMMIT_HANDLER *aHandler, const wxString &aExpectedBranch, const git_oid &aExpectedHead, wxString &aMessage)=0
Move aExpectedBranch back to the parent of aExpectedHead, leaving the index and working files as they...
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:55
@ SuccessIndexStale
Committed, but the staged list was left as another program had it. Never retry on this.
Definition git_backend.h:59
APIEXPORT GIT_BACKEND * GetGitBackend()
MergeCommitResult
Definition git_backend.h:83
UndoCommitResult
Definition git_backend.h:67
@ TargetChanged
The branch or its last commit is no longer the one the caller saw.
Definition git_backend.h:74
@ Published
A remote-tracking branch already holds the commit, so taking it back would rewrite shared history.
Definition git_backend.h:71
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.