KiCad PCB EDA Suite
Loading...
Searching...
No Matches
git_repo_mixin.h
Go to the documentation of this file.
1// This program is free software; you can redistribute it and/or modify
2// it under the terms of the GNU General Public License as published by
3// the Free Software Foundation; either version 3 of the License, or
4// (at your option) any later version.
5//
6// This program is distributed in the hope that it will be useful,
7// but WITHOUT ANY WARRANTY; without even the implied warranty of
8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9// GNU General Public License for more details.
10//
11// You should have received a copy of the GNU General Public License
12// along with this program. If not, see <https://www.gnu.org/licenses/>.
13
14#ifndef GIT_REPO_MIXIN_H
15#define GIT_REPO_MIXIN_H
16
17#include "kicad_git_common.h"
18#include "kicad_git_errors.h"
19#include "kigit_failure.h"
20#include "git_progress.h"
21#include <import_export.h>
22
24{
25public:
27 m_common( aCommon ),
28 m_cancelToken( KIGIT_COMMON::NewCancelToken() )
29 {
30 // Ensure m_common is initialized
31 wxASSERT( aCommon != nullptr );
32 }
33
35 {
36 // Non-owning, don't delete
37 }
38
43 std::vector<wxString> GetProjectDirs()
44 {
45 return m_common->GetProjectDirs();
46 }
47
53 {
54 return m_common->GetRepo();
55 }
56
61
63 {
64 return m_common;
65 }
66
70 void ResetNextKey() { m_common->ResetNextKey(); }
71
77 {
78 return m_common->GetNextPublicKey();
79 }
80
86 {
87 return m_common->GetConnType();
88 }
89
94 wxString GetUsername() const
95 {
96 return m_common->GetUsername();
97 }
98
103 void SetUsername( const wxString& aUsername )
104 {
105 m_common->SetUsername( aUsername );
106 }
107
112 void SetPassword( const wxString& aPassword )
113 {
114 m_common->SetPassword( aPassword );
115 }
116
121 void SetSSHKey( const wxString& aSSHKey )
122 {
123 m_common->SetSSHKey( aSSHKey );
124 }
125
130 wxString GetRemotename() const
131 {
132 return m_common->GetRemotename();
133 }
134
139 wxString GetProjectDir() const
140 {
141 return m_common->GetProjectDir();
142 }
143
148 std::atomic<unsigned>& TestedTypes() { return m_common->TestedTypes(); }
149
150 void UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage ) override
151 {
152 // The transfer callbacks poll this token and abort on their next tick.
153 if( !ReportProgress( aCurrent, aTotal, aMessage ) )
155 }
156
160 {
161 if( aToken )
162 m_cancelToken = aToken;
163 }
164
166
169 void SetWaitForActionLock( bool aWait ) { m_waitForActionLock = aWait; }
170
172 void SetActionLockWait( std::chrono::milliseconds aWait ) { m_actionLockWait = aWait; }
173
174 std::unique_lock<std::mutex> GetActionLock() const
175 {
177 return m_common->LockAction();
178
179 if( m_actionLockWait.count() > 0 )
180 return m_common->TryLockActionFor( m_actionLockWait );
181
182 return m_common->TryLockAction();
183 }
184
188 std::optional<KIGIT::HOST_KEY_FAILURE> GetHostKeyFailure() const { return m_hostKeyFailure; }
189 void SetHostKeyFailure( const KIGIT::HOST_KEY_FAILURE& aFailure ) { m_hostKeyFailure = aFailure; }
191
192 void SetHostKeyRefusal( const wxString& aReason ) { m_hostKeyRefusal = aReason; }
193
197 {
198 TestedTypes() = 0;
199 ResetNextKey();
201 m_hostKeyRefusal.clear();
203 m_serverMessage.clear();
204 m_pendingSideband.clear();
205 m_skippingServerLine = false;
206 m_pushRefusal.clear();
207 m_authFailed = false;
208 m_failureKind.reset();
209 }
210
212
214 bool WasAuthFailure() const { return m_authFailed; }
215 void SetAuthFailure() { m_authFailed = true; }
216
219 void ReceiveSideband( const char* aData, size_t aLength );
220
221 void SetPushRefusal( const wxString& aStatus );
222
225 KIGIT_FAILURE_REPORT ReportTransferFailure( const KIGIT_ERROR_INFO& aError, KIGIT_OPERATION aOperation,
226 const wxString& aRemoteName );
227
229 std::optional<KIGIT_FAILURE> GetFailureKind() const { return m_failureKind; }
230
231 bool IsThisOperationCancelled() const { return m_cancelToken->load(); }
232
233 void CancelThisOperation() { m_cancelToken->store( true ); }
234
235
236private:
237 void addServerLine( const wxString& aLine );
238
242 std::chrono::milliseconds m_actionLockWait{ 0 };
243
244 std::optional<KIGIT::HOST_KEY_FAILURE> m_hostKeyFailure;
247 bool m_authFailed = false;
249 std::string m_pendingSideband;
252 std::optional<KIGIT_FAILURE> m_failureKind;
253};
254
255
256#endif // GIT_REPO_MIXIN_H
GIT_PROGRESS(wxWindow *aParent, int aMaxValue1, int aMaxValue2)
bool ReportProgress(int aCurrent, int aTotal, const wxString &aMessage)
Returns false when the user pressed the reporter's cancel button.
The project's git session.
std::shared_ptr< std::atomic< bool > > CANCEL_TOKEN
One token per operation.
KIGIT_ERRORS()=default
std::chrono::milliseconds m_actionLockWait
void SetPassword(const wxString &aPassword)
Set the password.
wxString GetProjectDir() const
Get the project directory path, preserving symlinks if set.
std::vector< wxString > GetProjectDirs()
Get a list of project directories.
std::optional< KIGIT::HOST_KEY_FAILURE > GetHostKeyFailure() const
The host key this operation's transfer refused, for the UI to offer to trust or to report.
std::optional< KIGIT_FAILURE > m_failureKind
std::optional< KIGIT::HOST_KEY_FAILURE > m_hostKeyFailure
git_repository * GetRepo() const
Get a pointer to the git repository.
void SetActionLockWait(std::chrono::milliseconds aWait)
A UI caller retrying confirmed input waits this long for a background read instead of failing at once...
void SetUsername(const wxString &aUsername)
Set the username.
KIGIT_AUTH_ATTEMPT m_authAttempt
void SetHostKeyRefusal(const wxString &aReason)
KIGIT_COMMON * m_common
wxString m_hostKeyRefusal
KIGIT_COMMON::CANCEL_TOKEN m_cancelToken
virtual ~KIGIT_REPO_MIXIN()
void SetCancelToken(const KIGIT_COMMON::CANCEL_TOKEN &aToken)
Callbacks read this token rather than the session, so one operation's cancel cannot reach another.
const KIGIT_COMMON::CANCEL_TOKEN & CancelToken() const
wxString GetUsername() const
Get the username.
wxString GetNextPublicKey()
Get the next public key.
KIGIT_AUTH_ATTEMPT & AuthAttempt()
std::atomic< unsigned > & TestedTypes()
Return the connection types that have been tested for authentication.
std::optional< KIGIT_FAILURE > GetFailureKind() const
The kind of the last failure ReportTransferFailure classified, or none.
std::string m_pendingSideband
bool IsThisOperationCancelled() const
std::unique_lock< std::mutex > GetActionLock() const
void SetHostKeyFailure(const KIGIT::HOST_KEY_FAILURE &aFailure)
void SetWaitForActionLock(bool aWait)
Worker transfers may wait for a background read to finish.
KIGIT_COMMON * GetCommon() const
Get the common object.
KIGIT_REPO_MIXIN(KIGIT_COMMON *aCommon)
KIGIT_COMMON::GIT_CONN_TYPE GetConnType() const
Get the connection type.
bool WasAuthFailure() const
Set when the server refused every credential offered, so the caller can prompt and retry.
void SetSSHKey(const wxString &aSSHKey)
Set the SSH key.
void ResetTransferState()
Start a transfer with nothing left from an earlier one on this handler or session: no keys or methods...
wxString GetRemotename() const
Get the remote name.
void ResetNextKey()
Reset the next public key to test.
void UpdateProgress(int aCurrent, int aTotal, const wxString &aMessage) override
#define APIEXPORT
Macros which export functions from a DLL/DSO.
KIGIT_OPERATION
The transfer that failed, so a message nothing more specific explains can say what did not happen.
A server key the connection refused, for the UI to offer to trust or to report.
What the credential callback handed out during one operation, kept to explain a rejection.
What libgit2 reported for a failed call, read before anything else can replace it.