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
72 {
73 return m_common->GetConnType();
74 }
75
80 wxString GetUsername() const
81 {
82 return m_common->GetUsername();
83 }
84
89 void SetUsername( const wxString& aUsername )
90 {
91 m_common->SetUsername( aUsername );
92 }
93
98 void SetPassword( const wxString& aPassword )
99 {
100 m_common->SetPassword( aPassword );
101 }
102
107 void SetSSHKey( const wxString& aSSHKey )
108 {
109 m_common->SetSSHKey( aSSHKey );
110 }
111
116 wxString GetRemotename() const
117 {
118 return m_common->GetRemotename();
119 }
120
125 wxString GetProjectDir() const
126 {
127 return m_common->GetProjectDir();
128 }
129
130 void UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage ) override
131 {
132 // The transfer callbacks poll this token and abort on their next tick.
133 if( !ReportProgress( aCurrent, aTotal, aMessage ) )
135 }
136
140 {
141 if( aToken )
142 m_cancelToken = aToken;
143 }
144
146
149 void SetWaitForActionLock( bool aWait ) { m_waitForActionLock = aWait; }
150
152 void SetActionLockWait( std::chrono::milliseconds aWait ) { m_actionLockWait = aWait; }
153
154 std::unique_lock<std::mutex> GetActionLock() const
155 {
157 return m_common->LockAction();
158
159 if( m_actionLockWait.count() > 0 )
160 return m_common->TryLockActionFor( m_actionLockWait );
161
162 return m_common->TryLockAction();
163 }
164
168 std::optional<KIGIT::HOST_KEY_FAILURE> GetHostKeyFailure() const { return m_hostKeyFailure; }
169 void SetHostKeyFailure( const KIGIT::HOST_KEY_FAILURE& aFailure ) { m_hostKeyFailure = aFailure; }
171
172 void SetHostKeyRefusal( const wxString& aReason ) { m_hostKeyRefusal = aReason; }
173
177 {
178 m_common->ResetNextKey();
180 m_hostKeyRefusal.clear();
182 m_serverMessage.clear();
183 m_pendingSideband.clear();
184 m_skippingServerLine = false;
185 m_pushRefusal.clear();
186 m_authFailed = false;
187 m_failureKind.reset();
188 }
189
191
193 void RememberWorkingSSHKey() { m_common->RememberWorkingSSHKey( m_authAttempt ); }
194
196 bool WasAuthFailure() const { return m_authFailed; }
197 void SetAuthFailure() { m_authFailed = true; }
198
201 void ReceiveSideband( const char* aData, size_t aLength );
202
203 void SetPushRefusal( const wxString& aStatus );
204
207 KIGIT_FAILURE_REPORT ReportTransferFailure( const KIGIT_ERROR_INFO& aError, KIGIT_OPERATION aOperation,
208 const wxString& aRemoteName );
209
211 std::optional<KIGIT_FAILURE> GetFailureKind() const { return m_failureKind; }
212
213 bool IsThisOperationCancelled() const { return m_cancelToken->load(); }
214
215 void CancelThisOperation() { m_cancelToken->store( true ); }
216
217
218private:
219 void addServerLine( const wxString& aLine );
220
224 std::chrono::milliseconds m_actionLockWait{ 0 };
225
226 std::optional<KIGIT::HOST_KEY_FAILURE> m_hostKeyFailure;
229 bool m_authFailed = false;
231 std::string m_pendingSideband;
234 std::optional<KIGIT_FAILURE> m_failureKind;
235};
236
237
238#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.
KIGIT_AUTH_ATTEMPT & AuthAttempt()
std::optional< KIGIT_FAILURE > GetFailureKind() const
The kind of the last failure ReportTransferFailure classified, or none.
std::string m_pendingSideband
void RememberWorkingSSHKey()
Call once the transfer has connected, so the key that worked is offered first next time.
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: the first key offe...
wxString GetRemotename() const
Get the remote name.
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.