29 git_config_entry* entry =
nullptr;
30 int result = git_config_get_entry( &entry, aConfig, aKey );
33 if(
result != GIT_OK || !entry )
36 aValue = wxString::FromUTF8( entry->value );
48 git_config*
config =
nullptr;
51 if( ( aRepo ? git_repository_config( &
config, aRepo ) : git_config_open_default( &
config ) ) != GIT_OK )
56 auto readLevel = []( git_config* aAll, git_config_level_t aLevel,
GitUserConfig& aOut )
58 git_config* level =
nullptr;
60 if( git_config_open_level( &level, aAll, aLevel ) != GIT_OK )
66 if( aOut.authorName.IsEmpty() &&
ReadConfigString( level,
"user.name", value ) )
67 aOut.authorName = value;
69 if( aOut.authorEmail.IsEmpty() &&
ReadConfigString( level,
"user.email", value ) )
70 aOut.authorEmail = value;
72 aOut.hasName = !aOut.authorName.IsEmpty();
73 aOut.hasEmail = !aOut.authorEmail.IsEmpty();
76 readLevel(
config, GIT_CONFIG_LEVEL_LOCAL, aLocal );
78 for( git_config_level_t level : { GIT_CONFIG_LEVEL_GLOBAL, GIT_CONFIG_LEVEL_XDG, GIT_CONFIG_LEVEL_SYSTEM,
79 GIT_CONFIG_LEVEL_PROGRAMDATA } )
81 readLevel(
config, level, aGlobal );
88 const wxString& aAccountEmail )
90 auto firstSet = []( std::initializer_list<const wxString*> aCandidates ) -> wxString
92 for(
const wxString* candidate : aCandidates )
94 if( !candidate->IsEmpty() )
101 const wxString noValue;
APIEXPORT bool ReadConfigString(git_config *aConfig, const char *aKey, wxString &aValue)
Read a git config value, decoded as UTF-8.
APIEXPORT void ReadAuthorConfig(git_repository *aRepo, GitUserConfig &aLocal, GitUserConfig &aGlobal)
Read the author set in a repository's own config and the one set in the global, XDG or system config.
APIEXPORT GitUserConfig ResolveAuthor(const COMMON_SETTINGS::GIT &aPrefs, const GitUserConfig &aLocal, const GitUserConfig &aGlobal, const wxString &aAccountName=wxEmptyString, const wxString &aAccountEmail=wxEmptyString)
Resolve the author recorded for new commits.
std::unique_ptr< git_config, decltype([](git_config *aConfig) { git_config_free(aConfig); })> GitConfigPtr
A unique pointer for git_config objects with automatic cleanup.
std::unique_ptr< git_config_entry, decltype([](git_config_entry *aEntry) { git_config_entry_free(aEntry); })> GitConfigEntryPtr
A unique pointer for git_config_entry objects with automatic cleanup.
APIEXPORT bool AuthorPreferenceChanged(const COMMON_SETTINGS::GIT &aBefore, const COMMON_SETTINGS::GIT &aAfter)
Whether aAfter changes the author ResolveAuthor gives against aBefore.
Holds libgit2 initialized while it lives, for a helper that can run before any git backend exists.
wxString result
Test unit parsing edge cases and error handling.