Code cleanup and compiler warnings.

(cherry picked from commit 51848a0b43)
This commit is contained in:
Jeff Young 2024-02-22 10:38:54 +00:00 committed by Roberto Fernandez Bautista
parent 98cd040952
commit 4a561b04bc
5 changed files with 78 additions and 71 deletions

View File

@ -37,9 +37,15 @@
#include <wx/stdpaths.h>
DIALOG_GIT_REPOSITORY::DIALOG_GIT_REPOSITORY( wxWindow* aParent, git_repository* aRepository, wxString aURL ) :
DIALOG_GIT_REPOSITORY_BASE( aParent ), m_repository( aRepository ), m_prevFile( wxEmptyString ),
m_tested( 0 ), m_failedTest( false ), m_testError( wxEmptyString ), m_tempRepo( false ),
DIALOG_GIT_REPOSITORY::DIALOG_GIT_REPOSITORY( wxWindow* aParent, git_repository* aRepository,
wxString aURL ) :
DIALOG_GIT_REPOSITORY_BASE( aParent ),
m_repository( aRepository ),
m_prevFile( wxEmptyString ),
m_tested( 0 ),
m_failedTest( false ),
m_testError( wxEmptyString ),
m_tempRepo( false ),
m_repoType( KIGIT_COMMON::GIT_CONN_TYPE::GIT_CONN_LOCAL )
{
m_txtURL->SetFocus();
@ -50,7 +56,8 @@ DIALOG_GIT_REPOSITORY::DIALOG_GIT_REPOSITORY( wxWindow* aParent, git_repository*
m_tempRepo = true;
m_tempPath = wxFileName::CreateTempFileName( "kicadtestrepo" );
git_repository_init_options options = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_repository_init_options options;
options.version = GIT_REPOSITORY_INIT_OPTIONS_VERSION;
options.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_NO_REINIT;
git_repository_init_ext( &m_repository, m_tempPath.ToStdString().c_str(), &options );
}
@ -90,7 +97,9 @@ bool DIALOG_GIT_REPOSITORY::extractClipboardData()
{
if( std::get<0>( isValidHTTPS( clipboardText ) )
|| std::get<0>( isValidSSH( clipboardText ) ) )
{
m_txtURL->SetValue( clipboardText );
}
}
wxTheClipboard->Close();
@ -252,7 +261,8 @@ void DIALOG_GIT_REPOSITORY::updateURLData()
void DIALOG_GIT_REPOSITORY::OnTestClick( wxCommandEvent& event )
{
git_remote* remote = nullptr;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
git_remote_callbacks callbacks;
callbacks.version = GIT_REMOTE_CALLBACKS_VERSION;
// We track if we have already tried to connect.
// If we have, the server may come back to offer another connection
@ -362,7 +372,8 @@ void DIALOG_GIT_REPOSITORY::OnFileUpdated( wxFileDirPickerEvent& aEvent )
if( !isValid )
{
DisplayErrorMessage( this, _( "Invalid SSH Key" ), _( "The selected file is not a valid SSH private key" ) );
DisplayErrorMessage( this, _( "Invalid SSH Key" ),
_( "The selected file is not a valid SSH private key" ) );
CallAfter( [this] { SetRepoSSHPath( m_prevFile ); } );
return;
}
@ -386,7 +397,8 @@ void DIALOG_GIT_REPOSITORY::OnFileUpdated( wxFileDirPickerEvent& aEvent )
if( !pubIfs.good() || !pubIfs.is_open() )
{
DisplayErrorMessage( this, wxString::Format( _( "Could not open public key '%s'" ), file + ".pub" ),
DisplayErrorMessage( this, wxString::Format( _( "Could not open public key '%s'" ),
file + ".pub" ),
wxString::Format( "%s: %d", std::strerror( errno ), errno ) );
aEvent.SetPath( wxEmptyString );
CallAfter( [this] { SetRepoSSHPath( m_prevFile ); } );
@ -404,19 +416,22 @@ void DIALOG_GIT_REPOSITORY::OnOKClick( wxCommandEvent& event )
if( m_txtName->GetValue().IsEmpty() )
{
DisplayErrorMessage( this, _( "Missing information" ), _( "Please enter a name for the repository" ) );
DisplayErrorMessage( this, _( "Missing information" ),
_( "Please enter a name for the repository" ) );
return;
}
if( m_txtURL->GetValue().IsEmpty() )
{
DisplayErrorMessage( this, _( "Missing information" ), _( "Please enter a URL for the repository" ) );
DisplayErrorMessage( this, _( "Missing information" ),
_( "Please enter a URL for the repository" ) );
return;
}
EndModal( wxID_OK );
}
void DIALOG_GIT_REPOSITORY::updateAuthControls()
{
if( m_ConnType->GetSelection() == static_cast<int>( KIGIT_COMMON::GIT_CONN_TYPE::GIT_CONN_LOCAL ) )

View File

@ -32,7 +32,8 @@
class DIALOG_GIT_REPOSITORY : public DIALOG_GIT_REPOSITORY_BASE
{
public:
DIALOG_GIT_REPOSITORY( wxWindow* aParent, git_repository* aRepository, wxString aURL = wxEmptyString );
DIALOG_GIT_REPOSITORY( wxWindow* aParent, git_repository* aRepository,
wxString aURL = wxEmptyString );
~DIALOG_GIT_REPOSITORY() override;
void SetTestResult( bool aFailed, const wxString& aError )
@ -47,7 +48,10 @@ public:
updateAuthControls();
}
KIGIT_COMMON::GIT_CONN_TYPE GetRepoType() const { return static_cast<KIGIT_COMMON::GIT_CONN_TYPE>( m_ConnType->GetSelection() ); }
KIGIT_COMMON::GIT_CONN_TYPE GetRepoType() const
{
return static_cast<KIGIT_COMMON::GIT_CONN_TYPE>( m_ConnType->GetSelection() );
}
void SetRepoName( const wxString& aName ) { m_txtName->SetValue( aName ); }
wxString GetRepoName() const { return m_txtName->GetValue(); }
@ -106,19 +110,19 @@ private:
std::tuple<bool,wxString,wxString,wxString> isValidHTTPS( const wxString& url );
std::tuple<bool,wxString, wxString> isValidSSH( const wxString& url );
private:
git_repository* m_repository;
wxString m_prevFile;
wxString m_prevFile;
unsigned m_tested;
bool m_failedTest;
wxString m_testError;
unsigned m_tested;
bool m_failedTest;
wxString m_testError;
bool m_tempRepo;
wxString m_tempPath;
bool m_tempRepo;
wxString m_tempPath;
KIGIT_COMMON::GIT_CONN_TYPE m_repoType;
};
#endif /* DIALOG_GIT_REPOSITORY_H_ */

View File

@ -55,7 +55,7 @@ void PANEL_GIT_REPOS::ResetPanel()
m_authorEmail->SetValue( wxEmptyString );
}
static std::pair<wxString, wxString> getDefaultAuthorEmail()
static std::pair<wxString, wxString> getDefaultAuthorAndEmail()
{
wxString name;
wxString email;
@ -94,8 +94,8 @@ static std::pair<wxString, wxString> getDefaultAuthorEmail()
bool PANEL_GIT_REPOS::TransferDataFromWindow()
{
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
auto& repos = settings->m_Git.repositories;
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
std::vector<COMMON_SETTINGS::GIT_REPOSITORY>& repos = settings->m_Git.repositories;
repos.clear();
@ -109,7 +109,8 @@ bool PANEL_GIT_REPOS::TransferDataFromWindow()
repo.authType = m_grid->GetCellValue( row, COL_AUTH_TYPE );
repo.username = m_grid->GetCellValue( row, COL_USERNAME );
KIPLATFORM::SECRETS::StoreSecret( repo.path, repo.username, m_grid->GetCellValue( row, COL_PASSWORD ) );
KIPLATFORM::SECRETS::StoreSecret( repo.path, repo.username,
m_grid->GetCellValue( row, COL_PASSWORD ) );
repo.ssh_path = m_grid->GetCellValue( row, COL_SSH_PATH );
repo.checkValid = m_grid->GetCellValue( row, COL_STATUS ) == "1";
repos.push_back( repo );
@ -126,7 +127,8 @@ static bool testRepositoryConnection( COMMON_SETTINGS::GIT_REPOSITORY& repositor
{
git_libgit2_init();
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
git_remote_callbacks callbacks;
callbacks.version = GIT_REMOTE_CALLBACKS_VERSION;
typedef struct
{
@ -134,35 +136,39 @@ static bool testRepositoryConnection( COMMON_SETTINGS::GIT_REPOSITORY& repositor
bool success;
} callbacksPayload;
callbacksPayload cb_data( { &repository, true } ); // If we don't need authentication, then, we are successful
callbacksPayload cb_data( { &repository, true } ); // If we don't need authentication, then,
// we are successful
callbacks.payload = &cb_data;
callbacks.credentials = [](git_cred** out, const char* url, const char* username, unsigned int allowed_types, void* payload) -> int {
callbacks.credentials =
[](git_cred** out, const char* url, const char* username, unsigned int allowed_types,
void* payload) -> int
{
// If we are asking for credentials, then, we need authentication
// If we are asking for credentials, then, we need authentication
callbacksPayload* data = static_cast<callbacksPayload*>(payload);
callbacksPayload* data = static_cast<callbacksPayload*>(payload);
data->success = false;
data->success = false;
if( allowed_types & GIT_CREDTYPE_USERNAME )
{
data->success = true;
}
else if( data->repo->authType == "ssh" && ( allowed_types & GIT_CREDTYPE_SSH_KEY ) )
{
wxString sshKeyPath = data->repo->ssh_path;
if( allowed_types & GIT_CREDTYPE_USERNAME )
{
data->success = true;
}
else if( data->repo->authType == "ssh" && ( allowed_types & GIT_CREDTYPE_SSH_KEY ) )
{
wxString sshKeyPath = data->repo->ssh_path;
// Check if the SSH key exists and is readable
if( wxFileExists( sshKeyPath ) && wxFile::Access( sshKeyPath, wxFile::read ) )
data->success = true;
}
else if( data->repo->authType == "password" )
{
data->success = ( allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT );
}
// Check if the SSH key exists and is readable
if( wxFileExists( sshKeyPath ) && wxFile::Access( sshKeyPath, wxFile::read ) )
data->success = true;
}
else if( data->repo->authType == "password" )
{
data->success = ( allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT );
}
return 0;
};
return 0;
};
// Create a temporary directory to initialize the Git repository
wxString tempDirPath = wxFileName::CreateTempFileName(wxT("kigit_temp"));
@ -177,9 +183,10 @@ static bool testRepositoryConnection( COMMON_SETTINGS::GIT_REPOSITORY& repositor
// Initialize the Git repository
git_repository* repo = nullptr;
int result = git_repository_init(&repo, tempDirPath.mb_str(wxConvUTF8), 0);
int result = git_repository_init( &repo, tempDirPath.mb_str( wxConvUTF8 ), 0 );
if (result != 0) {
if (result != 0)
{
git_repository_free(repo);
git_libgit2_shutdown();
wxRmdir(tempDirPath);
@ -187,8 +194,10 @@ static bool testRepositoryConnection( COMMON_SETTINGS::GIT_REPOSITORY& repositor
}
git_remote* remote = nullptr;
result = git_remote_create_anonymous(&remote, repo, tempDirPath.mb_str(wxConvUTF8));
if (result != 0) {
result = git_remote_create_anonymous( &remote, repo, tempDirPath.mb_str( wxConvUTF8 ) );
if (result != 0)
{
git_remote_free(remote);
git_repository_free(repo);
git_libgit2_shutdown();
@ -249,7 +258,7 @@ bool PANEL_GIT_REPOS::TransferDataToWindow()
if( settings->m_Git.useDefaultAuthor )
{
auto defaultAuthor = getDefaultAuthorEmail();
std::pair<wxString, wxString> defaultAuthor = getDefaultAuthorAndEmail();
m_author->SetValue( defaultAuthor.first );
m_authorEmail->SetValue( defaultAuthor.second );
m_author->Disable();

View File

@ -1955,16 +1955,6 @@ static struct EDA_SHAPE_DESC
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
REGISTER_TYPE( EDA_SHAPE );
auto isNotPolygon =
[]( INSPECTABLE* aItem ) -> bool
{
// Polygons, unlike other shapes, have no meaningful start or end coordinates
if( EDA_SHAPE* shape = dynamic_cast<EDA_SHAPE*>( aItem ) )
return shape->GetShape() != SHAPE_T::POLY;
return false;
};
auto isNotPolygonOrCircle = []( INSPECTABLE* aItem ) -> bool
{
// Polygons, unlike other shapes, have no meaningful start or end coordinates

View File

@ -89,17 +89,6 @@ const std::map<GRAPHIC_PINSHAPE, struct pinShapeStruct> pinShapes = {
// clang-format on
// bitmaps to show pins orientations in dialog editor
// must have same order than pin_orientation_names
static const BITMAPS iconsPinsOrientations[] =
{
BITMAPS::pinorient_right,
BITMAPS::pinorient_left,
BITMAPS::pinorient_up,
BITMAPS::pinorient_down,
};
// clang-format off
std::map<PIN_ORIENTATION, struct pinShapeStruct> pinOrientations = {
{ PIN_ORIENTATION::PIN_RIGHT, { _( "Right" ), BITMAPS::pinorient_right } },