Lazy load git credentials when needed

Prevents querying SecretStore on boot

Fixes https://gitlab.com/kicad/code/kicad/issues/20176

(cherry picked from commit 4ed56d87a4)
This commit is contained in:
Seth Hillbrand
2025-10-05 04:32:21 -07:00
parent d189c6ddbf
commit 1d577cf917
2 changed files with 34 additions and 8 deletions
+28 -5
View File
@@ -40,7 +40,7 @@
KIGIT_COMMON::KIGIT_COMMON( git_repository* aRepo ) :
m_repo( aRepo ), m_connType( GIT_CONN_TYPE::GIT_CONN_LOCAL ), m_testedTypes( 0 ),
m_nextPublicKey( 0 )
m_nextPublicKey( 0 ), m_secretFetched( false )
{}
KIGIT_COMMON::KIGIT_COMMON( const KIGIT_COMMON& aOther ) :
@@ -55,7 +55,8 @@ KIGIT_COMMON::KIGIT_COMMON( const KIGIT_COMMON& aOther ) :
// The mutex is default-initialized, not copied
m_gitActionMutex(),
m_publicKeys( aOther.m_publicKeys ),
m_nextPublicKey( aOther.m_nextPublicKey )
m_nextPublicKey( aOther.m_nextPublicKey ),
m_secretFetched( aOther.m_secretFetched )
{
}
@@ -100,6 +101,25 @@ wxString KIGIT_COMMON::GetCurrentBranchName() const
}
wxString KIGIT_COMMON::GetPassword()
{
if( !m_secretFetched )
{
if( m_connType != GIT_CONN_TYPE::GIT_CONN_LOCAL && !m_remote.IsEmpty() )
{
wxString secret;
if( KIPLATFORM::SECRETS::GetSecret( m_remote, m_username, secret ) )
m_password = secret;
}
m_secretFetched = true;
}
return m_password;
}
std::vector<wxString> KIGIT_COMMON::GetBranchNames() const
{
if( !m_repo )
@@ -645,6 +665,10 @@ void KIGIT_COMMON::UpdateCurrentBranchInfo()
wxString remote_name = GetRemotename();
git_remote* remote = nullptr;
m_remote.clear();
m_password.clear();
m_secretFetched = false;
if( git_remote_lookup( &remote, m_repo, remote_name.ToStdString().c_str() ) == GIT_OK )
{
const char* url = git_remote_url( remote );
@@ -655,9 +679,6 @@ void KIGIT_COMMON::UpdateCurrentBranchInfo()
git_remote_free( remote );
}
// Find the stored password if it exists
KIPLATFORM::SECRETS::GetSecret( m_remote, m_username, m_password );
updateConnectionType();
updatePublicKeys();
}
@@ -748,6 +769,8 @@ void KIGIT_COMMON::updateConnectionType()
m_hostname = host;
}
}
m_secretFetched = !m_password.IsEmpty();
}
+6 -3
View File
@@ -89,11 +89,11 @@ public:
};
wxString GetUsername() const { return m_username; }
wxString GetPassword() const { return m_password; }
wxString GetPassword();
GIT_CONN_TYPE GetConnType() const;
void SetUsername( const wxString& aUsername ) { m_username = aUsername; }
void SetPassword( const wxString& aPassword ) { m_password = aPassword; }
void SetUsername( const wxString& aUsername ) { m_username = aUsername; m_secretFetched = false; }
void SetPassword( const wxString& aPassword ) { m_password = aPassword; m_secretFetched = true; }
void SetSSHKey( const wxString& aSSHKey );
// Holds a temporary variable that can be used by the authentication callback
@@ -127,6 +127,8 @@ public:
void SetRemote( const wxString& aRemote )
{
m_remote = aRemote;
m_password.clear();
m_secretFetched = false;
updateConnectionType();
}
@@ -170,6 +172,7 @@ private:
std::vector<wxString> m_publicKeys;
int m_nextPublicKey;
bool m_secretFetched;
// Create a dummy flag to tell if we have tested ssh agent credentials separately
// from the ssh key credentials