diff options
author | Vicent Martà <vicent@github.com> | 2013-08-16 15:33:13 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2013-08-16 15:33:13 -0700 |
commit | b2be62fd23a9e39ce32725139bdeecf7e10aa2ac (patch) | |
tree | 005f907f0613d807c6425b52e1e385927e20a54e /src | |
parent | 68458e422a6070d8f445eb6a4bfaac3310c330a3 (diff) | |
parent | 0ea41445f4028460aefcd55cb37f10870ea9311c (diff) | |
download | libgit2-b2be62fd23a9e39ce32725139bdeecf7e10aa2ac.tar.gz |
Merge pull request #1790 from libgit2/examples-init
Add "git init"-like example
Diffstat (limited to 'src')
-rw-r--r-- | src/signature.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/signature.c b/src/signature.c index 0a34ccfaa..52ca2b375 100644 --- a/src/signature.c +++ b/src/signature.c @@ -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) { |