Re: [PATCH v5 3/5] merge/pull: verify GPG signatures of commits being merged
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 30, 2013, 03:38 UTC
- Message-ID
- <7vvc89k15t.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <51562E6A.6020007@physik.tu-berlin.de>
Sebastian Götte <jaseg@physik.tu-berlin.de> writes:
> + OPT_BOOLEAN(0, "verify-signatures", &verify_signatures,
> + N_("Verify that the named commit has a valid GPG signature")),Please use OPT_BOOL() in new code. Verifying existing OPT_BOOLEAN() can safely converted to OPT_BOOL() and doing so would be a separate matter and should not be part of this series.
Show 6 quoted lines
> @@ -1233,6 +1235,35 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
> usage_with_options(builtin_merge_usage,
> builtin_merge_options);
>
> + if (verify_signatures) {
> + /* Verify the commit signatures */This boolean variable is named clearly enough that you do not need this comment.
Show 19 quoted lines
> + for (p = remoteheads; p; p = p->next) {
> + struct commit *commit = p->item;
> + char hex[41];
> + struct signature_check signature_check;
> + memset(&signature_check, 0, sizeof(signature_check));
> +
> + check_commit_signature(commit, &signature_check);
> +
> + strcpy(hex, find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
> + switch(signature_check.check_result){
> + case 'G':
> + if (verbosity >= 0)
> + printf(_("Commit %s has a good GPG signature by %s (key fingerprint %s)\n"), hex, signature_check.signer, signature_check.key);
> + break;
> + case 'B':
> + die(_("Commit %s has a bad GPG signature allegedly by %s (key fingerprint %s)."), hex, signature_check.signer, signature_check.key);
> + default: /* 'N' */
> + die(_("Commit %s does not have a good GPG signature. In fact, commit %s does not have a GPG signature at all."), hex, hex);
> + }Style.
switch (expr) {
case 'G':
do_something_for_G();
break;
...
}Also avoid overlong lines, both in the source, but pay extra attention to what we show the user. For example:
"Commit %s has a bad GPG signature allegedly by %s (key fingerprint %s)."
The first %s will expand to 40 places, the other two are likely to be around 20-30 places.
"Commit %s does not have a good GPG signature. In fact, commit %s does not have a GPG signature at all."
Drop everything from the beginning up to "In fact, ", perhaps:
"Commit '%s' does not have any GPG signature."
is sufficient? You may also want to consider
die(_("Commit '%.*s...' does not have any GPG signature."),
8, hex);