signature: add git_signature_default_from_env

People who are doing a commit expect a unified timestamp between
author and committer information when we're using the current timestamp.
Provide a single function that returns both author and committer
information so that they can have an identical timestamp when none is
specified in the environment.
This commit is contained in:
Edward Thomson
2024-06-14 12:50:40 +02:00
parent 24d9fe1339
commit 649ef1cca6
7 changed files with 131 additions and 108 deletions

View File

@@ -63,10 +63,8 @@ int lg2_commit(git_repository *repo, int argc, char **argv)
check_lg2(git_tree_lookup(&tree, repo, &tree_oid), "Error looking up tree", NULL);
check_lg2(git_signature_default_author(&author_signature, repo),
"Error creating author signature", NULL);
check_lg2(git_signature_default_committer(&committer_signature, repo),
"Error creating committer signature", NULL);
check_lg2(git_signature_default_from_env(&author_signature, &committer_signature, repo),
"Error creating signature", NULL);
check_lg2(git_commit_create_v(
&commit_oid,

View File

@@ -130,8 +130,7 @@ static void create_initial_commit(git_repository *repo)
/** First use the config to initialize a commit signature for the user. */
if ((git_signature_default_author(&author_sig, repo) < 0) ||
(git_signature_default_committer(&committer_sig, repo) < 0))
if ((git_signature_default_from_env(&author_sig, &committer_sig, repo) < 0))
fatal("Unable to create a commit signature.",
"Perhaps 'user.name' and 'user.email' are not set");

View File

@@ -108,7 +108,7 @@ static int cmd_push(git_repository *repo, struct opts *opts)
if (opts->argc)
usage("push does not accept any parameters");
check_lg2(git_signature_default_author(&signature, repo),
check_lg2(git_signature_default_from_env(&signature, NULL, repo),
"Unable to get signature", NULL);
check_lg2(git_stash_save(&stashid, repo, signature, NULL, GIT_STASH_DEFAULT),
"Unable to save stash", NULL);

View File

@@ -226,7 +226,7 @@ static void action_create_tag(tag_state *state)
check_lg2(git_revparse_single(&target, repo, opts->target),
"Unable to resolve spec", opts->target);
check_lg2(git_signature_default_author(&tagger, repo),
check_lg2(git_signature_default_from_env(&tagger, NULL, repo),
"Unable to create signature", NULL);
check_lg2(git_tag_create(&oid, repo, opts->tag_name,