mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-04 21:46:22 +00:00
Add new git_signature_default API using config
This adds a new API for creating a signature that uses the config to look up "user.name" and "user.email".
This commit is contained in:
parent
68458e422a
commit
ce23330fd6
@ -48,6 +48,19 @@ GIT_EXTERN(int) git_signature_new(git_signature **out, const char *name, const c
|
||||
*/
|
||||
GIT_EXTERN(int) git_signature_now(git_signature **out, const char *name, const char *email);
|
||||
|
||||
/**
|
||||
* Create a new action signature with default user and now timestamp.
|
||||
*
|
||||
* This looks up the user.name and user.email from the configuration and
|
||||
* uses the current time as the timestamp, and creates a new signature
|
||||
* based on that information. It will return GIT_ENOTFOUND if either the
|
||||
* user.name or user.email are not set.
|
||||
*
|
||||
* @param out new signature
|
||||
* @param repo repository pointer
|
||||
* @return 0 on success, GIT_ENOTFOUND if config is missing, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_signature_default(git_signature **out, git_repository *repo);
|
||||
|
||||
/**
|
||||
* Create a copy of an existing signature. All internal strings are also
|
||||
|
@ -129,6 +129,23 @@ int git_signature_now(git_signature **sig_out, const char *name, const char *ema
|
||||
return 0;
|
||||
}
|
||||
|
||||
int git_signature_default(git_signature **out, git_repository *repo)
|
||||
{
|
||||
int error;
|
||||
git_config *cfg;
|
||||
const char *user_name, *user_email;
|
||||
|
||||
if ((error = git_repository_config(&cfg, repo)) < 0)
|
||||
return error;
|
||||
|
||||
if (!(error = git_config_get_string(&user_name, cfg, "user.name")) &&
|
||||
!(error = git_config_get_string(&user_email, cfg, "user.email")))
|
||||
error = git_signature_now(out, user_name, user_email);
|
||||
|
||||
git_config_free(cfg);
|
||||
return error;
|
||||
}
|
||||
|
||||
int git_signature__parse(git_signature *sig, const char **buffer_out,
|
||||
const char *buffer_end, const char *header, char ender)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user