commit d4becbee8b30bfddd42b47a5d8cc47e3cfbc7077 from: Omar Polo via: Thomas Adam date: Fri Jan 27 16:48:21 2023 UTC cmd_tag: avoid unnecessary strdup of signer_id ok jrick commit - 717bfe1fc5d8b17816b1976027e99de75e670213 commit + d4becbee8b30bfddd42b47a5d8cc47e3cfbc7077 blob - 86b78a39c45a0ad32b8585b03c72dfebdefda4c0 blob + e334be3f5c0318204850c2bbf9a438e889cbdf30 --- got/got.c +++ got/got.c @@ -709,15 +709,12 @@ get_revoked_signers(char **revoked_signers, struct got return NULL; } -static const struct got_error * -get_signer_id(char **signer_id, struct got_repository *repo, - struct got_worktree *worktree) +static const char * +get_signer_id(struct got_repository *repo, struct got_worktree *worktree) { const char *got_signer_id = NULL; const struct got_gotconfig *worktree_conf = NULL, *repo_conf = NULL; - *signer_id = NULL; - if (worktree) worktree_conf = got_worktree_get_gotconfig(worktree); repo_conf = got_repo_get_gotconfig(repo); @@ -734,12 +731,7 @@ get_signer_id(char **signer_id, struct got_repository if (got_signer_id == NULL) got_signer_id = got_gotconfig_get_signer_id(repo_conf); - if (got_signer_id) { - *signer_id = strdup(got_signer_id); - if (*signer_id == NULL) - return got_error_from_errno("strdup"); - } - return NULL; + return got_signer_id; } static const struct got_error * @@ -7505,7 +7497,7 @@ cmd_tag(int argc, char *argv[]) char *cwd = NULL, *repo_path = NULL, *commit_id_str = NULL; char *gitconfig_path = NULL, *tagger = NULL; char *allowed_signers = NULL, *revoked_signers = NULL; - char *signer_id = NULL; + const char *signer_id = NULL; const char *tag_name = NULL, *commit_id_arg = NULL, *tagmsg = NULL; int ch, do_list = 0, verify_tags = 0, verbosity = 0; int *pack_fds = NULL; @@ -7531,11 +7523,7 @@ cmd_tag(int argc, char *argv[]) got_path_strip_trailing_slashes(repo_path); break; case 's': - signer_id = strdup(optarg); - if (signer_id == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } + signer_id = optarg; break; case 'V': verify_tags = 1; @@ -7662,11 +7650,8 @@ cmd_tag(int argc, char *argv[]) error = get_author(&tagger, repo, worktree); if (error) goto done; - if (signer_id == NULL) { - error = get_signer_id(&signer_id, repo, worktree); - if (error) - goto done; - } + if (signer_id == NULL) + signer_id = get_signer_id(repo, worktree); if (tagmsg) { if (signer_id) { @@ -7728,7 +7713,6 @@ done: free(tagger); free(allowed_signers); free(revoked_signers); - free(signer_id); return error; }