diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-01-04 13:51:28 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-01-05 13:02:27 -0800 |
commit | 824958e50b250e957998626a21763603ca30e832 (patch) | |
tree | 5831ae9621501ab28237f16e230e8b4420c31940 /log-tree.c | |
parent | c6b3ec41e2efdd9e05118c2e99ad70f0e0629873 (diff) | |
download | git-824958e50b250e957998626a21763603ca30e832.tar.gz |
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: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'log-tree.c')
-rw-r--r-- | log-tree.c | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/log-tree.c b/log-tree.c index 005c5a51c0..61a12a7cb0 100644 --- a/log-tree.c +++ b/log-tree.c @@ -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; |