Commit ce23330f by Russell Belfer

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".
parent 68458e42
......@@ -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
......
......@@ -74,7 +74,7 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
git_signature_free(p);
return signature_error("Signature cannot have an empty name");
}
p->when.time = time;
p->when.offset = offset;
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment