提交 824958e5 编写于 作者: J Junio C Hamano

log-tree: show mergetag in log --show-signature output

A commit object that merges a signed tag records the "mergetag" extended
header. Check the validity of the GPG signature on it, and show it in a
way similar to how "gpgsig" extended header is shown.
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 c6b3ec41
......@@ -443,6 +443,78 @@ static void show_signature(struct rev_info *opt, struct commit *commit)
strbuf_release(&signature);
}
static int which_parent(const unsigned char *sha1, const struct commit *commit)
{
int nth;
const struct commit_list *parent;
for (nth = 0, parent = commit->parents; parent; parent = parent->next) {
if (!hashcmp(parent->item->object.sha1, sha1))
return nth;
nth++;
}
return -1;
}
static void show_one_mergetag(struct rev_info *opt,
struct commit_extra_header *extra,
struct commit *commit)
{
unsigned char sha1[20];
struct tag *tag;
struct strbuf verify_message;
int status, nth;
size_t payload_size, gpg_message_offset;
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), sha1);
tag = lookup_tag(sha1);
if (!tag)
return; /* error message already given */
strbuf_init(&verify_message, 256);
if (parse_tag_buffer(tag, extra->value, extra->len))
strbuf_addstr(&verify_message, "malformed mergetag\n");
else if ((nth = which_parent(tag->tagged->sha1, commit)) < 0)
strbuf_addf(&verify_message, "tag %s names a non-parent %s\n",
tag->tag, tag->tagged->sha1);
else
strbuf_addf(&verify_message,
"parent #%d, tagged '%s'\n", nth + 1, tag->tag);
gpg_message_offset = verify_message.len;
payload_size = parse_signature(extra->value, extra->len);
if ((extra->len <= payload_size) ||
(verify_signed_buffer(extra->value, payload_size,
extra->value + payload_size,
extra->len - payload_size,
&verify_message) &&
verify_message.len <= gpg_message_offset)) {
strbuf_addstr(&verify_message, "No signature\n");
status = -1;
}
else if (strstr(verify_message.buf + gpg_message_offset,
": Good signature from "))
status = 0;
else
status = -1;
show_sig_lines(opt, status, verify_message.buf);
strbuf_release(&verify_message);
}
static void show_mergetag(struct rev_info *opt, struct commit *commit)
{
struct commit_extra_header *extra, *to_free;
to_free = read_commit_extra_headers(commit, NULL);
for (extra = to_free; extra; extra = extra->next) {
if (strcmp(extra->key, "mergetag"))
continue; /* not a merge tag */
show_one_mergetag(opt, extra, commit);
}
free_commit_extra_headers(to_free);
}
void show_log(struct rev_info *opt)
{
struct strbuf msgbuf = STRBUF_INIT;
......@@ -554,8 +626,10 @@ void show_log(struct rev_info *opt)
}
}
if (opt->show_signature)
if (opt->show_signature) {
show_signature(opt, commit);
show_mergetag(opt, commit);
}
if (!commit->buffer)
return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册