From: Junio C Hamano <gitster@pobox.com>
To: "Jaydeep Das via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Jaydeep Das <jaydeepjd.8914@gmail.com>
Subject: Re: [PATCH] gpg-interface: add function for converting trust level to string
Date: Thu, 07 Jul 2022 11:18:20 -0700 [thread overview]
Message-ID: <xmqqwncozt03.fsf@gitster.g> (raw)
In-Reply-To: <pull.1281.git.1657202265048.gitgitgadget@gmail.com> (Jaydeep Das via GitGitGadget's message of "Thu, 07 Jul 2022 13:57:44 +0000")
"Jaydeep Das via GitGitGadget" <gitgitgadget@gmail.com> writes:
> diff --git a/gpg-interface.c b/gpg-interface.c
> index 947b58ad4da..fe6e5ce5127 100644
> --- a/gpg-interface.c
> +++ b/gpg-interface.c
> @@ -165,6 +165,7 @@ static struct {
> { 0, "TRUST_", GPG_STATUS_TRUST_LEVEL },
> };
>
> +/* Keep the order same as enum signature_trust_level */
> static struct {
> const char *key;
> enum signature_trust_level value;
> @@ -905,6 +906,12 @@ const char *get_signing_key(void)
> return git_committer_info(IDENT_STRICT | IDENT_NO_DATE);
> }
>
> +const char *gpg_trust_level_to_str(enum signature_trust_level level){
> + if (level < TRUST_UNDEFINED || level > TRUST_ULTIMATE)
> + return NULL;
> + return sigcheck_gpg_trust_level[level].key;
> +}
> +
> int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key)
> {
> return use_format->sign_buffer(buffer, signature, signing_key);
> diff --git a/gpg-interface.h b/gpg-interface.h
> index b30cbdcd3da..48f7edd916b 100644
> --- a/gpg-interface.h
> +++ b/gpg-interface.h
> @@ -71,6 +71,14 @@ size_t parse_signed_buffer(const char *buf, size_t size);
> int sign_buffer(struct strbuf *buffer, struct strbuf *signature,
> const char *signing_key);
>
> +
> +/*
> + * Returns corresponding string for a given member of
> + * enum signature_trust_level. For example, `TRUST_ULTIMATE` will
> + * return "ULTIMATE".
> + */
> +const char *gpg_trust_level_to_str(enum signature_trust_level level);
> + sig_str = gpg_trust_level_to_str(c->signature_check.trust_level);
> + if (sig_str){
Missing SP before open-brace.
> + const char *sig_str_lower = xstrdup_tolower(sig_str);
> + strbuf_addstr(sb, sig_str_lower);
> + free((char *)sig_str_lower);
Unnecessary const plus casting-away of it. You are getting a copy
to work with, so there is no reason to declare sig_str_lower to be
"const". This downcasing should be done in gpg_trust_level_to_str()
function, shouldn't it? After all, the "str" version of the trust
level existing end-users are familiar with are the strings you
removed from pretty.c that are all lowercase.
Thanks.
next prev parent reply other threads:[~2022-07-07 18:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-07 13:57 [PATCH] gpg-interface: add function for converting trust level to string Jaydeep Das via GitGitGadget
2022-07-07 18:18 ` Junio C Hamano [this message]
2022-07-08 11:24 ` [PATCH v2] " Jaydeep Das via GitGitGadget
2022-07-09 0:58 ` Eric Sunshine
2022-07-09 3:51 ` jaydeepjd.8914
2022-07-09 20:52 ` Junio C Hamano
2022-07-10 5:44 ` Eric Sunshine
2022-07-10 5:48 ` Junio C Hamano
2022-07-10 6:21 ` Eric Sunshine
2022-07-11 3:51 ` Jaydeep Das
2022-07-09 4:43 ` [PATCH v3] " Jaydeep Das via GitGitGadget
2022-07-11 5:00 ` [PATCH v4] " Jaydeep Das via GitGitGadget
2022-07-11 5:12 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqwncozt03.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=jaydeepjd.8914@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.