From c19341dfe746db22366c31941a0f07d2d2ce24bf Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 4 Feb 2026 11:38:42 -0500 Subject: [PATCH] Coding policy fixes. --- common/git/git_backend.cpp | 1 + common/git/git_branch_handler.cpp | 6 +- common/git/git_commit_handler.cpp | 7 +-- common/git/git_config_handler.cpp | 7 ++- common/git/git_init_handler.cpp | 7 ++- common/git/git_progress.h | 3 +- common/git/git_pull_handler.cpp | 8 ++- common/git/git_push_handler.cpp | 2 + common/git/git_push_handler.h | 4 +- common/git/git_status_handler.cpp | 10 +++- common/git/kicad_git_common.cpp | 12 +++- common/git/libgit_backend.cpp | 94 ++++++++++++++++++++++--------- common/git/project_git_utils.cpp | 7 ++- common/git/project_git_utils.h | 6 +- 14 files changed, 127 insertions(+), 47 deletions(-) diff --git a/common/git/git_backend.cpp b/common/git/git_backend.cpp index 563ab4abb1..024075f7fb 100644 --- a/common/git/git_backend.cpp +++ b/common/git/git_backend.cpp @@ -30,6 +30,7 @@ GIT_BACKEND* GetGitBackend() return s_backend; } + void SetGitBackend( GIT_BACKEND* aBackend ) { s_backend = aBackend; diff --git a/common/git/git_branch_handler.cpp b/common/git/git_branch_handler.cpp index a4e362db19..bcd5afb558 100644 --- a/common/git/git_branch_handler.cpp +++ b/common/git/git_branch_handler.cpp @@ -31,20 +31,24 @@ GIT_BRANCH_HANDLER::GIT_BRANCH_HANDLER( KIGIT_COMMON* aCommon ) : KIGIT_REPO_MIXIN( aCommon ) {} + GIT_BRANCH_HANDLER::~GIT_BRANCH_HANDLER() {} + bool GIT_BRANCH_HANDLER::BranchExists( const wxString& aBranchName ) { return GetGitBackend()->BranchExists( this, aBranchName ); } + BranchResult GIT_BRANCH_HANDLER::SwitchToBranch( const wxString& aBranchName ) { return GetGitBackend()->SwitchToBranch( this, aBranchName ); } + void GIT_BRANCH_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage ) { ReportProgress( aCurrent, aTotal, aMessage ); -} \ No newline at end of file +} diff --git a/common/git/git_commit_handler.cpp b/common/git/git_commit_handler.cpp index c11d65ec98..d7652a84f0 100644 --- a/common/git/git_commit_handler.cpp +++ b/common/git/git_commit_handler.cpp @@ -35,9 +35,9 @@ GIT_COMMIT_HANDLER::~GIT_COMMIT_HANDLER() CommitResult GIT_COMMIT_HANDLER::PerformCommit( const std::vector& aFiles, - const wxString& aMessage, - const wxString& aAuthorName, - const wxString& aAuthorEmail ) + const wxString& aMessage, + const wxString& aAuthorName, + const wxString& aAuthorEmail ) { return GetGitBackend()->Commit( this, aFiles, aMessage, aAuthorName, aAuthorEmail ); } @@ -53,4 +53,3 @@ void GIT_COMMIT_HANDLER::AddErrorString( const wxString& aErrorString ) { m_errorString += aErrorString; } - diff --git a/common/git/git_config_handler.cpp b/common/git/git_config_handler.cpp index 67daf5b8da..9920bec720 100644 --- a/common/git/git_config_handler.cpp +++ b/common/git/git_config_handler.cpp @@ -33,9 +33,11 @@ GIT_CONFIG_HANDLER::GIT_CONFIG_HANDLER( KIGIT_COMMON* aCommon ) : KIGIT_REPO_MIXIN( aCommon ) {} + GIT_CONFIG_HANDLER::~GIT_CONFIG_HANDLER() {} + GitUserConfig GIT_CONFIG_HANDLER::GetUserConfig() { GitUserConfig userConfig; @@ -58,17 +60,20 @@ GitUserConfig GIT_CONFIG_HANDLER::GetUserConfig() return userConfig; } + wxString GIT_CONFIG_HANDLER::GetWorkingDirectory() { return GetGitBackend()->GetWorkingDirectory( this ); } + bool GIT_CONFIG_HANDLER::GetConfigString( const wxString& aKey, wxString& aValue ) { return GetGitBackend()->GetConfigString( this, aKey, aValue ); } + void GIT_CONFIG_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage ) { ReportProgress( aCurrent, aTotal, aMessage ); -} \ No newline at end of file +} diff --git a/common/git/git_init_handler.cpp b/common/git/git_init_handler.cpp index 0309c6c2ef..98fd509867 100644 --- a/common/git/git_init_handler.cpp +++ b/common/git/git_init_handler.cpp @@ -31,25 +31,30 @@ GIT_INIT_HANDLER::GIT_INIT_HANDLER( KIGIT_COMMON* aCommon ) : KIGIT_REPO_MIXIN( aCommon ) {} + GIT_INIT_HANDLER::~GIT_INIT_HANDLER() {} + bool GIT_INIT_HANDLER::IsRepository( const wxString& aPath ) { return GetGitBackend()->IsRepository( this, aPath ); } + InitResult GIT_INIT_HANDLER::InitializeRepository( const wxString& aPath ) { return GetGitBackend()->InitializeRepository( this, aPath ); } + bool GIT_INIT_HANDLER::SetupRemote( const RemoteConfig& aConfig ) { return GetGitBackend()->SetupRemote( this, aConfig ); } + void GIT_INIT_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage ) { ReportProgress( aCurrent, aTotal, aMessage ); -} \ No newline at end of file +} diff --git a/common/git/git_progress.h b/common/git/git_progress.h index cd84b639b6..8c0fc2777f 100644 --- a/common/git/git_progress.h +++ b/common/git/git_progress.h @@ -45,7 +45,6 @@ public: void ReportProgress( int aCurrent, int aTotal, const wxString& aMessage ) { - if( m_progressReporter ) { if( aCurrent == m_previousProgress || aTotal == 0 ) @@ -72,4 +71,4 @@ protected: std::unique_ptr m_progressReporter; }; -#endif // GIT_PROGRESS_H__ \ No newline at end of file +#endif // GIT_PROGRESS_H__ diff --git a/common/git/git_pull_handler.cpp b/common/git/git_pull_handler.cpp index 9520cf985c..68b26e8d4e 100644 --- a/common/git/git_pull_handler.cpp +++ b/common/git/git_pull_handler.cpp @@ -27,25 +27,29 @@ GIT_PULL_HANDLER::GIT_PULL_HANDLER( KIGIT_COMMON* aCommon ) : KIGIT_REPO_MIXIN( aCommon ) {} + GIT_PULL_HANDLER::~GIT_PULL_HANDLER() {} + bool GIT_PULL_HANDLER::PerformFetch( bool aSkipLock ) { return GetGitBackend()->PerformFetch( this, aSkipLock ); } + PullResult GIT_PULL_HANDLER::PerformPull() { return GetGitBackend()->PerformPull( this ); } -const std::vector>>& -GIT_PULL_HANDLER::GetFetchResults() const + +const std::vector>>&GIT_PULL_HANDLER::GetFetchResults() const { return m_fetchResults; } + void GIT_PULL_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage ) { ReportProgress( aCurrent, aTotal, aMessage ); diff --git a/common/git/git_push_handler.cpp b/common/git/git_push_handler.cpp index 41ac3f8c0b..c378a7a7fb 100644 --- a/common/git/git_push_handler.cpp +++ b/common/git/git_push_handler.cpp @@ -28,9 +28,11 @@ GIT_PUSH_HANDLER::GIT_PUSH_HANDLER( KIGIT_COMMON* aRepo ) : KIGIT_REPO_MIXIN( aRepo ) {} + GIT_PUSH_HANDLER::~GIT_PUSH_HANDLER() {} + PushResult GIT_PUSH_HANDLER::PerformPush() { return GetGitBackend()->Push( this ); diff --git a/common/git/git_push_handler.h b/common/git/git_push_handler.h index 0c8bf1f486..a231e39112 100644 --- a/common/git/git_push_handler.h +++ b/common/git/git_push_handler.h @@ -47,12 +47,12 @@ public: PushResult PerformPush(); // Virtual method for progress reporting - virtual void ReportProgress(int aCurrent, int aTotal, const wxString& aMessage) {} + virtual void ReportProgress( int aCurrent, int aTotal, const wxString& aMessage ) {} private: // Implementation of GIT_PROGRESS's virtual method - void UpdateProgress(int aCurrent, int aTotal, const wxString& aMessage) override; + void UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage ) override; }; #endif // _GIT_PUSH_HANDLER_H_ diff --git a/common/git/git_status_handler.cpp b/common/git/git_status_handler.cpp index 3acde10727..00a53c3ac3 100644 --- a/common/git/git_status_handler.cpp +++ b/common/git/git_status_handler.cpp @@ -28,24 +28,29 @@ GIT_STATUS_HANDLER::GIT_STATUS_HANDLER( KIGIT_COMMON* aCommon ) : KIGIT_REPO_MIXIN( aCommon ) {} + GIT_STATUS_HANDLER::~GIT_STATUS_HANDLER() {} + bool GIT_STATUS_HANDLER::HasChangedFiles() { return GetGitBackend()->HasChangedFiles( this ); } + std::map GIT_STATUS_HANDLER::GetFileStatus( const wxString& aPathspec ) { return GetGitBackend()->GetFileStatus( this, aPathspec ); } + wxString GIT_STATUS_HANDLER::GetCurrentBranchName() { return GetGitBackend()->GetCurrentBranchName( this ); } + void GIT_STATUS_HANDLER::UpdateRemoteStatus( const std::set& aLocalChanges, const std::set& aRemoteChanges, std::map& aFileStatus ) @@ -53,11 +58,13 @@ void GIT_STATUS_HANDLER::UpdateRemoteStatus( const std::set& aLocalCha GetGitBackend()->UpdateRemoteStatus( this, aLocalChanges, aRemoteChanges, aFileStatus ); } + wxString GIT_STATUS_HANDLER::GetWorkingDirectory() { return GetGitBackend()->GetWorkingDirectory( this ); } + KIGIT_COMMON::GIT_STATUS GIT_STATUS_HANDLER::ConvertStatus( unsigned int aGitStatus ) { if( aGitStatus & GIT_STATUS_IGNORED ) @@ -86,7 +93,8 @@ KIGIT_COMMON::GIT_STATUS GIT_STATUS_HANDLER::ConvertStatus( unsigned int aGitSta } } + void GIT_STATUS_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage ) { ReportProgress( aCurrent, aTotal, aMessage ); -} \ No newline at end of file +} diff --git a/common/git/kicad_git_common.cpp b/common/git/kicad_git_common.cpp index 8608771653..0381680a0c 100644 --- a/common/git/kicad_git_common.cpp +++ b/common/git/kicad_git_common.cpp @@ -43,6 +43,7 @@ KIGIT_COMMON::KIGIT_COMMON( git_repository* aRepo ) : m_nextPublicKey( 0 ), m_secretFetched( false ) {} + KIGIT_COMMON::KIGIT_COMMON( const KIGIT_COMMON& aOther ) : // Initialize base class and member variables m_repo( aOther.m_repo ), @@ -53,6 +54,7 @@ KIGIT_COMMON::KIGIT_COMMON( const KIGIT_COMMON& aOther ) : m_username( aOther.m_username ), m_password( aOther.m_password ), m_testedTypes( aOther.m_testedTypes ), + // The mutex is default-initialized, not copied m_gitActionMutex(), m_publicKeys( aOther.m_publicKeys ), @@ -61,6 +63,7 @@ KIGIT_COMMON::KIGIT_COMMON( const KIGIT_COMMON& aOther ) : { } + KIGIT_COMMON::~KIGIT_COMMON() {} @@ -587,6 +590,7 @@ wxString KIGIT_COMMON::GetRemotename() const return retval; } + void KIGIT_COMMON::SetSSHKey( const wxString& aKey ) { auto it = std::find( m_publicKeys.begin(), m_publicKeys.end(), aKey ); @@ -706,6 +710,7 @@ void KIGIT_COMMON::UpdateCurrentBranchInfo() updatePublicKeys(); } + KIGIT_COMMON::GIT_CONN_TYPE KIGIT_COMMON::GetConnType() const { wxString remote = m_remote; @@ -726,6 +731,7 @@ KIGIT_COMMON::GIT_CONN_TYPE KIGIT_COMMON::GetConnType() const return GIT_CONN_TYPE::GIT_CONN_LOCAL; } + void KIGIT_COMMON::updateConnectionType() { if( m_remote.StartsWith( "https://" ) || m_remote.StartsWith( "http://" ) ) @@ -769,6 +775,7 @@ void KIGIT_COMMON::updateConnectionType() { // SSH format: git@hostname:path size_t colonPos = m_remote.find( ':' ); + if( colonPos != wxString::npos ) m_hostname = m_remote.Mid( 4, colonPos - 4 ); } @@ -818,7 +825,7 @@ int KIGIT_COMMON::HandleSSHKeyAuthentication( git_cred** aOut, const wxString& a wxLogTrace( traceGit, "Testing %s\n", sshKey ); if( git_credential_ssh_key_new( aOut, aUsername.mbc_str(), sshPubKey.mbc_str(), sshKey.mbc_str(), - password.mbc_str() ) != GIT_OK ) + password.mbc_str() ) != GIT_OK ) { wxLogTrace( traceGit, "Failed to create SSH key credential for %s: %s", aUsername, KIGIT_COMMON::GetLastGitError() ); @@ -839,6 +846,7 @@ int KIGIT_COMMON::HandlePlaintextAuthentication( git_cred** aOut, const wxString return GIT_OK; } + int KIGIT_COMMON::HandleSSHAgentAuthentication( git_cred** aOut, const wxString& aUsername ) { if( git_credential_ssh_key_from_agent( aOut, aUsername.mbc_str() ) != GIT_OK ) @@ -999,6 +1007,7 @@ extern "C" int credentials_cb( git_cred** aOut, const char* aUrl, const char* aU wxString username = parent->GetUsername().Trim().Trim( false ); wxLogTrace( traceGit, "Username credential for %s at %s with allowed type %d", username, aUrl, aAllowedTypes ); + if( git_credential_username_new( aOut, username.ToStdString().c_str() ) != GIT_OK ) { wxLogTrace( traceGit, "Failed to create username credential for %s: %s", @@ -1036,6 +1045,7 @@ extern "C" int credentials_cb( git_cred** aOut, const char* aUrl, const char* aU git_error_clear(); git_error_set_str( GIT_ERROR_NET, _( "Unable to authenticate" ).mbc_str() ); + // Otherwise, we did try something but we failed, so return an authentication error return GIT_EAUTH; } diff --git a/common/git/libgit_backend.cpp b/common/git/libgit_backend.cpp index 08e1cf4a58..2594649f7e 100644 --- a/common/git/libgit_backend.cpp +++ b/common/git/libgit_backend.cpp @@ -61,30 +61,36 @@ static std::string getFirstLineFromCommitMessage( const std::string& aMessage ) return aMessage; } + static std::string getFormattedCommitDate( const git_time& aTime ) { char dateBuffer[64]; time_t time = static_cast( aTime.time ); struct tm timeInfo; + #ifdef _WIN32 localtime_s( &timeInfo, &time ); #else gmtime_r( &time, &timeInfo ); #endif + strftime( dateBuffer, sizeof( dateBuffer ), "%Y-%b-%d %H:%M:%S", &timeInfo ); return dateBuffer; } + void LIBGIT_BACKEND::Init() { git_libgit2_init(); } + void LIBGIT_BACKEND::Shutdown() { git_libgit2_shutdown(); } + bool LIBGIT_BACKEND::IsLibraryAvailable() { #if ( LIBGIT2_VER_MAJOR >= 1 ) || ( LIBGIT2_VER_MINOR >= 99 ) @@ -96,6 +102,7 @@ bool LIBGIT_BACKEND::IsLibraryAvailable() #endif } + bool LIBGIT_BACKEND::Clone( GIT_CLONE_HANDLER* aHandler ) { KIGIT_COMMON* common = aHandler->GetCommon(); @@ -114,7 +121,7 @@ bool LIBGIT_BACKEND::Clone( GIT_CLONE_HANDLER* aHandler ) if( !clonePath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) ) { aHandler->AddErrorString( wxString::Format( _( "Could not create directory '%s'" ), - aHandler->GetClonePath() ) ); + aHandler->GetClonePath() ) ); return false; } } @@ -145,6 +152,7 @@ bool LIBGIT_BACKEND::Clone( GIT_CLONE_HANDLER* aHandler ) return true; } + CommitResult LIBGIT_BACKEND::Commit( GIT_COMMIT_HANDLER* aHandler, const std::vector& aFiles, const wxString& aMessage, @@ -181,7 +189,7 @@ CommitResult LIBGIT_BACKEND::Commit( GIT_COMMIT_HANDLER* aHandler, { aHandler->AddErrorString( wxString::Format( _( "Failed to write index: %s" ), KIGIT_COMMON::GetLastGitError() ) ); - return CommitResult::Error; + return CommitResult::Error; } git_oid tree_id; @@ -190,7 +198,7 @@ CommitResult LIBGIT_BACKEND::Commit( GIT_COMMIT_HANDLER* aHandler, { aHandler->AddErrorString( wxString::Format( _( "Failed to write tree: %s" ), KIGIT_COMMON::GetLastGitError() ) ); - return CommitResult::Error; + return CommitResult::Error; } git_tree* tree = nullptr; @@ -199,7 +207,7 @@ CommitResult LIBGIT_BACKEND::Commit( GIT_COMMIT_HANDLER* aHandler, { aHandler->AddErrorString( wxString::Format( _( "Failed to lookup tree: %s" ), KIGIT_COMMON::GetLastGitError() ) ); - return CommitResult::Error; + return CommitResult::Error; } KIGIT::GitTreePtr treePtr( tree ); @@ -234,13 +242,14 @@ CommitResult LIBGIT_BACKEND::Commit( GIT_COMMIT_HANDLER* aHandler, { aHandler->AddErrorString( wxString::Format( _( "Failed to create author signature: %s" ), KIGIT_COMMON::GetLastGitError() ) ); - return CommitResult::Error; + return CommitResult::Error; } KIGIT::GitSignaturePtr authorPtr( author ); git_oid oid; size_t parentsCount = parent ? 1 : 0; -#if( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR == 8 \ + +#if( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR == 8 \ && ( LIBGIT2_VER_REVISION < 2 || LIBGIT2_VER_REVISION == 3 ) ) git_commit* const parents[1] = { parent }; git_commit** const parentsPtr = parent ? parents : nullptr; @@ -249,27 +258,26 @@ CommitResult LIBGIT_BACKEND::Commit( GIT_COMMIT_HANDLER* aHandler, const git_commit** parentsPtr = parent ? parents : nullptr; #endif - - if( git_commit_create( &oid, repo, "HEAD", author, author, nullptr, aMessage.mb_str(), tree, parentsCount, parentsPtr ) != 0 ) { aHandler->AddErrorString( wxString::Format( _( "Failed to create commit: %s" ), KIGIT_COMMON::GetLastGitError() ) ); - return CommitResult::Error; + return CommitResult::Error; } return CommitResult::Success; } + PushResult LIBGIT_BACKEND::Push( GIT_PUSH_HANDLER* aHandler ) { KIGIT_COMMON* common = aHandler->GetCommon(); std::unique_lock lock( common->m_gitActionMutex, std::try_to_lock ); - if(!lock.owns_lock()) + if( !lock.owns_lock() ) { - wxLogTrace(traceGit, "GIT_PUSH_HANDLER::PerformPush: Could not lock mutex"); + wxLogTrace( traceGit, "GIT_PUSH_HANDLER::PerformPush: Could not lock mutex" ); return PushResult::Error; } @@ -277,16 +285,16 @@ PushResult LIBGIT_BACKEND::Push( GIT_PUSH_HANDLER* aHandler ) git_remote* remote = nullptr; - if(git_remote_lookup(&remote, aHandler->GetRepo(), "origin") != 0) + if( git_remote_lookup( &remote, aHandler->GetRepo(), "origin" ) != 0 ) { - aHandler->AddErrorString(_("Could not lookup remote")); + aHandler->AddErrorString( _( "Could not lookup remote" ) ); return PushResult::Error; } KIGIT::GitRemotePtr remotePtr(remote); git_remote_callbacks remoteCallbacks; - git_remote_init_callbacks(&remoteCallbacks, GIT_REMOTE_CALLBACKS_VERSION); + git_remote_init_callbacks( &remoteCallbacks, GIT_REMOTE_CALLBACKS_VERSION ); remoteCallbacks.sideband_progress = progress_cb; remoteCallbacks.transfer_progress = transfer_progress_cb; remoteCallbacks.update_tips = update_cb; @@ -337,6 +345,7 @@ PushResult LIBGIT_BACKEND::Push( GIT_PUSH_HANDLER* aHandler ) return result; } + bool LIBGIT_BACKEND::HasChangedFiles( GIT_STATUS_HANDLER* aHandler ) { git_repository* repo = aHandler->GetRepo(); @@ -365,6 +374,7 @@ bool LIBGIT_BACKEND::HasChangedFiles( GIT_STATUS_HANDLER* aHandler ) return hasChanges; } + std::map LIBGIT_BACKEND::GetFileStatus( GIT_STATUS_HANDLER* aHandler, const wxString& aPathspec ) { @@ -411,12 +421,15 @@ std::map LIBGIT_BACKEND::GetFileStatus( GIT_STATUS_HANDLER : entry->index_to_workdir->old_file.path ); wxString absPath = repoWorkDir + path; - fileStatusMap[absPath] = FileStatus{ absPath, aHandler->ConvertStatus( entry->status ), static_cast( entry->status ) }; + fileStatusMap[absPath] = FileStatus{ absPath, + aHandler->ConvertStatus( entry->status ), + static_cast( entry->status ) }; } return fileStatusMap; } + wxString LIBGIT_BACKEND::GetCurrentBranchName( GIT_STATUS_HANDLER* aHandler ) { git_repository* repo = aHandler->GetRepo(); @@ -443,6 +456,7 @@ wxString LIBGIT_BACKEND::GetCurrentBranchName( GIT_STATUS_HANDLER* aHandler ) } } + void LIBGIT_BACKEND::UpdateRemoteStatus( GIT_STATUS_HANDLER* aHandler, const std::set& aLocalChanges, const std::set& aRemoteChanges, @@ -461,6 +475,7 @@ void LIBGIT_BACKEND::UpdateRemoteStatus( GIT_STATUS_HANDLER* aHandler, if( relativePath.StartsWith( repoWorkDir ) ) { relativePath = relativePath.Mid( repoWorkDir.length() ); + #ifdef _WIN32 relativePath.Replace( wxS( "\\" ), wxS( "/" ) ); #endif @@ -482,18 +497,20 @@ void LIBGIT_BACKEND::UpdateRemoteStatus( GIT_STATUS_HANDLER* aHandler, } } + wxString LIBGIT_BACKEND::GetWorkingDirectory( GIT_STATUS_HANDLER* aHandler ) { return aHandler->GetProjectDir(); } + wxString LIBGIT_BACKEND::GetWorkingDirectory( GIT_CONFIG_HANDLER* aHandler ) { return aHandler->GetProjectDir(); } -bool LIBGIT_BACKEND::GetConfigString( GIT_CONFIG_HANDLER* aHandler, const wxString& aKey, - wxString& aValue ) + +bool LIBGIT_BACKEND::GetConfigString( GIT_CONFIG_HANDLER* aHandler, const wxString& aKey, wxString& aValue ) { git_repository* repo = aHandler->GetRepo(); @@ -524,6 +541,7 @@ bool LIBGIT_BACKEND::GetConfigString( GIT_CONFIG_HANDLER* aHandler, const wxStri return true; } + bool LIBGIT_BACKEND::IsRepository( GIT_INIT_HANDLER* aHandler, const wxString& aPath ) { git_repository* repo = nullptr; @@ -538,6 +556,7 @@ bool LIBGIT_BACKEND::IsRepository( GIT_INIT_HANDLER* aHandler, const wxString& a return false; } + InitResult LIBGIT_BACKEND::InitializeRepository( GIT_INIT_HANDLER* aHandler, const wxString& aPath ) { if( IsRepository( aHandler, aPath ) ) @@ -563,6 +582,7 @@ InitResult LIBGIT_BACKEND::InitializeRepository( GIT_INIT_HANDLER* aHandler, con return InitResult::Success; } + bool LIBGIT_BACKEND::SetupRemote( GIT_INIT_HANDLER* aHandler, const RemoteConfig& aConfig ) { if( aConfig.url.IsEmpty() ) @@ -605,6 +625,7 @@ bool LIBGIT_BACKEND::SetupRemote( GIT_INIT_HANDLER* aHandler, const RemoteConfig } wxString bareURL = aConfig.url; + if( bareURL.StartsWith( "https://" ) ) bareURL = bareURL.Mid( 8 ); else if( bareURL.StartsWith( "http://" ) ) @@ -634,6 +655,7 @@ bool LIBGIT_BACKEND::SetupRemote( GIT_INIT_HANDLER* aHandler, const RemoteConfig return true; } + static bool lookup_branch_reference( git_repository* repo, const wxString& aBranchName, git_reference** aReference ) { @@ -646,6 +668,7 @@ static bool lookup_branch_reference( git_repository* repo, const wxString& aBran return false; } + BranchResult LIBGIT_BACKEND::SwitchToBranch( GIT_BRANCH_HANDLER* aHandler, const wxString& aBranchName ) { git_repository* repo = aHandler->GetRepo(); @@ -661,7 +684,7 @@ BranchResult LIBGIT_BACKEND::SwitchToBranch( GIT_BRANCH_HANDLER* aHandler, const if( !lookup_branch_reference( repo, aBranchName, &branchRef ) ) { aHandler->AddErrorString( wxString::Format( _( "Failed to lookup branch '%s': %s" ), - aBranchName, KIGIT_COMMON::GetLastGitError() ) ); + aBranchName, KIGIT_COMMON::GetLastGitError() ) ); return BranchResult::BranchNotFound; } @@ -696,6 +719,7 @@ BranchResult LIBGIT_BACKEND::SwitchToBranch( GIT_BRANCH_HANDLER* aHandler, const return BranchResult::Success; } + bool LIBGIT_BACKEND::BranchExists( GIT_BRANCH_HANDLER* aHandler, const wxString& aBranchName ) { git_repository* repo = aHandler->GetRepo(); @@ -712,6 +736,7 @@ bool LIBGIT_BACKEND::BranchExists( GIT_BRANCH_HANDLER* aHandler, const wxString& return exists; } + // Use callbacks declared/implemented in kicad_git_common.h/.cpp bool LIBGIT_BACKEND::PerformFetch( GIT_PULL_HANDLER* aHandler, bool aSkipLock ) @@ -756,7 +781,8 @@ bool LIBGIT_BACKEND::PerformFetch( GIT_PULL_HANDLER* aHandler, bool aSkipLock ) { wxString errorMsg = KIGIT_COMMON::GetLastGitError(); wxLogTrace( traceGit, "GIT_PULL_HANDLER::PerformFetch() - Failed to connect to remote: %s", errorMsg ); - aHandler->AddErrorString( wxString::Format( _( "Could not connect to remote '%s': %s" ), "origin", errorMsg ) ); + aHandler->AddErrorString( wxString::Format( _( "Could not connect to remote '%s': %s" ), "origin", + errorMsg ) ); return false; } @@ -768,7 +794,8 @@ bool LIBGIT_BACKEND::PerformFetch( GIT_PULL_HANDLER* aHandler, bool aSkipLock ) { wxString errorMsg = KIGIT_COMMON::GetLastGitError(); wxLogTrace( traceGit, "GIT_PULL_HANDLER::PerformFetch() - Failed to fetch from remote: %s", errorMsg ); - aHandler->AddErrorString( wxString::Format( _( "Could not fetch data from remote '%s': %s" ), "origin", errorMsg ) ); + aHandler->AddErrorString( wxString::Format( _( "Could not fetch data from remote '%s': %s" ), "origin", + errorMsg ) ); return false; } @@ -776,6 +803,7 @@ bool LIBGIT_BACKEND::PerformFetch( GIT_PULL_HANDLER* aHandler, bool aSkipLock ) return true; } + PullResult LIBGIT_BACKEND::PerformPull( GIT_PULL_HANDLER* aHandler ) { PullResult result = PullResult::Success; @@ -792,8 +820,7 @@ PullResult LIBGIT_BACKEND::PerformPull( GIT_PULL_HANDLER* aHandler ) git_oid pull_merge_oid = {}; - if( git_repository_fetchhead_foreach( aHandler->GetRepo(), fetchhead_foreach_cb, - &pull_merge_oid ) ) + if( git_repository_fetchhead_foreach( aHandler->GetRepo(), fetchhead_foreach_cb, &pull_merge_oid ) ) { aHandler->AddErrorString( _( "Could not read 'FETCH_HEAD'" ) ); return PullResult::Error; @@ -869,6 +896,7 @@ PullResult LIBGIT_BACKEND::PerformPull( GIT_PULL_HANDLER* aHandler ) return result; } + PullResult LIBGIT_BACKEND::handleFastForward( GIT_PULL_HANDLER* aHandler ) { git_reference* rawRef = nullptr; @@ -890,7 +918,7 @@ PullResult LIBGIT_BACKEND::handleFastForward( GIT_PULL_HANDLER* aHandler ) if( git_reference_name_to_id( &updatedRefOid, aHandler->GetRepo(), remoteBranchName.c_str() ) != GIT_OK ) { aHandler->AddErrorString( wxString::Format( _( "Could not get reference OID for reference '%s'" ), - remoteBranchName ) ); + remoteBranchName ) ); return PullResult::Error; } @@ -948,7 +976,8 @@ PullResult LIBGIT_BACKEND::handleFastForward( GIT_PULL_HANDLER* aHandler ) checkoutOptions.notify_flags = GIT_CHECKOUT_NOTIFY_ALL; checkoutOptions.notify_cb = notify_cb; - if( git_checkout_tree( aHandler->GetRepo(), reinterpret_cast( targetTree ), &checkoutOptions ) != GIT_OK ) + if( git_checkout_tree( aHandler->GetRepo(), reinterpret_cast( targetTree ), + &checkoutOptions ) != GIT_OK ) { aHandler->AddErrorString( _( "Failed to perform checkout operation." ) ); return PullResult::Error; @@ -959,7 +988,7 @@ PullResult LIBGIT_BACKEND::handleFastForward( GIT_PULL_HANDLER* aHandler ) if( git_reference_set_target( &updatedRef, rawRef, &updatedRefOid, nullptr ) != GIT_OK ) { aHandler->AddErrorString( wxString::Format( _( "Failed to update reference '%s' to point to '%s'" ), - currentBranchName, git_oid_tostr_s( &updatedRefOid ) ) ); + currentBranchName, git_oid_tostr_s( &updatedRefOid ) ) ); return PullResult::Error; } @@ -1018,6 +1047,7 @@ PullResult LIBGIT_BACKEND::handleFastForward( GIT_PULL_HANDLER* aHandler ) return PullResult::FastForward; } + bool LIBGIT_BACKEND::hasUnstagedChanges( git_repository* aRepo ) { if( !aRepo ) @@ -1056,6 +1086,7 @@ bool LIBGIT_BACKEND::hasUnstagedChanges( git_repository* aRepo ) return false; } + PullResult LIBGIT_BACKEND::handleMerge( GIT_PULL_HANDLER* aHandler, const git_annotated_commit** aMergeHeads, size_t aMergeHeadsCount ) @@ -1079,6 +1110,7 @@ PullResult LIBGIT_BACKEND::handleMerge( GIT_PULL_HANDLER* aHandler, return PullResult::Success; } + PullResult LIBGIT_BACKEND::handleRebase( GIT_PULL_HANDLER* aHandler, const git_annotated_commit** aMergeHeads, size_t aMergeHeadsCount ) @@ -1131,6 +1163,7 @@ PullResult LIBGIT_BACKEND::handleRebase( GIT_PULL_HANDLER* aHandler, return PullResult::Success; } + void LIBGIT_BACKEND::PerformRevert( GIT_REVERT_HANDLER* aHandler ) { git_object* head_commit = NULL; @@ -1175,6 +1208,7 @@ void LIBGIT_BACKEND::PerformRevert( GIT_REVERT_HANDLER* aHandler ) git_object_free( head_commit ); } + git_repository* LIBGIT_BACKEND::GetRepositoryForFile( const char* aFilename ) { git_repository* repo = nullptr; @@ -1199,6 +1233,7 @@ git_repository* LIBGIT_BACKEND::GetRepositoryForFile( const char* aFilename ) return repo; } + int LIBGIT_BACKEND::CreateBranch( git_repository* aRepo, const wxString& aBranchName ) { git_oid head_oid; @@ -1233,6 +1268,7 @@ int LIBGIT_BACKEND::CreateBranch( git_repository* aRepo, const wxString& aBranch return 0; } + bool LIBGIT_BACKEND::RemoveVCS( git_repository*& aRepo, const wxString& aProjectPath, bool aRemoveGitDir, wxString* aErrors ) { @@ -1250,6 +1286,7 @@ bool LIBGIT_BACKEND::RemoveVCS( git_repository*& aRepo, const wxString& aProject if( gitDir.DirExists() ) { wxString errors; + if( !RmDirRecursive( gitDir.GetPath(), &errors ) ) { if( aErrors ) @@ -1265,6 +1302,7 @@ bool LIBGIT_BACKEND::RemoveVCS( git_repository*& aRepo, const wxString& aProject return true; } + bool LIBGIT_BACKEND::AddToIndex( GIT_ADD_TO_INDEX_HANDLER* aHandler, const wxString& aFilePath ) { git_repository* repo = aHandler->GetRepo(); @@ -1290,6 +1328,7 @@ bool LIBGIT_BACKEND::AddToIndex( GIT_ADD_TO_INDEX_HANDLER* aHandler, const wxStr return true; } + bool LIBGIT_BACKEND::PerformAddToIndex( GIT_ADD_TO_INDEX_HANDLER* aHandler ) { git_repository* repo = aHandler->GetRepo(); @@ -1329,8 +1368,8 @@ bool LIBGIT_BACKEND::PerformAddToIndex( GIT_ADD_TO_INDEX_HANDLER* aHandler ) return true; } -bool LIBGIT_BACKEND::RemoveFromIndex( GIT_REMOVE_FROM_INDEX_HANDLER* aHandler, - const wxString& aFilePath ) + +bool LIBGIT_BACKEND::RemoveFromIndex( GIT_REMOVE_FROM_INDEX_HANDLER* aHandler, const wxString& aFilePath ) { git_repository* repo = aHandler->GetRepo(); git_index* index = nullptr; @@ -1354,6 +1393,7 @@ bool LIBGIT_BACKEND::RemoveFromIndex( GIT_REMOVE_FROM_INDEX_HANDLER* aHandler, return true; } + void LIBGIT_BACKEND::PerformRemoveFromIndex( GIT_REMOVE_FROM_INDEX_HANDLER* aHandler ) { git_repository* repo = aHandler->GetRepo(); diff --git a/common/git/project_git_utils.cpp b/common/git/project_git_utils.cpp index 263815b058..974ab1b4bd 100644 --- a/common/git/project_git_utils.cpp +++ b/common/git/project_git_utils.cpp @@ -41,17 +41,20 @@ git_repository* PROJECT_GIT_UTILS::GetRepositoryForFile( const char* aFilename ) return GetGitBackend()->GetRepositoryForFile( aFilename ); } + int PROJECT_GIT_UTILS::CreateBranch( git_repository* aRepo, const wxString& aBranchName ) { return GetGitBackend()->CreateBranch( aRepo, aBranchName ); } + bool PROJECT_GIT_UTILS::RemoveVCS( git_repository*& aRepo, const wxString& aProjectPath, - bool aRemoveGitDir, wxString* aErrors ) + bool aRemoveGitDir, wxString* aErrors ) { return GetGitBackend()->RemoveVCS( aRepo, aProjectPath, aRemoveGitDir, aErrors ); } + wxString PROJECT_GIT_UTILS::GetCurrentHash( const wxString& aProjectFile, bool aShort ) { wxString result = wxT( "no hash" ); @@ -61,7 +64,7 @@ wxString PROJECT_GIT_UTILS::GetCurrentHash( const wxString& aProjectFile, bool a { git_reference* head = nullptr; - if( git_repository_head( &head, repo ) == 0 ) + if( git_repository_head( &head, repo ) == 0 ) { const git_oid* oid = git_reference_target( head ); diff --git a/common/git/project_git_utils.h b/common/git/project_git_utils.h index 16fa39f969..c5b7956a45 100644 --- a/common/git/project_git_utils.h +++ b/common/git/project_git_utils.h @@ -72,8 +72,8 @@ public: * @param aErrors Output parameter for any error messages * @return True on success, false on failure */ -static bool RemoveVCS( git_repository*& aRepo, const wxString& aProjectPath = wxEmptyString, - bool aRemoveGitDir = false, wxString* aErrors = nullptr ); + static bool RemoveVCS( git_repository*& aRepo, const wxString& aProjectPath = wxEmptyString, + bool aRemoveGitDir = false, wxString* aErrors = nullptr ); /** * Compute a working directory path that preserves symlinks from the user's project path. @@ -94,4 +94,4 @@ static bool RemoveVCS( git_repository*& aRepo, const wxString& aProjectPath = wx } // namespace KIGIT -#endif // PROJECT_GIT_UTILS_H \ No newline at end of file +#endif // PROJECT_GIT_UTILS_H