log-tree.c: small refactor in show_signature()
The next patch needs to show the result of signature verification on a mergetag extended header in a way similar to how embedded signature for the commit object itself is shown. Separate out the logic to go through the message lines and show them in the "error" color (highlighted) or the "correct" color (dim). Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jan 4, 2012 at 13:48 UTC
c6b3ec41e2efdd9e05118c2e99ad70f0e0629873
1 file changed
+16
-12
log-tree.c
+16
-12
@@ -404,13 +404,27 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
404
*extra_headers_p = extra_headers;
405
}
406
407
+static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
408
+{
409
+ const char *color, *reset, *eol;
410
+
411
+ color = diff_get_color_opt(&opt->diffopt,
412
+ status ? DIFF_WHITESPACE : DIFF_FRAGINFO);
413
+ reset = diff_get_color_opt(&opt->diffopt, DIFF_RESET);
414
+ while (*bol) {
415
+ eol = strchrnul(bol, '\n');
416
+ printf("%s%.*s%s%s", color, (int)(eol - bol), bol, reset,
417
+ *eol ? "\n" : "");
418
+ bol = (*eol) ? (eol + 1) : eol;
419
+ }
420
+}
421
+
422
static void show_signature(struct rev_info *opt, struct commit *commit)
423
{
424
struct strbuf payload = STRBUF_INIT;
425
struct strbuf signature = STRBUF_INIT;
426
struct strbuf gpg_output = STRBUF_INIT;
427
int status;
413
- const char *color, *reset, *bol, *eol;
428
429
if (parse_signed_commit(commit->object.sha1, &payload, &signature) <= 0)
430
goto out;
@@ -421,17 +435,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)
435
if (status && !gpg_output.len)
436
strbuf_addstr(&gpg_output, "No signature\n");
437
424
- color = diff_get_color_opt(&opt->diffopt,
425
- status ? DIFF_WHITESPACE : DIFF_FRAGINFO);
426
- reset = diff_get_color_opt(&opt->diffopt, DIFF_RESET);
427
-
428
- bol = gpg_output.buf;
429
- while (*bol) {
430
- eol = strchrnul(bol, '\n');
431
- printf("%s%.*s%s%s", color, (int)(eol - bol), bol, reset,
432
- *eol ? "\n" : "");
433
- bol = (*eol) ? (eol + 1) : eol;
434
- }
438
+ show_sig_lines(opt, status, gpg_output.buf);
439
440
out:
441
strbuf_release(&gpg_output);