@@ -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);
}
+char *gpg_trust_level_to_str(enum signature_trust_level level){
+ if (level < TRUST_UNDEFINED || level > TRUST_ULTIMATE)
+ return NULL;
+ return xstrdup_tolower(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);
@@ -71,6 +71,16 @@ 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 in lowercase for a given member of
+ * enum signature_trust_level. For example, `TRUST_ULTIMATE` will
+ * return "ultimate". Since it uses xstrdup_tolower(), which uses
+ * xmallocz(), the caller has to free up the memory for returned string
+ * after usage.
+ */
+char *gpg_trust_level_to_str(enum signature_trust_level level);
+
int git_gpg_config(const char *, const char *, void *);
void set_signing_key(const char *);
const char *get_signing_key(void);
@@ -1348,6 +1348,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
const char *msg = c->message;
struct commit_list *p;
const char *arg, *eol;
+ char *sig_str;
size_t res;
char **slot;
@@ -1575,23 +1576,10 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
strbuf_addstr(sb, c->signature_check.primary_key_fingerprint);
break;
case 'T':
- switch (c->signature_check.trust_level) {
- case TRUST_UNDEFINED:
- strbuf_addstr(sb, "undefined");
- break;
- case TRUST_NEVER:
- strbuf_addstr(sb, "never");
- break;
- case TRUST_MARGINAL:
- strbuf_addstr(sb, "marginal");
- break;
- case TRUST_FULLY:
- strbuf_addstr(sb, "fully");
- break;
- case TRUST_ULTIMATE:
- strbuf_addstr(sb, "ultimate");
- break;
- }
+ sig_str = gpg_trust_level_to_str(c->signature_check.trust_level);
+ if (sig_str)
+ strbuf_addstr(sb, sig_str);
+ free(sig_str);
break;
default:
return 0;