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 int nlen
= strlen(name
);
81 struct name_decoration
*res
= xmalloc(sizeof(*res
) + nlen
+ 1);
82 memcpy(res
->name
, name
, nlen
+ 1);
84 res
->next
= add_decoration(&name_decoration
, obj
, res
);
87 const struct name_decoration
*get_name_decoration(const struct object
*obj
)
89 return lookup_decoration(&name_decoration
, obj
);
92 static int add_ref_decoration(const char *refname
, const unsigned char *sha1
, int flags
, void *cb_data
)
95 enum decoration_type type
= DECORATION_NONE
;
97 assert(cb_data
== NULL
);
99 if (starts_with(refname
, "refs/replace/")) {
100 unsigned char original_sha1
[20];
101 if (!check_replace_refs
)
103 if (get_sha1_hex(refname
+ 13, original_sha1
)) {
104 warning("invalid replace ref %s", refname
);
107 obj
= parse_object(original_sha1
);
109 add_name_decoration(DECORATION_GRAFTED
, "replaced", obj
);
113 obj
= parse_object(sha1
);
117 if (starts_with(refname
, "refs/heads/"))
118 type
= DECORATION_REF_LOCAL
;
119 else if (starts_with(refname
, "refs/remotes/"))
120 type
= DECORATION_REF_REMOTE
;
121 else if (starts_with(refname
, "refs/tags/"))
122 type
= DECORATION_REF_TAG
;
123 else if (!strcmp(refname
, "refs/stash"))
124 type
= DECORATION_REF_STASH
;
125 else if (!strcmp(refname
, "HEAD"))
126 type
= DECORATION_REF_HEAD
;
128 add_name_decoration(type
, refname
, obj
);
129 while (obj
->type
== OBJ_TAG
) {
130 obj
= ((struct tag
*)obj
)->tagged
;
134 parse_object(obj
->sha1
);
135 add_name_decoration(DECORATION_REF_TAG
, refname
, obj
);
140 static int add_graft_decoration(const struct commit_graft
*graft
, void *cb_data
)
142 struct commit
*commit
= lookup_commit(graft
->sha1
);
145 add_name_decoration(DECORATION_GRAFTED
, "grafted", &commit
->object
);
149 void load_ref_decorations(int flags
)
151 if (!decoration_loaded
) {
152 decoration_loaded
= 1;
153 decoration_flags
= flags
;
154 for_each_ref(add_ref_decoration
, NULL
);
155 head_ref(add_ref_decoration
, NULL
);
156 for_each_commit_graft(add_graft_decoration
, NULL
);
160 static void show_parents(struct commit
*commit
, int abbrev
)
162 struct commit_list
*p
;
163 for (p
= commit
->parents
; p
; p
= p
->next
) {
164 struct commit
*parent
= p
->item
;
165 printf(" %s", find_unique_abbrev(parent
->object
.sha1
, abbrev
));
169 static void show_children(struct rev_info
*opt
, struct commit
*commit
, int abbrev
)
171 struct commit_list
*p
= lookup_decoration(&opt
->children
, &commit
->object
);
172 for ( ; p
; p
= p
->next
) {
173 printf(" %s", find_unique_abbrev(p
->item
->object
.sha1
, abbrev
));
178 * Do we have HEAD in the output, and also the branch it points at?
179 * If so, find that decoration entry for that current branch.
181 static const struct name_decoration
*current_pointed_by_HEAD(const struct name_decoration
*decoration
)
183 const struct name_decoration
*list
, *head
= NULL
;
184 const char *branch_name
= NULL
;
185 unsigned char unused
[20];
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, unused
, &rru_flags
);
199 if (!(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
, color_reset
);
265 strbuf_addstr(sb
, color_commit
);
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 printf("\t%s", (char *) commit
->util
);
288 if (!opt
->show_decorations
)
290 format_decorations(&sb
, commit
, opt
->diffopt
.use_color
);
291 fputs(sb
.buf
, stdout
);
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 log_write_email_headers(struct rev_info
*opt
, struct commit
*commit
,
336 const char **subject_p
,
337 const char **extra_headers_p
,
338 int *need_8bit_cte_p
)
340 const char *subject
= NULL
;
341 const char *extra_headers
= opt
->extra_headers
;
342 const char *name
= sha1_to_hex(commit
->object
.sha1
);
344 *need_8bit_cte_p
= 0; /* unknown */
345 if (opt
->total
> 0) {
346 static char buffer
[64];
347 snprintf(buffer
, sizeof(buffer
),
348 "Subject: [%s%s%0*d/%d] ",
350 *opt
->subject_prefix
? " " : "",
351 digits_in_number(opt
->total
),
352 opt
->nr
, opt
->total
);
354 } else if (opt
->total
== 0 && opt
->subject_prefix
&& *opt
->subject_prefix
) {
355 static char buffer
[256];
356 snprintf(buffer
, sizeof(buffer
),
358 opt
->subject_prefix
);
361 subject
= "Subject: ";
364 printf("From %s Mon Sep 17 00:00:00 2001\n", name
);
365 graph_show_oneline(opt
->graph
);
366 if (opt
->message_id
) {
367 printf("Message-Id: <%s>\n", opt
->message_id
);
368 graph_show_oneline(opt
->graph
);
370 if (opt
->ref_message_ids
&& opt
->ref_message_ids
->nr
> 0) {
372 n
= opt
->ref_message_ids
->nr
;
373 printf("In-Reply-To: <%s>\n", opt
->ref_message_ids
->items
[n
-1].string
);
374 for (i
= 0; i
< n
; i
++)
375 printf("%s<%s>\n", (i
> 0 ? "\t" : "References: "),
376 opt
->ref_message_ids
->items
[i
].string
);
377 graph_show_oneline(opt
->graph
);
379 if (opt
->mime_boundary
) {
380 static char subject_buffer
[1024];
381 static char buffer
[1024];
382 struct strbuf filename
= STRBUF_INIT
;
383 *need_8bit_cte_p
= -1; /* NEVER */
384 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
386 "MIME-Version: 1.0\n"
387 "Content-Type: multipart/mixed;"
388 " boundary=\"%s%s\"\n"
390 "This is a multi-part message in MIME "
393 "Content-Type: text/plain; "
394 "charset=UTF-8; format=fixed\n"
395 "Content-Transfer-Encoding: 8bit\n\n",
396 extra_headers
? extra_headers
: "",
397 mime_boundary_leader
, opt
->mime_boundary
,
398 mime_boundary_leader
, opt
->mime_boundary
);
399 extra_headers
= subject_buffer
;
401 if (opt
->numbered_files
)
402 strbuf_addf(&filename
, "%d", opt
->nr
);
404 fmt_output_commit(&filename
, commit
, opt
);
405 snprintf(buffer
, sizeof(buffer
) - 1,
407 "Content-Type: text/x-patch;"
409 "Content-Transfer-Encoding: 8bit\n"
410 "Content-Disposition: %s;"
411 " filename=\"%s\"\n\n",
412 mime_boundary_leader
, opt
->mime_boundary
,
414 opt
->no_inline
? "attachment" : "inline",
416 opt
->diffopt
.stat_sep
= buffer
;
417 strbuf_release(&filename
);
419 *subject_p
= subject
;
420 *extra_headers_p
= extra_headers
;
423 static void show_sig_lines(struct rev_info
*opt
, int status
, const char *bol
)
425 const char *color
, *reset
, *eol
;
427 color
= diff_get_color_opt(&opt
->diffopt
,
428 status
? DIFF_WHITESPACE
: DIFF_FRAGINFO
);
429 reset
= diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
);
431 eol
= strchrnul(bol
, '\n');
432 printf("%s%.*s%s%s", color
, (int)(eol
- bol
), bol
, reset
,
434 graph_show_oneline(opt
->graph
);
435 bol
= (*eol
) ? (eol
+ 1) : eol
;
439 static void show_signature(struct rev_info
*opt
, struct commit
*commit
)
441 struct strbuf payload
= STRBUF_INIT
;
442 struct strbuf signature
= STRBUF_INIT
;
443 struct strbuf gpg_output
= STRBUF_INIT
;
446 if (parse_signed_commit(commit
, &payload
, &signature
) <= 0)
449 status
= verify_signed_buffer(payload
.buf
, payload
.len
,
450 signature
.buf
, signature
.len
,
452 if (status
&& !gpg_output
.len
)
453 strbuf_addstr(&gpg_output
, "No signature\n");
455 show_sig_lines(opt
, status
, gpg_output
.buf
);
458 strbuf_release(&gpg_output
);
459 strbuf_release(&payload
);
460 strbuf_release(&signature
);
463 static int which_parent(const unsigned char *sha1
, const struct commit
*commit
)
466 const struct commit_list
*parent
;
468 for (nth
= 0, parent
= commit
->parents
; parent
; parent
= parent
->next
) {
469 if (!hashcmp(parent
->item
->object
.sha1
, sha1
))
476 static int is_common_merge(const struct commit
*commit
)
478 return (commit
->parents
479 && commit
->parents
->next
480 && !commit
->parents
->next
->next
);
483 static void show_one_mergetag(struct commit
*commit
,
484 struct commit_extra_header
*extra
,
487 struct rev_info
*opt
= (struct rev_info
*)data
;
488 unsigned char sha1
[20];
490 struct strbuf verify_message
;
492 size_t payload_size
, gpg_message_offset
;
494 hash_sha1_file(extra
->value
, extra
->len
, typename(OBJ_TAG
), sha1
);
495 tag
= lookup_tag(sha1
);
497 return; /* error message already given */
499 strbuf_init(&verify_message
, 256);
500 if (parse_tag_buffer(tag
, extra
->value
, extra
->len
))
501 strbuf_addstr(&verify_message
, "malformed mergetag\n");
502 else if (is_common_merge(commit
) &&
503 !hashcmp(tag
->tagged
->sha1
,
504 commit
->parents
->next
->item
->object
.sha1
))
505 strbuf_addf(&verify_message
,
506 "merged tag '%s'\n", tag
->tag
);
507 else if ((nth
= which_parent(tag
->tagged
->sha1
, commit
)) < 0)
508 strbuf_addf(&verify_message
, "tag %s names a non-parent %s\n",
509 tag
->tag
, tag
->tagged
->sha1
);
511 strbuf_addf(&verify_message
,
512 "parent #%d, tagged '%s'\n", nth
+ 1, tag
->tag
);
513 gpg_message_offset
= verify_message
.len
;
515 payload_size
= parse_signature(extra
->value
, extra
->len
);
517 if (extra
->len
> payload_size
) {
518 /* could have a good signature */
519 if (!verify_signed_buffer(extra
->value
, payload_size
,
520 extra
->value
+ payload_size
,
521 extra
->len
- payload_size
,
522 &verify_message
, NULL
))
523 status
= 0; /* good */
524 else if (verify_message
.len
<= gpg_message_offset
)
525 strbuf_addstr(&verify_message
, "No signature\n");
526 /* otherwise we couldn't verify, which is shown as bad */
529 show_sig_lines(opt
, status
, verify_message
.buf
);
530 strbuf_release(&verify_message
);
533 static void show_mergetag(struct rev_info
*opt
, struct commit
*commit
)
535 for_each_mergetag(show_one_mergetag
, commit
, opt
);
538 void show_log(struct rev_info
*opt
)
540 struct strbuf msgbuf
= STRBUF_INIT
;
541 struct log_info
*log
= opt
->loginfo
;
542 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
543 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: 40;
544 const char *extra_headers
= opt
->extra_headers
;
545 struct pretty_print_context ctx
= {0};
548 if (!opt
->verbose_header
) {
549 graph_show_commit(opt
->graph
);
552 put_revision_mark(opt
, commit
);
553 fputs(find_unique_abbrev(commit
->object
.sha1
, abbrev_commit
), stdout
);
554 if (opt
->print_parents
)
555 show_parents(commit
, abbrev_commit
);
556 if (opt
->children
.name
)
557 show_children(opt
, commit
, abbrev_commit
);
558 show_decorations(opt
, commit
);
559 if (opt
->graph
&& !graph_is_commit_finished(opt
->graph
)) {
561 graph_show_remainder(opt
->graph
);
563 putchar(opt
->diffopt
.line_termination
);
568 * If use_terminator is set, we already handled any record termination
569 * at the end of the last record.
570 * Otherwise, add a diffopt.line_termination character before all
571 * entries but the first. (IOW, as a separator between entries)
573 if (opt
->shown_one
&& !opt
->use_terminator
) {
575 * If entries are separated by a newline, the output
576 * should look human-readable. If the last entry ended
577 * with a newline, print the graph output before this
578 * newline. Otherwise it will end up as a completely blank
579 * line and will look like a gap in the graph.
581 * If the entry separator is not a newline, the output is
582 * primarily intended for programmatic consumption, and we
583 * never want the extra graph output before the entry
586 if (opt
->diffopt
.line_termination
== '\n' &&
587 !opt
->missing_newline
)
588 graph_show_padding(opt
->graph
);
589 putchar(opt
->diffopt
.line_termination
);
594 * If the history graph was requested,
595 * print the graph, up to this commit's line
597 graph_show_commit(opt
->graph
);
600 * Print header line of header..
603 if (opt
->commit_format
== CMIT_FMT_EMAIL
) {
604 log_write_email_headers(opt
, commit
, &ctx
.subject
, &extra_headers
,
606 } else if (opt
->commit_format
!= CMIT_FMT_USERFORMAT
) {
607 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_COMMIT
), stdout
);
608 if (opt
->commit_format
!= CMIT_FMT_ONELINE
)
609 fputs("commit ", stdout
);
612 put_revision_mark(opt
, commit
);
613 fputs(find_unique_abbrev(commit
->object
.sha1
, abbrev_commit
),
615 if (opt
->print_parents
)
616 show_parents(commit
, abbrev_commit
);
617 if (opt
->children
.name
)
618 show_children(opt
, commit
, abbrev_commit
);
621 find_unique_abbrev(parent
->object
.sha1
,
623 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
), stdout
);
624 show_decorations(opt
, commit
);
625 if (opt
->commit_format
== CMIT_FMT_ONELINE
) {
629 graph_show_oneline(opt
->graph
);
631 if (opt
->reflog_info
) {
633 * setup_revisions() ensures that opt->reflog_info
634 * and opt->graph cannot both be set,
635 * so we don't need to worry about printing the
638 show_reflog_message(opt
->reflog_info
,
639 opt
->commit_format
== CMIT_FMT_ONELINE
,
641 opt
->date_mode_explicit
);
642 if (opt
->commit_format
== CMIT_FMT_ONELINE
)
647 if (opt
->show_signature
) {
648 show_signature(opt
, commit
);
649 show_mergetag(opt
, commit
);
652 if (!get_cached_commit_buffer(commit
, NULL
))
655 if (opt
->show_notes
) {
657 struct strbuf notebuf
= STRBUF_INIT
;
659 raw
= (opt
->commit_format
== CMIT_FMT_USERFORMAT
);
660 format_display_notes(commit
->object
.sha1
, ¬ebuf
,
661 get_log_output_encoding(), raw
);
662 ctx
.notes_message
= notebuf
.len
663 ? strbuf_detach(¬ebuf
, NULL
)
668 * And then the pretty-printed message itself
670 if (ctx
.need_8bit_cte
>= 0 && opt
->add_signoff
)
672 has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"),
673 getenv("GIT_COMMITTER_EMAIL")));
674 ctx
.date_mode
= opt
->date_mode
;
675 ctx
.date_mode_explicit
= opt
->date_mode_explicit
;
676 ctx
.abbrev
= opt
->diffopt
.abbrev
;
677 ctx
.after_subject
= extra_headers
;
678 ctx
.preserve_subject
= opt
->preserve_subject
;
679 ctx
.reflog_info
= opt
->reflog_info
;
680 ctx
.fmt
= opt
->commit_format
;
681 ctx
.mailmap
= opt
->mailmap
;
682 ctx
.color
= opt
->diffopt
.use_color
;
683 ctx
.output_encoding
= get_log_output_encoding();
684 if (opt
->from_ident
.mail_begin
&& opt
->from_ident
.name_begin
)
685 ctx
.from_ident
= &opt
->from_ident
;
686 pretty_print_commit(&ctx
, commit
, &msgbuf
);
688 if (opt
->add_signoff
)
689 append_signoff(&msgbuf
, 0, APPEND_SIGNOFF_DEDUP
);
691 if ((ctx
.fmt
!= CMIT_FMT_USERFORMAT
) &&
692 ctx
.notes_message
&& *ctx
.notes_message
) {
693 if (ctx
.fmt
== CMIT_FMT_EMAIL
) {
694 strbuf_addstr(&msgbuf
, "---\n");
695 opt
->shown_dashes
= 1;
697 strbuf_addstr(&msgbuf
, ctx
.notes_message
);
700 if (opt
->show_log_size
) {
701 printf("log size %i\n", (int)msgbuf
.len
);
702 graph_show_oneline(opt
->graph
);
706 * Set opt->missing_newline if msgbuf doesn't
707 * end in a newline (including if it is empty)
709 if (!msgbuf
.len
|| msgbuf
.buf
[msgbuf
.len
- 1] != '\n')
710 opt
->missing_newline
= 1;
712 opt
->missing_newline
= 0;
715 graph_show_commit_msg(opt
->graph
, &msgbuf
);
717 fwrite(msgbuf
.buf
, sizeof(char), msgbuf
.len
, stdout
);
718 if (opt
->use_terminator
&& !commit_format_is_empty(opt
->commit_format
)) {
719 if (!opt
->missing_newline
)
720 graph_show_padding(opt
->graph
);
721 putchar(opt
->diffopt
.line_termination
);
724 strbuf_release(&msgbuf
);
725 free(ctx
.notes_message
);
728 int log_tree_diff_flush(struct rev_info
*opt
)
730 opt
->shown_dashes
= 0;
731 diffcore_std(&opt
->diffopt
);
733 if (diff_queue_is_empty()) {
734 int saved_fmt
= opt
->diffopt
.output_format
;
735 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
736 diff_flush(&opt
->diffopt
);
737 opt
->diffopt
.output_format
= saved_fmt
;
741 if (opt
->loginfo
&& !opt
->no_commit_id
) {
743 if ((opt
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
) &&
744 opt
->verbose_header
&&
745 opt
->commit_format
!= CMIT_FMT_ONELINE
&&
746 !commit_format_is_empty(opt
->commit_format
)) {
748 * When showing a verbose header (i.e. log message),
749 * and not in --pretty=oneline format, we would want
750 * an extra newline between the end of log and the
751 * diff/diffstat output for readability.
753 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
754 if (opt
->diffopt
.output_prefix
) {
755 struct strbuf
*msg
= NULL
;
756 msg
= opt
->diffopt
.output_prefix(&opt
->diffopt
,
757 opt
->diffopt
.output_prefix_data
);
758 fwrite(msg
->buf
, msg
->len
, 1, stdout
);
762 * We may have shown three-dashes line early
763 * between notes and the log message, in which
764 * case we only want a blank line after the
765 * notes without (an extra) three-dashes line.
766 * Otherwise, we show the three-dashes line if
767 * we are showing the patch with diffstat, but
768 * in that case, there is no extra blank line
769 * after the three-dashes line.
771 if (!opt
->shown_dashes
&&
772 (pch
& opt
->diffopt
.output_format
) == pch
)
777 diff_flush(&opt
->diffopt
);
781 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
783 diff_tree_combined_merge(commit
, opt
->dense_combined_merges
, opt
);
784 return !opt
->loginfo
;
788 * Show the diff of a commit.
790 * Return true if we printed any log info messages
792 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
795 struct commit_list
*parents
;
796 unsigned const char *sha1
;
798 if (!opt
->diff
&& !DIFF_OPT_TST(&opt
->diffopt
, EXIT_WITH_STATUS
))
801 parse_commit_or_die(commit
);
802 sha1
= commit
->tree
->object
.sha1
;
805 parents
= get_saved_parents(opt
, commit
);
807 if (opt
->show_root_diff
) {
808 diff_root_tree_sha1(sha1
, "", &opt
->diffopt
);
809 log_tree_diff_flush(opt
);
811 return !opt
->loginfo
;
814 /* More than one parent? */
815 if (parents
&& parents
->next
) {
816 if (opt
->ignore_merges
)
818 else if (opt
->combine_merges
)
819 return do_diff_combined(opt
, commit
);
820 else if (opt
->first_parent_only
) {
822 * Generate merge log entry only for the first
823 * parent, showing summary diff of the others
826 parse_commit_or_die(parents
->item
);
827 diff_tree_sha1(parents
->item
->tree
->object
.sha1
,
828 sha1
, "", &opt
->diffopt
);
829 log_tree_diff_flush(opt
);
830 return !opt
->loginfo
;
833 /* If we show individual diffs, show the parent info */
834 log
->parent
= parents
->item
;
839 struct commit
*parent
= parents
->item
;
841 parse_commit_or_die(parent
);
842 diff_tree_sha1(parent
->tree
->object
.sha1
,
843 sha1
, "", &opt
->diffopt
);
844 log_tree_diff_flush(opt
);
846 showed_log
|= !opt
->loginfo
;
848 /* Set up the log info for the next parent, if any.. */
849 parents
= parents
->next
;
852 log
->parent
= parents
->item
;
858 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
867 if (opt
->line_level_traverse
)
868 return line_log_print(opt
, commit
);
870 if (opt
->track_linear
&& !opt
->linear
&& !opt
->reverse_output_stage
)
871 printf("\n%s\n", opt
->break_bar
);
872 shown
= log_tree_diff(opt
, commit
, &log
);
873 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {
878 if (opt
->track_linear
&& !opt
->linear
&& opt
->reverse_output_stage
)
879 printf("\n%s\n", opt
->break_bar
);
881 maybe_flush_or_die(stdout
, "stdout");