diff --git a/common/git/git_pull_handler.cpp b/common/git/git_pull_handler.cpp index e13e550474..b08043f8d0 100644 --- a/common/git/git_pull_handler.cpp +++ b/common/git/git_pull_handler.cpp @@ -76,6 +76,7 @@ bool GIT_PULL_HANDLER::PerformFetch( bool aSkipLock ) remoteCallbacks.transfer_progress = transfer_progress_cb; remoteCallbacks.credentials = credentials_cb; remoteCallbacks.payload = this; + GetCommon()->SetCancelled( false ); TestedTypes() = 0; ResetNextKey(); diff --git a/common/git/git_push_handler.cpp b/common/git/git_push_handler.cpp index 6f521bbbf1..316011936e 100644 --- a/common/git/git_push_handler.cpp +++ b/common/git/git_push_handler.cpp @@ -67,6 +67,7 @@ PushResult GIT_PUSH_HANDLER::PerformPush() remoteCallbacks.push_transfer_progress = push_transfer_progress_cb; remoteCallbacks.credentials = credentials_cb; remoteCallbacks.payload = this; + GetCommon()->SetCancelled( false ); TestedTypes() = 0; ResetNextKey(); diff --git a/common/git/kicad_git_common.cpp b/common/git/kicad_git_common.cpp index 94631b4b0c..446d574efd 100644 --- a/common/git/kicad_git_common.cpp +++ b/common/git/kicad_git_common.cpp @@ -830,6 +830,12 @@ extern "C" int progress_cb( const char* str, int len, void* aPayload ) { KIGIT_REPO_MIXIN* parent = reinterpret_cast( aPayload ); + if( parent->GetCommon()->IsCancelled() ) + { + wxLogTrace( traceGit, "Progress CB cancelled" ); + return GIT_EUSER; + } + wxString progressMessage( str, len ); parent->UpdateProgress( 0, 0, progressMessage ); @@ -844,6 +850,11 @@ extern "C" int transfer_progress_cb( const git_transfer_progress* aStats, void* wxString progressMessage = wxString::Format( _( "Received %u of %u objects" ), aStats->received_objects, aStats->total_objects ); + if( parent->GetCommon()->IsCancelled() ) + { + wxLogTrace( traceGit, "Transfer progress cancelled" ); + return GIT_EUSER; + } parent->UpdateProgress( aStats->received_objects, aStats->total_objects, progressMessage ); diff --git a/common/git/kicad_git_common.h b/common/git/kicad_git_common.h index 886526d3e6..e3150339fa 100644 --- a/common/git/kicad_git_common.h +++ b/common/git/kicad_git_common.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -146,6 +147,16 @@ public: return wxString( error->message ); } + bool IsCancelled() const + { + return m_cancel.load(); + } + + void SetCancelled( bool aCancel ) + { + m_cancel.store( aCancel ); + } + protected: git_repository* m_repo; @@ -172,6 +183,8 @@ private: std::vector m_publicKeys; int m_nextPublicKey; + std::atomic m_cancel; // Set to true when the user cancels an operation + // Create a dummy flag to tell if we have tested ssh agent credentials separately // from the ssh key credentials static const unsigned KIGIT_CREDENTIAL_SSH_AGENT = 1 << sizeof( m_testedTypes - 1 ); diff --git a/kicad/project_tree_pane.cpp b/kicad/project_tree_pane.cpp index 04dc2ce037..043940a735 100644 --- a/kicad/project_tree_pane.cpp +++ b/kicad/project_tree_pane.cpp @@ -1593,6 +1593,8 @@ void PROJECT_TREE_PANE::EmptyTreePrj() // Remove the git repository when the project is unloaded if( m_TreeProject->GetGitRepo() ) { + m_TreeProject->GitCommon()->SetCancelled( true ); + // We need to lock the mutex to ensure that no other thread is using the git repository std::unique_lock lock( m_TreeProject->GitCommon()->m_gitActionMutex, std::try_to_lock );