Skip to content

Commit c6b3ec4

Browse files
committed
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 <[email protected]>
1 parent c871a1d commit c6b3ec4

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

log-tree.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,27 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
404404
*extra_headers_p = extra_headers;
405405
}
406406

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+
407422
static void show_signature(struct rev_info *opt, struct commit *commit)
408423
{
409424
struct strbuf payload = STRBUF_INIT;
410425
struct strbuf signature = STRBUF_INIT;
411426
struct strbuf gpg_output = STRBUF_INIT;
412427
int status;
413-
const char *color, *reset, *bol, *eol;
414428

415429
if (parse_signed_commit(commit->object.sha1, &payload, &signature) <= 0)
416430
goto out;
@@ -421,17 +435,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)
421435
if (status && !gpg_output.len)
422436
strbuf_addstr(&gpg_output, "No signature\n");
423437

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);
435439

436440
out:
437441
strbuf_release(&gpg_output);

0 commit comments

Comments
 (0)