7 #include "reflog-walk.h"
9 #include "string-list.h"
11 #include "gpg-interface.h"
12 #include "sequencer.h"
15 static struct decoration name_decoration
= { "object names" };
16 static int decoration_loaded
;
17 static int decoration_flags
;
19 static char decoration_colors
[][COLOR_MAXLEN
] = {
21 GIT_COLOR_BOLD_GREEN
, /* REF_LOCAL */
22 GIT_COLOR_BOLD_RED
, /* REF_REMOTE */
23 GIT_COLOR_BOLD_YELLOW
, /* REF_TAG */
24 GIT_COLOR_BOLD_MAGENTA
, /* REF_STASH */
25 GIT_COLOR_BOLD_CYAN
, /* REF_HEAD */
26 GIT_COLOR_BOLD_BLUE
, /* GRAFTED */
29 static const char *decorate_get_color(int decorate_use_color
, enum decoration_type ix
)
31 if (want_color(decorate_use_color
))
32 return decoration_colors
[ix
];
36 static int parse_decorate_color_slot(const char *slot
)
39 * We're comparing with 'ignore-case' on
40 * (because config.c sets them all tolower),
41 * but let's match the letters in the literal
42 * string values here with how they are
43 * documented in Documentation/config.txt, for
46 * We love being consistent, don't we?
48 if (!strcasecmp(slot
, "branch"))
49 return DECORATION_REF_LOCAL
;
50 if (!strcasecmp(slot
, "remoteBranch"))
51 return DECORATION_REF_REMOTE
;
52 if (!strcasecmp(slot
, "tag"))
53 return DECORATION_REF_TAG
;
54 if (!strcasecmp(slot
, "stash"))
55 return DECORATION_REF_STASH
;
56 if (!strcasecmp(slot
, "HEAD"))
57 return DECORATION_REF_HEAD
;
61 int parse_decorate_color_config(const char *var
, const char *slot_name
, const char *value
)
63 int slot
= parse_decorate_color_slot(slot_name
);
67 return config_error_nonbool(var
);
68 return color_parse(value
, decoration_colors
[slot
]);
72 * log-tree.c uses DIFF_OPT_TST for determining whether to use color
73 * for showing the commit sha1, use the same check for --decorate
75 #define decorate_get_color_opt(o, ix) \
76 decorate_get_color((o)->use_color, ix)
78 void add_name_decoration(enum decoration_type type
, const char *name
, struct object
*obj
)
80 struct name_decoration
*res
;
81 FLEX_ALLOC_STR(res
, name
, name
);
83 res
->next
= add_decoration(&name_decoration
, obj
, res
);
86 const struct name_decoration
*get_name_decoration(const struct object
*obj
)
88 return lookup_decoration(&name_decoration
, obj
);
91 static int add_ref_decoration(const char *refname
, const struct object_id
*oid
,
92 int flags
, void *cb_data
)
95 enum decoration_type type
= DECORATION_NONE
;
97 assert(cb_data
== NULL
);
99 if (starts_with(refname
, git_replace_ref_base
)) {
100 struct object_id original_oid
;
101 if (!check_replace_refs
)
103 if (get_oid_hex(refname
+ strlen(git_replace_ref_base
),
105 warning("invalid replace ref %s", refname
);
108 obj
= parse_object(&original_oid
);
110 add_name_decoration(DECORATION_GRAFTED
, "replaced", obj
);
114 obj
= parse_object(oid
);
118 if (starts_with(refname
, "refs/heads/"))
119 type
= DECORATION_REF_LOCAL
;
120 else if (starts_with(refname
, "refs/remotes/"))
121 type
= DECORATION_REF_REMOTE
;
122 else if (starts_with(refname
, "refs/tags/"))
123 type
= DECORATION_REF_TAG
;
124 else if (!strcmp(refname
, "refs/stash"))
125 type
= DECORATION_REF_STASH
;
126 else if (!strcmp(refname
, "HEAD"))
127 type
= DECORATION_REF_HEAD
;
129 add_name_decoration(type
, refname
, obj
);
130 while (obj
->type
== OBJ_TAG
) {
131 obj
= ((struct tag
*)obj
)->tagged
;
135 parse_object(&obj
->oid
);
136 add_name_decoration(DECORATION_REF_TAG
, refname
, obj
);
141 static int add_graft_decoration(const struct commit_graft
*graft
, void *cb_data
)
143 struct commit
*commit
= lookup_commit(&graft
->oid
);
146 add_name_decoration(DECORATION_GRAFTED
, "grafted", &commit
->object
);
150 void load_ref_decorations(int flags
)
152 if (!decoration_loaded
) {
154 decoration_loaded
= 1;
155 decoration_flags
= flags
;
156 for_each_ref(add_ref_decoration
, NULL
);
157 head_ref(add_ref_decoration
, NULL
);
158 for_each_commit_graft(add_graft_decoration
, NULL
);
162 static void show_parents(struct commit
*commit
, int abbrev
, FILE *file
)
164 struct commit_list
*p
;
165 for (p
= commit
->parents
; p
; p
= p
->next
) {
166 struct commit
*parent
= p
->item
;
167 fprintf(file
, " %s", find_unique_abbrev(parent
->object
.oid
.hash
, abbrev
));
171 static void show_children(struct rev_info
*opt
, struct commit
*commit
, int abbrev
)
173 struct commit_list
*p
= lookup_decoration(&opt
->children
, &commit
->object
);
174 for ( ; p
; p
= p
->next
) {
175 fprintf(opt
->diffopt
.file
, " %s", find_unique_abbrev(p
->item
->object
.oid
.hash
, abbrev
));
180 * Do we have HEAD in the output, and also the branch it points at?
181 * If so, find that decoration entry for that current branch.
183 static const struct name_decoration
*current_pointed_by_HEAD(const struct name_decoration
*decoration
)
185 const struct name_decoration
*list
, *head
= NULL
;
186 const char *branch_name
= NULL
;
187 struct object_id unused
;
190 /* First find HEAD */
191 for (list
= decoration
; list
; list
= list
->next
)
192 if (list
->type
== DECORATION_REF_HEAD
) {
199 /* Now resolve and find the matching current branch */
200 branch_name
= resolve_ref_unsafe("HEAD", 0, unused
.hash
, &rru_flags
);
201 if (!(rru_flags
& REF_ISSYMREF
))
204 if (!starts_with(branch_name
, "refs/"))
207 /* OK, do we have that ref in the list? */
208 for (list
= decoration
; list
; list
= list
->next
)
209 if ((list
->type
== DECORATION_REF_LOCAL
) &&
210 !strcmp(branch_name
, list
->name
)) {
217 static void show_name(struct strbuf
*sb
, const struct name_decoration
*decoration
)
219 if (decoration_flags
== DECORATE_SHORT_REFS
)
220 strbuf_addstr(sb
, prettify_refname(decoration
->name
));
222 strbuf_addstr(sb
, decoration
->name
);
226 * The caller makes sure there is no funny color before calling.
227 * format_decorations_extended makes sure the same after return.
229 void format_decorations_extended(struct strbuf
*sb
,
230 const struct commit
*commit
,
233 const char *separator
,
236 const struct name_decoration
*decoration
;
237 const struct name_decoration
*current_and_HEAD
;
238 const char *color_commit
=
239 diff_get_color(use_color
, DIFF_COMMIT
);
240 const char *color_reset
=
241 decorate_get_color(use_color
, DECORATION_NONE
);
243 decoration
= get_name_decoration(&commit
->object
);
247 current_and_HEAD
= current_pointed_by_HEAD(decoration
);
250 * When both current and HEAD are there, only
251 * show HEAD->current where HEAD would have
252 * appeared, skipping the entry for current.
254 if (decoration
!= current_and_HEAD
) {
255 strbuf_addstr(sb
, color_commit
);
256 strbuf_addstr(sb
, prefix
);
257 strbuf_addstr(sb
, color_reset
);
258 strbuf_addstr(sb
, decorate_get_color(use_color
, decoration
->type
));
259 if (decoration
->type
== DECORATION_REF_TAG
)
260 strbuf_addstr(sb
, "tag: ");
262 show_name(sb
, decoration
);
264 if (current_and_HEAD
&&
265 decoration
->type
== DECORATION_REF_HEAD
) {
266 strbuf_addstr(sb
, " -> ");
267 strbuf_addstr(sb
, color_reset
);
268 strbuf_addstr(sb
, decorate_get_color(use_color
, current_and_HEAD
->type
));
269 show_name(sb
, current_and_HEAD
);
271 strbuf_addstr(sb
, color_reset
);
275 decoration
= decoration
->next
;
277 strbuf_addstr(sb
, color_commit
);
278 strbuf_addstr(sb
, suffix
);
279 strbuf_addstr(sb
, color_reset
);
282 void show_decorations(struct rev_info
*opt
, struct commit
*commit
)
284 struct strbuf sb
= STRBUF_INIT
;
286 if (opt
->show_source
&& commit
->util
)
287 fprintf(opt
->diffopt
.file
, "\t%s", (char *) commit
->util
);
288 if (!opt
->show_decorations
)
290 format_decorations(&sb
, commit
, opt
->diffopt
.use_color
);
291 fputs(sb
.buf
, opt
->diffopt
.file
);
295 static unsigned int digits_in_number(unsigned int number
)
297 unsigned int i
= 10, result
= 1;
298 while (i
<= number
) {
305 void fmt_output_subject(struct strbuf
*filename
,
307 struct rev_info
*info
)
309 const char *suffix
= info
->patch_suffix
;
311 int start_len
= filename
->len
;
312 int max_len
= start_len
+ FORMAT_PATCH_NAME_MAX
- (strlen(suffix
) + 1);
314 if (0 < info
->reroll_count
)
315 strbuf_addf(filename
, "v%d-", info
->reroll_count
);
316 strbuf_addf(filename
, "%04d-%s", nr
, subject
);
318 if (max_len
< filename
->len
)
319 strbuf_setlen(filename
, max_len
);
320 strbuf_addstr(filename
, suffix
);
323 void fmt_output_commit(struct strbuf
*filename
,
324 struct commit
*commit
,
325 struct rev_info
*info
)
327 struct pretty_print_context ctx
= {0};
328 struct strbuf subject
= STRBUF_INIT
;
330 format_commit_message(commit
, "%f", &subject
, &ctx
);
331 fmt_output_subject(filename
, subject
.buf
, info
);
332 strbuf_release(&subject
);
335 void fmt_output_email_subject(struct strbuf
*sb
, struct rev_info
*opt
)
337 if (opt
->total
> 0) {
338 strbuf_addf(sb
, "Subject: [%s%s%0*d/%d] ",
340 *opt
->subject_prefix
? " " : "",
341 digits_in_number(opt
->total
),
342 opt
->nr
, opt
->total
);
343 } else if (opt
->total
== 0 && opt
->subject_prefix
&& *opt
->subject_prefix
) {
344 strbuf_addf(sb
, "Subject: [%s] ",
345 opt
->subject_prefix
);
347 strbuf_addstr(sb
, "Subject: ");
351 void log_write_email_headers(struct rev_info
*opt
, struct commit
*commit
,
352 const char **extra_headers_p
,
353 int *need_8bit_cte_p
)
355 const char *extra_headers
= opt
->extra_headers
;
356 const char *name
= oid_to_hex(opt
->zero_commit
?
357 &null_oid
: &commit
->object
.oid
);
359 *need_8bit_cte_p
= 0; /* unknown */
361 fprintf(opt
->diffopt
.file
, "From %s Mon Sep 17 00:00:00 2001\n", name
);
362 graph_show_oneline(opt
->graph
);
363 if (opt
->message_id
) {
364 fprintf(opt
->diffopt
.file
, "Message-Id: <%s>\n", opt
->message_id
);
365 graph_show_oneline(opt
->graph
);
367 if (opt
->ref_message_ids
&& opt
->ref_message_ids
->nr
> 0) {
369 n
= opt
->ref_message_ids
->nr
;
370 fprintf(opt
->diffopt
.file
, "In-Reply-To: <%s>\n", opt
->ref_message_ids
->items
[n
-1].string
);
371 for (i
= 0; i
< n
; i
++)
372 fprintf(opt
->diffopt
.file
, "%s<%s>\n", (i
> 0 ? "\t" : "References: "),
373 opt
->ref_message_ids
->items
[i
].string
);
374 graph_show_oneline(opt
->graph
);
376 if (opt
->mime_boundary
) {
377 static char subject_buffer
[1024];
378 static char buffer
[1024];
379 struct strbuf filename
= STRBUF_INIT
;
380 *need_8bit_cte_p
= -1; /* NEVER */
381 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
383 "MIME-Version: 1.0\n"
384 "Content-Type: multipart/mixed;"
385 " boundary=\"%s%s\"\n"
387 "This is a multi-part message in MIME "
390 "Content-Type: text/plain; "
391 "charset=UTF-8; format=fixed\n"
392 "Content-Transfer-Encoding: 8bit\n\n",
393 extra_headers
? extra_headers
: "",
394 mime_boundary_leader
, opt
->mime_boundary
,
395 mime_boundary_leader
, opt
->mime_boundary
);
396 extra_headers
= subject_buffer
;
398 if (opt
->numbered_files
)
399 strbuf_addf(&filename
, "%d", opt
->nr
);
401 fmt_output_commit(&filename
, commit
, opt
);
402 snprintf(buffer
, sizeof(buffer
) - 1,
404 "Content-Type: text/x-patch;"
406 "Content-Transfer-Encoding: 8bit\n"
407 "Content-Disposition: %s;"
408 " filename=\"%s\"\n\n",
409 mime_boundary_leader
, opt
->mime_boundary
,
411 opt
->no_inline
? "attachment" : "inline",
413 opt
->diffopt
.stat_sep
= buffer
;
414 strbuf_release(&filename
);
416 *extra_headers_p
= extra_headers
;
419 static void show_sig_lines(struct rev_info
*opt
, int status
, const char *bol
)
421 const char *color
, *reset
, *eol
;
423 color
= diff_get_color_opt(&opt
->diffopt
,
424 status
? DIFF_WHITESPACE
: DIFF_FRAGINFO
);
425 reset
= diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
);
427 eol
= strchrnul(bol
, '\n');
428 fprintf(opt
->diffopt
.file
, "%s%.*s%s%s", color
, (int)(eol
- bol
), bol
, reset
,
430 graph_show_oneline(opt
->graph
);
431 bol
= (*eol
) ? (eol
+ 1) : eol
;
435 static void show_signature(struct rev_info
*opt
, struct commit
*commit
)
437 struct strbuf payload
= STRBUF_INIT
;
438 struct strbuf signature
= STRBUF_INIT
;
439 struct strbuf gpg_output
= STRBUF_INIT
;
442 if (parse_signed_commit(commit
, &payload
, &signature
) <= 0)
445 status
= verify_signed_buffer(payload
.buf
, payload
.len
,
446 signature
.buf
, signature
.len
,
448 if (status
&& !gpg_output
.len
)
449 strbuf_addstr(&gpg_output
, "No signature\n");
451 show_sig_lines(opt
, status
, gpg_output
.buf
);
454 strbuf_release(&gpg_output
);
455 strbuf_release(&payload
);
456 strbuf_release(&signature
);
459 static int which_parent(const struct object_id
*oid
, const struct commit
*commit
)
462 const struct commit_list
*parent
;
464 for (nth
= 0, parent
= commit
->parents
; parent
; parent
= parent
->next
) {
465 if (!oidcmp(&parent
->item
->object
.oid
, oid
))
472 static int is_common_merge(const struct commit
*commit
)
474 return (commit
->parents
475 && commit
->parents
->next
476 && !commit
->parents
->next
->next
);
479 static void show_one_mergetag(struct commit
*commit
,
480 struct commit_extra_header
*extra
,
483 struct rev_info
*opt
= (struct rev_info
*)data
;
484 struct object_id oid
;
486 struct strbuf verify_message
;
488 size_t payload_size
, gpg_message_offset
;
490 hash_sha1_file(extra
->value
, extra
->len
, typename(OBJ_TAG
), oid
.hash
);
491 tag
= lookup_tag(&oid
);
493 return; /* error message already given */
495 strbuf_init(&verify_message
, 256);
496 if (parse_tag_buffer(tag
, extra
->value
, extra
->len
))
497 strbuf_addstr(&verify_message
, "malformed mergetag\n");
498 else if (is_common_merge(commit
) &&
499 !oidcmp(&tag
->tagged
->oid
,
500 &commit
->parents
->next
->item
->object
.oid
))
501 strbuf_addf(&verify_message
,
502 "merged tag '%s'\n", tag
->tag
);
503 else if ((nth
= which_parent(&tag
->tagged
->oid
, commit
)) < 0)
504 strbuf_addf(&verify_message
, "tag %s names a non-parent %s\n",
505 tag
->tag
, tag
->tagged
->oid
.hash
);
507 strbuf_addf(&verify_message
,
508 "parent #%d, tagged '%s'\n", nth
+ 1, tag
->tag
);
509 gpg_message_offset
= verify_message
.len
;
511 payload_size
= parse_signature(extra
->value
, extra
->len
);
513 if (extra
->len
> payload_size
) {
514 /* could have a good signature */
515 if (!verify_signed_buffer(extra
->value
, payload_size
,
516 extra
->value
+ payload_size
,
517 extra
->len
- payload_size
,
518 &verify_message
, NULL
))
519 status
= 0; /* good */
520 else if (verify_message
.len
<= gpg_message_offset
)
521 strbuf_addstr(&verify_message
, "No signature\n");
522 /* otherwise we couldn't verify, which is shown as bad */
525 show_sig_lines(opt
, status
, verify_message
.buf
);
526 strbuf_release(&verify_message
);
529 static void show_mergetag(struct rev_info
*opt
, struct commit
*commit
)
531 for_each_mergetag(show_one_mergetag
, commit
, opt
);
534 void show_log(struct rev_info
*opt
)
536 struct strbuf msgbuf
= STRBUF_INIT
;
537 struct log_info
*log
= opt
->loginfo
;
538 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
539 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: GIT_SHA1_HEXSZ
;
540 const char *extra_headers
= opt
->extra_headers
;
541 struct pretty_print_context ctx
= {0};
544 if (!opt
->verbose_header
) {
545 graph_show_commit(opt
->graph
);
548 put_revision_mark(opt
, commit
);
549 fputs(find_unique_abbrev(commit
->object
.oid
.hash
, abbrev_commit
), opt
->diffopt
.file
);
550 if (opt
->print_parents
)
551 show_parents(commit
, abbrev_commit
, opt
->diffopt
.file
);
552 if (opt
->children
.name
)
553 show_children(opt
, commit
, abbrev_commit
);
554 show_decorations(opt
, commit
);
555 if (opt
->graph
&& !graph_is_commit_finished(opt
->graph
)) {
556 putc('\n', opt
->diffopt
.file
);
557 graph_show_remainder(opt
->graph
);
559 putc(opt
->diffopt
.line_termination
, opt
->diffopt
.file
);
564 * If use_terminator is set, we already handled any record termination
565 * at the end of the last record.
566 * Otherwise, add a diffopt.line_termination character before all
567 * entries but the first. (IOW, as a separator between entries)
569 if (opt
->shown_one
&& !opt
->use_terminator
) {
571 * If entries are separated by a newline, the output
572 * should look human-readable. If the last entry ended
573 * with a newline, print the graph output before this
574 * newline. Otherwise it will end up as a completely blank
575 * line and will look like a gap in the graph.
577 * If the entry separator is not a newline, the output is
578 * primarily intended for programmatic consumption, and we
579 * never want the extra graph output before the entry
582 if (opt
->diffopt
.line_termination
== '\n' &&
583 !opt
->missing_newline
)
584 graph_show_padding(opt
->graph
);
585 putc(opt
->diffopt
.line_termination
, opt
->diffopt
.file
);
590 * If the history graph was requested,
591 * print the graph, up to this commit's line
593 graph_show_commit(opt
->graph
);
596 * Print header line of header..
599 if (cmit_fmt_is_mail(opt
->commit_format
)) {
600 log_write_email_headers(opt
, commit
, &extra_headers
,
603 ctx
.print_email_subject
= 1;
604 } else if (opt
->commit_format
!= CMIT_FMT_USERFORMAT
) {
605 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_COMMIT
), opt
->diffopt
.file
);
606 if (opt
->commit_format
!= CMIT_FMT_ONELINE
)
607 fputs("commit ", opt
->diffopt
.file
);
610 put_revision_mark(opt
, commit
);
611 fputs(find_unique_abbrev(commit
->object
.oid
.hash
, abbrev_commit
),
613 if (opt
->print_parents
)
614 show_parents(commit
, abbrev_commit
, opt
->diffopt
.file
);
615 if (opt
->children
.name
)
616 show_children(opt
, commit
, abbrev_commit
);
618 fprintf(opt
->diffopt
.file
, " (from %s)",
619 find_unique_abbrev(parent
->object
.oid
.hash
,
621 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
), opt
->diffopt
.file
);
622 show_decorations(opt
, commit
);
623 if (opt
->commit_format
== CMIT_FMT_ONELINE
) {
624 putc(' ', opt
->diffopt
.file
);
626 putc('\n', opt
->diffopt
.file
);
627 graph_show_oneline(opt
->graph
);
629 if (opt
->reflog_info
) {
631 * setup_revisions() ensures that opt->reflog_info
632 * and opt->graph cannot both be set,
633 * so we don't need to worry about printing the
636 show_reflog_message(opt
->reflog_info
,
637 opt
->commit_format
== CMIT_FMT_ONELINE
,
639 opt
->date_mode_explicit
);
640 if (opt
->commit_format
== CMIT_FMT_ONELINE
)
645 if (opt
->show_signature
) {
646 show_signature(opt
, commit
);
647 show_mergetag(opt
, commit
);
650 if (!get_cached_commit_buffer(commit
, NULL
))
653 if (opt
->show_notes
) {
655 struct strbuf notebuf
= STRBUF_INIT
;
657 raw
= (opt
->commit_format
== CMIT_FMT_USERFORMAT
);
658 format_display_notes(commit
->object
.oid
.hash
, ¬ebuf
,
659 get_log_output_encoding(), raw
);
660 ctx
.notes_message
= notebuf
.len
661 ? strbuf_detach(¬ebuf
, NULL
)
666 * And then the pretty-printed message itself
668 if (ctx
.need_8bit_cte
>= 0 && opt
->add_signoff
)
670 has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"),
671 getenv("GIT_COMMITTER_EMAIL")));
672 ctx
.date_mode
= opt
->date_mode
;
673 ctx
.date_mode_explicit
= opt
->date_mode_explicit
;
674 ctx
.abbrev
= opt
->diffopt
.abbrev
;
675 ctx
.after_subject
= extra_headers
;
676 ctx
.preserve_subject
= opt
->preserve_subject
;
677 ctx
.reflog_info
= opt
->reflog_info
;
678 ctx
.fmt
= opt
->commit_format
;
679 ctx
.mailmap
= opt
->mailmap
;
680 ctx
.color
= opt
->diffopt
.use_color
;
681 ctx
.expand_tabs_in_log
= opt
->expand_tabs_in_log
;
682 ctx
.output_encoding
= get_log_output_encoding();
683 if (opt
->from_ident
.mail_begin
&& opt
->from_ident
.name_begin
)
684 ctx
.from_ident
= &opt
->from_ident
;
686 ctx
.graph_width
= graph_width(opt
->graph
);
687 pretty_print_commit(&ctx
, commit
, &msgbuf
);
689 if (opt
->add_signoff
)
690 append_signoff(&msgbuf
, 0, APPEND_SIGNOFF_DEDUP
);
692 if ((ctx
.fmt
!= CMIT_FMT_USERFORMAT
) &&
693 ctx
.notes_message
&& *ctx
.notes_message
) {
694 if (cmit_fmt_is_mail(ctx
.fmt
)) {
695 strbuf_addstr(&msgbuf
, "---\n");
696 opt
->shown_dashes
= 1;
698 strbuf_addstr(&msgbuf
, ctx
.notes_message
);
701 if (opt
->show_log_size
) {
702 fprintf(opt
->diffopt
.file
, "log size %i\n", (int)msgbuf
.len
);
703 graph_show_oneline(opt
->graph
);
707 * Set opt->missing_newline if msgbuf doesn't
708 * end in a newline (including if it is empty)
710 if (!msgbuf
.len
|| msgbuf
.buf
[msgbuf
.len
- 1] != '\n')
711 opt
->missing_newline
= 1;
713 opt
->missing_newline
= 0;
715 graph_show_commit_msg(opt
->graph
, opt
->diffopt
.file
, &msgbuf
);
716 if (opt
->use_terminator
&& !commit_format_is_empty(opt
->commit_format
)) {
717 if (!opt
->missing_newline
)
718 graph_show_padding(opt
->graph
);
719 putc(opt
->diffopt
.line_termination
, opt
->diffopt
.file
);
722 strbuf_release(&msgbuf
);
723 free(ctx
.notes_message
);
726 int log_tree_diff_flush(struct rev_info
*opt
)
728 opt
->shown_dashes
= 0;
729 diffcore_std(&opt
->diffopt
);
731 if (diff_queue_is_empty()) {
732 int saved_fmt
= opt
->diffopt
.output_format
;
733 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
734 diff_flush(&opt
->diffopt
);
735 opt
->diffopt
.output_format
= saved_fmt
;
739 if (opt
->loginfo
&& !opt
->no_commit_id
) {
741 if ((opt
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
) &&
742 opt
->verbose_header
&&
743 opt
->commit_format
!= CMIT_FMT_ONELINE
&&
744 !commit_format_is_empty(opt
->commit_format
)) {
746 * When showing a verbose header (i.e. log message),
747 * and not in --pretty=oneline format, we would want
748 * an extra newline between the end of log and the
749 * diff/diffstat output for readability.
751 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
752 if (opt
->diffopt
.output_prefix
) {
753 struct strbuf
*msg
= NULL
;
754 msg
= opt
->diffopt
.output_prefix(&opt
->diffopt
,
755 opt
->diffopt
.output_prefix_data
);
756 fwrite(msg
->buf
, msg
->len
, 1, opt
->diffopt
.file
);
760 * We may have shown three-dashes line early
761 * between notes and the log message, in which
762 * case we only want a blank line after the
763 * notes without (an extra) three-dashes line.
764 * Otherwise, we show the three-dashes line if
765 * we are showing the patch with diffstat, but
766 * in that case, there is no extra blank line
767 * after the three-dashes line.
769 if (!opt
->shown_dashes
&&
770 (pch
& opt
->diffopt
.output_format
) == pch
)
771 fprintf(opt
->diffopt
.file
, "---");
772 putc('\n', opt
->diffopt
.file
);
775 diff_flush(&opt
->diffopt
);
779 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
781 diff_tree_combined_merge(commit
, opt
->dense_combined_merges
, opt
);
782 return !opt
->loginfo
;
786 * Show the diff of a commit.
788 * Return true if we printed any log info messages
790 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
793 struct commit_list
*parents
;
794 struct object_id
*oid
;
796 if (!opt
->diff
&& !DIFF_OPT_TST(&opt
->diffopt
, EXIT_WITH_STATUS
))
799 parse_commit_or_die(commit
);
800 oid
= &commit
->tree
->object
.oid
;
803 parents
= get_saved_parents(opt
, commit
);
805 if (opt
->show_root_diff
) {
806 diff_root_tree_sha1(oid
->hash
, "", &opt
->diffopt
);
807 log_tree_diff_flush(opt
);
809 return !opt
->loginfo
;
812 /* More than one parent? */
813 if (parents
&& parents
->next
) {
814 if (opt
->ignore_merges
)
816 else if (opt
->combine_merges
)
817 return do_diff_combined(opt
, commit
);
818 else if (opt
->first_parent_only
) {
820 * Generate merge log entry only for the first
821 * parent, showing summary diff of the others
824 parse_commit_or_die(parents
->item
);
825 diff_tree_sha1(parents
->item
->tree
->object
.oid
.hash
,
826 oid
->hash
, "", &opt
->diffopt
);
827 log_tree_diff_flush(opt
);
828 return !opt
->loginfo
;
831 /* If we show individual diffs, show the parent info */
832 log
->parent
= parents
->item
;
837 struct commit
*parent
= parents
->item
;
839 parse_commit_or_die(parent
);
840 diff_tree_sha1(parent
->tree
->object
.oid
.hash
,
841 oid
->hash
, "", &opt
->diffopt
);
842 log_tree_diff_flush(opt
);
844 showed_log
|= !opt
->loginfo
;
846 /* Set up the log info for the next parent, if any.. */
847 parents
= parents
->next
;
850 log
->parent
= parents
->item
;
856 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
859 int shown
, close_file
= opt
->diffopt
.close_file
;
864 opt
->diffopt
.close_file
= 0;
866 if (opt
->line_level_traverse
)
867 return line_log_print(opt
, commit
);
869 if (opt
->track_linear
&& !opt
->linear
&& !opt
->reverse_output_stage
)
870 fprintf(opt
->diffopt
.file
, "\n%s\n", opt
->break_bar
);
871 shown
= log_tree_diff(opt
, commit
, &log
);
872 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {
877 if (opt
->track_linear
&& !opt
->linear
&& opt
->reverse_output_stage
)
878 fprintf(opt
->diffopt
.file
, "\n%s\n", opt
->break_bar
);
880 maybe_flush_or_die(opt
->diffopt
.file
, "stdout");
882 fclose(opt
->diffopt
.file
);