8 #include "reflog-walk.h"
10 #include "string-list.h"
12 #include "gpg-interface.h"
13 #include "sequencer.h"
17 static struct decoration name_decoration
= { "object names" };
18 static int decoration_loaded
;
19 static int decoration_flags
;
21 static char decoration_colors
[][COLOR_MAXLEN
] = {
23 GIT_COLOR_BOLD_GREEN
, /* REF_LOCAL */
24 GIT_COLOR_BOLD_RED
, /* REF_REMOTE */
25 GIT_COLOR_BOLD_YELLOW
, /* REF_TAG */
26 GIT_COLOR_BOLD_MAGENTA
, /* REF_STASH */
27 GIT_COLOR_BOLD_CYAN
, /* REF_HEAD */
28 GIT_COLOR_BOLD_BLUE
, /* GRAFTED */
31 static const char *color_decorate_slots
[] = {
32 [DECORATION_REF_LOCAL
] = "branch",
33 [DECORATION_REF_REMOTE
] = "remoteBranch",
34 [DECORATION_REF_TAG
] = "tag",
35 [DECORATION_REF_STASH
] = "stash",
36 [DECORATION_REF_HEAD
] = "HEAD",
39 static const char *decorate_get_color(int decorate_use_color
, enum decoration_type ix
)
41 if (want_color(decorate_use_color
))
42 return decoration_colors
[ix
];
46 define_list_config_array(color_decorate_slots
);
48 int parse_decorate_color_config(const char *var
, const char *slot_name
, const char *value
)
50 int slot
= LOOKUP_CONFIG(color_decorate_slots
, slot_name
);
54 return config_error_nonbool(var
);
55 return color_parse(value
, decoration_colors
[slot
]);
59 * log-tree.c uses DIFF_OPT_TST for determining whether to use color
60 * for showing the commit sha1, use the same check for --decorate
62 #define decorate_get_color_opt(o, ix) \
63 decorate_get_color((o)->use_color, ix)
65 void add_name_decoration(enum decoration_type type
, const char *name
, struct object
*obj
)
67 struct name_decoration
*res
;
68 FLEX_ALLOC_STR(res
, name
, name
);
70 res
->next
= add_decoration(&name_decoration
, obj
, res
);
73 const struct name_decoration
*get_name_decoration(const struct object
*obj
)
75 return lookup_decoration(&name_decoration
, obj
);
78 static int add_ref_decoration(const char *refname
, const struct object_id
*oid
,
79 int flags
, void *cb_data
)
82 enum decoration_type type
= DECORATION_NONE
;
83 struct decoration_filter
*filter
= (struct decoration_filter
*)cb_data
;
85 if (filter
&& !ref_filter_match(refname
,
86 filter
->include_ref_pattern
,
87 filter
->exclude_ref_pattern
))
90 if (starts_with(refname
, git_replace_ref_base
)) {
91 struct object_id original_oid
;
92 if (!check_replace_refs
)
94 if (get_oid_hex(refname
+ strlen(git_replace_ref_base
),
96 warning("invalid replace ref %s", refname
);
99 obj
= parse_object(&original_oid
);
101 add_name_decoration(DECORATION_GRAFTED
, "replaced", obj
);
105 obj
= parse_object(oid
);
109 if (starts_with(refname
, "refs/heads/"))
110 type
= DECORATION_REF_LOCAL
;
111 else if (starts_with(refname
, "refs/remotes/"))
112 type
= DECORATION_REF_REMOTE
;
113 else if (starts_with(refname
, "refs/tags/"))
114 type
= DECORATION_REF_TAG
;
115 else if (!strcmp(refname
, "refs/stash"))
116 type
= DECORATION_REF_STASH
;
117 else if (!strcmp(refname
, "HEAD"))
118 type
= DECORATION_REF_HEAD
;
120 add_name_decoration(type
, refname
, obj
);
121 while (obj
->type
== OBJ_TAG
) {
122 obj
= ((struct tag
*)obj
)->tagged
;
126 parse_object(&obj
->oid
);
127 add_name_decoration(DECORATION_REF_TAG
, refname
, obj
);
132 static int add_graft_decoration(const struct commit_graft
*graft
, void *cb_data
)
134 struct commit
*commit
= lookup_commit(&graft
->oid
);
137 add_name_decoration(DECORATION_GRAFTED
, "grafted", &commit
->object
);
141 void load_ref_decorations(struct decoration_filter
*filter
, int flags
)
143 if (!decoration_loaded
) {
145 struct string_list_item
*item
;
146 for_each_string_list_item(item
, filter
->exclude_ref_pattern
) {
147 normalize_glob_ref(item
, NULL
, item
->string
);
149 for_each_string_list_item(item
, filter
->include_ref_pattern
) {
150 normalize_glob_ref(item
, NULL
, item
->string
);
153 decoration_loaded
= 1;
154 decoration_flags
= flags
;
155 for_each_ref(add_ref_decoration
, filter
);
156 head_ref(add_ref_decoration
, filter
);
157 for_each_commit_graft(add_graft_decoration
, filter
);
161 static void show_parents(struct commit
*commit
, int abbrev
, FILE *file
)
163 struct commit_list
*p
;
164 for (p
= commit
->parents
; p
; p
= p
->next
) {
165 struct commit
*parent
= p
->item
;
166 fprintf(file
, " %s", find_unique_abbrev(&parent
->object
.oid
, abbrev
));
170 static void show_children(struct rev_info
*opt
, struct commit
*commit
, int abbrev
)
172 struct commit_list
*p
= lookup_decoration(&opt
->children
, &commit
->object
);
173 for ( ; p
; p
= p
->next
) {
174 fprintf(opt
->diffopt
.file
, " %s", find_unique_abbrev(&p
->item
->object
.oid
, abbrev
));
179 * Do we have HEAD in the output, and also the branch it points at?
180 * If so, find that decoration entry for that current branch.
182 static const struct name_decoration
*current_pointed_by_HEAD(const struct name_decoration
*decoration
)
184 const struct name_decoration
*list
, *head
= NULL
;
185 const char *branch_name
= NULL
;
188 /* First find HEAD */
189 for (list
= decoration
; list
; list
= list
->next
)
190 if (list
->type
== DECORATION_REF_HEAD
) {
197 /* Now resolve and find the matching current branch */
198 branch_name
= resolve_ref_unsafe("HEAD", 0, NULL
, &rru_flags
);
199 if (!branch_name
|| !(rru_flags
& REF_ISSYMREF
))
202 if (!starts_with(branch_name
, "refs/"))
205 /* OK, do we have that ref in the list? */
206 for (list
= decoration
; list
; list
= list
->next
)
207 if ((list
->type
== DECORATION_REF_LOCAL
) &&
208 !strcmp(branch_name
, list
->name
)) {
215 static void show_name(struct strbuf
*sb
, const struct name_decoration
*decoration
)
217 if (decoration_flags
== DECORATE_SHORT_REFS
)
218 strbuf_addstr(sb
, prettify_refname(decoration
->name
));
220 strbuf_addstr(sb
, decoration
->name
);
224 * The caller makes sure there is no funny color before calling.
225 * format_decorations_extended makes sure the same after return.
227 void format_decorations_extended(struct strbuf
*sb
,
228 const struct commit
*commit
,
231 const char *separator
,
234 const struct name_decoration
*decoration
;
235 const struct name_decoration
*current_and_HEAD
;
236 const char *color_commit
=
237 diff_get_color(use_color
, DIFF_COMMIT
);
238 const char *color_reset
=
239 decorate_get_color(use_color
, DECORATION_NONE
);
241 decoration
= get_name_decoration(&commit
->object
);
245 current_and_HEAD
= current_pointed_by_HEAD(decoration
);
248 * When both current and HEAD are there, only
249 * show HEAD->current where HEAD would have
250 * appeared, skipping the entry for current.
252 if (decoration
!= current_and_HEAD
) {
253 strbuf_addstr(sb
, color_commit
);
254 strbuf_addstr(sb
, prefix
);
255 strbuf_addstr(sb
, color_reset
);
256 strbuf_addstr(sb
, decorate_get_color(use_color
, decoration
->type
));
257 if (decoration
->type
== DECORATION_REF_TAG
)
258 strbuf_addstr(sb
, "tag: ");
260 show_name(sb
, decoration
);
262 if (current_and_HEAD
&&
263 decoration
->type
== DECORATION_REF_HEAD
) {
264 strbuf_addstr(sb
, " -> ");
265 strbuf_addstr(sb
, color_reset
);
266 strbuf_addstr(sb
, decorate_get_color(use_color
, current_and_HEAD
->type
));
267 show_name(sb
, current_and_HEAD
);
269 strbuf_addstr(sb
, color_reset
);
273 decoration
= decoration
->next
;
275 strbuf_addstr(sb
, color_commit
);
276 strbuf_addstr(sb
, suffix
);
277 strbuf_addstr(sb
, color_reset
);
280 void show_decorations(struct rev_info
*opt
, struct commit
*commit
)
282 struct strbuf sb
= STRBUF_INIT
;
284 if (opt
->show_source
&& commit
->util
)
285 fprintf(opt
->diffopt
.file
, "\t%s", (char *) commit
->util
);
286 if (!opt
->show_decorations
)
288 format_decorations(&sb
, commit
, opt
->diffopt
.use_color
);
289 fputs(sb
.buf
, opt
->diffopt
.file
);
293 static unsigned int digits_in_number(unsigned int number
)
295 unsigned int i
= 10, result
= 1;
296 while (i
<= number
) {
303 void fmt_output_subject(struct strbuf
*filename
,
305 struct rev_info
*info
)
307 const char *suffix
= info
->patch_suffix
;
309 int start_len
= filename
->len
;
310 int max_len
= start_len
+ FORMAT_PATCH_NAME_MAX
- (strlen(suffix
) + 1);
312 if (0 < info
->reroll_count
)
313 strbuf_addf(filename
, "v%d-", info
->reroll_count
);
314 strbuf_addf(filename
, "%04d-%s", nr
, subject
);
316 if (max_len
< filename
->len
)
317 strbuf_setlen(filename
, max_len
);
318 strbuf_addstr(filename
, suffix
);
321 void fmt_output_commit(struct strbuf
*filename
,
322 struct commit
*commit
,
323 struct rev_info
*info
)
325 struct pretty_print_context ctx
= {0};
326 struct strbuf subject
= STRBUF_INIT
;
328 format_commit_message(commit
, "%f", &subject
, &ctx
);
329 fmt_output_subject(filename
, subject
.buf
, info
);
330 strbuf_release(&subject
);
333 void fmt_output_email_subject(struct strbuf
*sb
, struct rev_info
*opt
)
335 if (opt
->total
> 0) {
336 strbuf_addf(sb
, "Subject: [%s%s%0*d/%d] ",
338 *opt
->subject_prefix
? " " : "",
339 digits_in_number(opt
->total
),
340 opt
->nr
, opt
->total
);
341 } else if (opt
->total
== 0 && opt
->subject_prefix
&& *opt
->subject_prefix
) {
342 strbuf_addf(sb
, "Subject: [%s] ",
343 opt
->subject_prefix
);
345 strbuf_addstr(sb
, "Subject: ");
349 void log_write_email_headers(struct rev_info
*opt
, struct commit
*commit
,
350 const char **extra_headers_p
,
351 int *need_8bit_cte_p
,
354 const char *extra_headers
= opt
->extra_headers
;
355 const char *name
= oid_to_hex(opt
->zero_commit
?
356 &null_oid
: &commit
->object
.oid
);
358 *need_8bit_cte_p
= 0; /* unknown */
360 fprintf(opt
->diffopt
.file
, "From %s Mon Sep 17 00:00:00 2001\n", name
);
361 graph_show_oneline(opt
->graph
);
362 if (opt
->message_id
) {
363 fprintf(opt
->diffopt
.file
, "Message-Id: <%s>\n", opt
->message_id
);
364 graph_show_oneline(opt
->graph
);
366 if (opt
->ref_message_ids
&& opt
->ref_message_ids
->nr
> 0) {
368 n
= opt
->ref_message_ids
->nr
;
369 fprintf(opt
->diffopt
.file
, "In-Reply-To: <%s>\n", opt
->ref_message_ids
->items
[n
-1].string
);
370 for (i
= 0; i
< n
; i
++)
371 fprintf(opt
->diffopt
.file
, "%s<%s>\n", (i
> 0 ? "\t" : "References: "),
372 opt
->ref_message_ids
->items
[i
].string
);
373 graph_show_oneline(opt
->graph
);
375 if (opt
->mime_boundary
&& maybe_multipart
) {
376 static char subject_buffer
[1024];
377 static char buffer
[1024];
378 struct strbuf filename
= STRBUF_INIT
;
379 *need_8bit_cte_p
= -1; /* NEVER */
380 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
382 "MIME-Version: 1.0\n"
383 "Content-Type: multipart/mixed;"
384 " boundary=\"%s%s\"\n"
386 "This is a multi-part message in MIME "
389 "Content-Type: text/plain; "
390 "charset=UTF-8; format=fixed\n"
391 "Content-Transfer-Encoding: 8bit\n\n",
392 extra_headers
? extra_headers
: "",
393 mime_boundary_leader
, opt
->mime_boundary
,
394 mime_boundary_leader
, opt
->mime_boundary
);
395 extra_headers
= subject_buffer
;
397 if (opt
->numbered_files
)
398 strbuf_addf(&filename
, "%d", opt
->nr
);
400 fmt_output_commit(&filename
, commit
, opt
);
401 snprintf(buffer
, sizeof(buffer
) - 1,
403 "Content-Type: text/x-patch;"
405 "Content-Transfer-Encoding: 8bit\n"
406 "Content-Disposition: %s;"
407 " filename=\"%s\"\n\n",
408 mime_boundary_leader
, opt
->mime_boundary
,
410 opt
->no_inline
? "attachment" : "inline",
412 opt
->diffopt
.stat_sep
= buffer
;
413 strbuf_release(&filename
);
415 *extra_headers_p
= extra_headers
;
418 static void show_sig_lines(struct rev_info
*opt
, int status
, const char *bol
)
420 const char *color
, *reset
, *eol
;
422 color
= diff_get_color_opt(&opt
->diffopt
,
423 status
? DIFF_WHITESPACE
: DIFF_FRAGINFO
);
424 reset
= diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
);
426 eol
= strchrnul(bol
, '\n');
427 fprintf(opt
->diffopt
.file
, "%s%.*s%s%s", color
, (int)(eol
- bol
), bol
, reset
,
429 graph_show_oneline(opt
->graph
);
430 bol
= (*eol
) ? (eol
+ 1) : eol
;
434 static void show_signature(struct rev_info
*opt
, struct commit
*commit
)
436 struct strbuf payload
= STRBUF_INIT
;
437 struct strbuf signature
= STRBUF_INIT
;
438 struct strbuf gpg_output
= STRBUF_INIT
;
441 if (parse_signed_commit(commit
, &payload
, &signature
) <= 0)
444 status
= verify_signed_buffer(payload
.buf
, payload
.len
,
445 signature
.buf
, signature
.len
,
447 if (status
&& !gpg_output
.len
)
448 strbuf_addstr(&gpg_output
, "No signature\n");
450 show_sig_lines(opt
, status
, gpg_output
.buf
);
453 strbuf_release(&gpg_output
);
454 strbuf_release(&payload
);
455 strbuf_release(&signature
);
458 static int which_parent(const struct object_id
*oid
, const struct commit
*commit
)
461 const struct commit_list
*parent
;
463 for (nth
= 0, parent
= commit
->parents
; parent
; parent
= parent
->next
) {
464 if (!oidcmp(&parent
->item
->object
.oid
, oid
))
471 static int is_common_merge(const struct commit
*commit
)
473 return (commit
->parents
474 && commit
->parents
->next
475 && !commit
->parents
->next
->next
);
478 static int show_one_mergetag(struct commit
*commit
,
479 struct commit_extra_header
*extra
,
482 struct rev_info
*opt
= (struct rev_info
*)data
;
483 struct object_id oid
;
485 struct strbuf verify_message
;
487 size_t payload_size
, gpg_message_offset
;
489 hash_object_file(extra
->value
, extra
->len
, type_name(OBJ_TAG
), &oid
);
490 tag
= lookup_tag(&oid
);
492 return -1; /* error message already given */
494 strbuf_init(&verify_message
, 256);
495 if (parse_tag_buffer(tag
, extra
->value
, extra
->len
))
496 strbuf_addstr(&verify_message
, "malformed mergetag\n");
497 else if (is_common_merge(commit
) &&
498 !oidcmp(&tag
->tagged
->oid
,
499 &commit
->parents
->next
->item
->object
.oid
))
500 strbuf_addf(&verify_message
,
501 "merged tag '%s'\n", tag
->tag
);
502 else if ((nth
= which_parent(&tag
->tagged
->oid
, commit
)) < 0)
503 strbuf_addf(&verify_message
, "tag %s names a non-parent %s\n",
504 tag
->tag
, tag
->tagged
->oid
.hash
);
506 strbuf_addf(&verify_message
,
507 "parent #%d, tagged '%s'\n", nth
+ 1, tag
->tag
);
508 gpg_message_offset
= verify_message
.len
;
510 payload_size
= parse_signature(extra
->value
, extra
->len
);
512 if (extra
->len
> payload_size
) {
513 /* could have a good signature */
514 if (!verify_signed_buffer(extra
->value
, payload_size
,
515 extra
->value
+ payload_size
,
516 extra
->len
- payload_size
,
517 &verify_message
, NULL
))
518 status
= 0; /* good */
519 else if (verify_message
.len
<= gpg_message_offset
)
520 strbuf_addstr(&verify_message
, "No signature\n");
521 /* otherwise we couldn't verify, which is shown as bad */
524 show_sig_lines(opt
, status
, verify_message
.buf
);
525 strbuf_release(&verify_message
);
529 static int show_mergetag(struct rev_info
*opt
, struct commit
*commit
)
531 return 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
, 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
,
601 &ctx
.need_8bit_cte
, 1);
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
,
614 if (opt
->print_parents
)
615 show_parents(commit
, abbrev_commit
, opt
->diffopt
.file
);
616 if (opt
->children
.name
)
617 show_children(opt
, commit
, abbrev_commit
);
619 fprintf(opt
->diffopt
.file
, " (from %s)",
620 find_unique_abbrev(&parent
->object
.oid
, abbrev_commit
));
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 (opt
->show_notes
) {
652 struct strbuf notebuf
= STRBUF_INIT
;
654 raw
= (opt
->commit_format
== CMIT_FMT_USERFORMAT
);
655 format_display_notes(&commit
->object
.oid
, ¬ebuf
,
656 get_log_output_encoding(), raw
);
657 ctx
.notes_message
= notebuf
.len
658 ? strbuf_detach(¬ebuf
, NULL
)
663 * And then the pretty-printed message itself
665 if (ctx
.need_8bit_cte
>= 0 && opt
->add_signoff
)
667 has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"),
668 getenv("GIT_COMMITTER_EMAIL")));
669 ctx
.date_mode
= opt
->date_mode
;
670 ctx
.date_mode_explicit
= opt
->date_mode_explicit
;
671 ctx
.abbrev
= opt
->diffopt
.abbrev
;
672 ctx
.after_subject
= extra_headers
;
673 ctx
.preserve_subject
= opt
->preserve_subject
;
674 ctx
.reflog_info
= opt
->reflog_info
;
675 ctx
.fmt
= opt
->commit_format
;
676 ctx
.mailmap
= opt
->mailmap
;
677 ctx
.color
= opt
->diffopt
.use_color
;
678 ctx
.expand_tabs_in_log
= opt
->expand_tabs_in_log
;
679 ctx
.output_encoding
= get_log_output_encoding();
680 if (opt
->from_ident
.mail_begin
&& opt
->from_ident
.name_begin
)
681 ctx
.from_ident
= &opt
->from_ident
;
683 ctx
.graph_width
= graph_width(opt
->graph
);
684 pretty_print_commit(&ctx
, commit
, &msgbuf
);
686 if (opt
->add_signoff
)
687 append_signoff(&msgbuf
, 0, APPEND_SIGNOFF_DEDUP
);
689 if ((ctx
.fmt
!= CMIT_FMT_USERFORMAT
) &&
690 ctx
.notes_message
&& *ctx
.notes_message
) {
691 if (cmit_fmt_is_mail(ctx
.fmt
)) {
692 strbuf_addstr(&msgbuf
, "---\n");
693 opt
->shown_dashes
= 1;
695 strbuf_addstr(&msgbuf
, ctx
.notes_message
);
698 if (opt
->show_log_size
) {
699 fprintf(opt
->diffopt
.file
, "log size %i\n", (int)msgbuf
.len
);
700 graph_show_oneline(opt
->graph
);
704 * Set opt->missing_newline if msgbuf doesn't
705 * end in a newline (including if it is empty)
707 if (!msgbuf
.len
|| msgbuf
.buf
[msgbuf
.len
- 1] != '\n')
708 opt
->missing_newline
= 1;
710 opt
->missing_newline
= 0;
712 graph_show_commit_msg(opt
->graph
, opt
->diffopt
.file
, &msgbuf
);
713 if (opt
->use_terminator
&& !commit_format_is_empty(opt
->commit_format
)) {
714 if (!opt
->missing_newline
)
715 graph_show_padding(opt
->graph
);
716 putc(opt
->diffopt
.line_termination
, opt
->diffopt
.file
);
719 strbuf_release(&msgbuf
);
720 free(ctx
.notes_message
);
723 int log_tree_diff_flush(struct rev_info
*opt
)
725 opt
->shown_dashes
= 0;
726 diffcore_std(&opt
->diffopt
);
728 if (diff_queue_is_empty()) {
729 int saved_fmt
= opt
->diffopt
.output_format
;
730 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
731 diff_flush(&opt
->diffopt
);
732 opt
->diffopt
.output_format
= saved_fmt
;
736 if (opt
->loginfo
&& !opt
->no_commit_id
) {
738 if ((opt
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
) &&
739 opt
->verbose_header
&&
740 opt
->commit_format
!= CMIT_FMT_ONELINE
&&
741 !commit_format_is_empty(opt
->commit_format
)) {
743 * When showing a verbose header (i.e. log message),
744 * and not in --pretty=oneline format, we would want
745 * an extra newline between the end of log and the
746 * diff/diffstat output for readability.
748 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
749 if (opt
->diffopt
.output_prefix
) {
750 struct strbuf
*msg
= NULL
;
751 msg
= opt
->diffopt
.output_prefix(&opt
->diffopt
,
752 opt
->diffopt
.output_prefix_data
);
753 fwrite(msg
->buf
, msg
->len
, 1, opt
->diffopt
.file
);
757 * We may have shown three-dashes line early
758 * between notes and the log message, in which
759 * case we only want a blank line after the
760 * notes without (an extra) three-dashes line.
761 * Otherwise, we show the three-dashes line if
762 * we are showing the patch with diffstat, but
763 * in that case, there is no extra blank line
764 * after the three-dashes line.
766 if (!opt
->shown_dashes
&&
767 (pch
& opt
->diffopt
.output_format
) == pch
)
768 fprintf(opt
->diffopt
.file
, "---");
769 putc('\n', opt
->diffopt
.file
);
772 diff_flush(&opt
->diffopt
);
776 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
778 diff_tree_combined_merge(commit
, opt
->dense_combined_merges
, opt
);
779 return !opt
->loginfo
;
783 * Show the diff of a commit.
785 * Return true if we printed any log info messages
787 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
790 struct commit_list
*parents
;
791 struct object_id
*oid
;
793 if (!opt
->diff
&& !opt
->diffopt
.flags
.exit_with_status
)
796 parse_commit_or_die(commit
);
797 oid
= get_commit_tree_oid(commit
);
800 parents
= get_saved_parents(opt
, commit
);
802 if (opt
->show_root_diff
) {
803 diff_root_tree_oid(oid
, "", &opt
->diffopt
);
804 log_tree_diff_flush(opt
);
806 return !opt
->loginfo
;
809 /* More than one parent? */
810 if (parents
&& parents
->next
) {
811 if (opt
->ignore_merges
)
813 else if (opt
->combine_merges
)
814 return do_diff_combined(opt
, commit
);
815 else if (opt
->first_parent_only
) {
817 * Generate merge log entry only for the first
818 * parent, showing summary diff of the others
821 parse_commit_or_die(parents
->item
);
822 diff_tree_oid(get_commit_tree_oid(parents
->item
),
823 oid
, "", &opt
->diffopt
);
824 log_tree_diff_flush(opt
);
825 return !opt
->loginfo
;
828 /* If we show individual diffs, show the parent info */
829 log
->parent
= parents
->item
;
834 struct commit
*parent
= parents
->item
;
836 parse_commit_or_die(parent
);
837 diff_tree_oid(get_commit_tree_oid(parent
),
838 oid
, "", &opt
->diffopt
);
839 log_tree_diff_flush(opt
);
841 showed_log
|= !opt
->loginfo
;
843 /* Set up the log info for the next parent, if any.. */
844 parents
= parents
->next
;
847 log
->parent
= parents
->item
;
853 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
856 int shown
, close_file
= opt
->diffopt
.close_file
;
861 opt
->diffopt
.close_file
= 0;
863 if (opt
->line_level_traverse
)
864 return line_log_print(opt
, commit
);
866 if (opt
->track_linear
&& !opt
->linear
&& !opt
->reverse_output_stage
)
867 fprintf(opt
->diffopt
.file
, "\n%s\n", opt
->break_bar
);
868 shown
= log_tree_diff(opt
, commit
, &log
);
869 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {
874 if (opt
->track_linear
&& !opt
->linear
&& opt
->reverse_output_stage
)
875 fprintf(opt
->diffopt
.file
, "\n%s\n", opt
->break_bar
);
877 maybe_flush_or_die(opt
->diffopt
.file
, "stdout");
879 fclose(opt
->diffopt
.file
);