commit a003d5184726e721ca5313a722fc1a22d602e8b8 from: Omar Polo date: Thu Jan 26 23:30:43 2023 UTC cmd_tag: avoid unnecessary strdup of signer_id ok jrick commit - 87332a0e6e71182f1fb148d7f42e78105713285b commit + a003d5184726e721ca5313a722fc1a22d602e8b8 blob - 87ce79c90db5ebd79d068d2738dfb439ab4da56a blob + 50fb5ec76cf7c16aa5ecf3017aa935c3f4c6cffa --- 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; }