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
, git_replace_ref_base
)) {
100 unsigned char original_sha1
[20];
101 if (!check_replace_refs
)
103 if (get_sha1_hex(refname
+ strlen(git_replace_ref_base
),
105 warning("invalid replace ref %s", refname
);
108 obj
= parse_object(original_sha1
);
110 add_name_decoration(DECORATION_GRAFTED
, "replaced", obj
);
114 obj
= parse_object(sha1
);
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
->sha1
);
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
.hash
);
146 add_name_decoration(DECORATION_GRAFTED
, "grafted", &commit
->object
);
150 void load_ref_decorations(int flags
)
152 if (!decoration_loaded
) {
153 decoration_loaded
= 1;
154 decoration_flags
= flags
;
155 for_each_ref(add_ref_decoration
, NULL
);
156 head_ref(add_ref_decoration
, NULL
);
157 for_each_commit_graft(add_graft_decoration
, NULL
);
161 static void show_parents(struct commit
*commit
, int abbrev
)
163 struct commit_list
*p
;
164 for (p
= commit
->parents
; p
; p
= p
->next
) {
165 struct commit
*parent
= p
->item
;
166 printf(" %s", find_unique_abbrev(parent
->object
.sha1
, 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 printf(" %s", find_unique_abbrev(p
->item
->object
.sha1
, 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
;
186 unsigned char unused
[20];
189 /* First find HEAD */
190 for (list
= decoration
; list
; list
= list
->next
)
191 if (list
->type
== DECORATION_REF_HEAD
) {
198 /* Now resolve and find the matching current branch */
199 branch_name
= resolve_ref_unsafe("HEAD", 0, unused
, &rru_flags
);
200 if (!(rru_flags
& REF_ISSYMREF
))
203 if (!starts_with(branch_name
, "refs/"))
206 /* OK, do we have that ref in the list? */
207 for (list
= decoration
; list
; list
= list
->next
)
208 if ((list
->type
== DECORATION_REF_LOCAL
) &&
209 !strcmp(branch_name
, list
->name
)) {
216 static void show_name(struct strbuf
*sb
, const struct name_decoration
*decoration
)
218 if (decoration_flags
== DECORATE_SHORT_REFS
)
219 strbuf_addstr(sb
, prettify_refname(decoration
->name
));
221 strbuf_addstr(sb
, decoration
->name
);
225 * The caller makes sure there is no funny color before calling.
226 * format_decorations_extended makes sure the same after return.
228 void format_decorations_extended(struct strbuf
*sb
,
229 const struct commit
*commit
,
232 const char *separator
,
235 const struct name_decoration
*decoration
;
236 const struct name_decoration
*current_and_HEAD
;
237 const char *color_commit
=
238 diff_get_color(use_color
, DIFF_COMMIT
);
239 const char *color_reset
=
240 decorate_get_color(use_color
, DECORATION_NONE
);
242 decoration
= get_name_decoration(&commit
->object
);
246 current_and_HEAD
= current_pointed_by_HEAD(decoration
);
249 * When both current and HEAD are there, only
250 * show HEAD->current where HEAD would have
251 * appeared, skipping the entry for current.
253 if (decoration
!= current_and_HEAD
) {
254 strbuf_addstr(sb
, color_commit
);
255 strbuf_addstr(sb
, prefix
);
256 strbuf_addstr(sb
, color_reset
);
257 strbuf_addstr(sb
, decorate_get_color(use_color
, decoration
->type
));
258 if (decoration
->type
== DECORATION_REF_TAG
)
259 strbuf_addstr(sb
, "tag: ");
261 show_name(sb
, decoration
);
263 if (current_and_HEAD
&&
264 decoration
->type
== DECORATION_REF_HEAD
) {
265 strbuf_addstr(sb
, color_reset
);
266 strbuf_addstr(sb
, color_commit
);
267 strbuf_addstr(sb
, " -> ");
268 strbuf_addstr(sb
, color_reset
);
269 strbuf_addstr(sb
, decorate_get_color(use_color
, current_and_HEAD
->type
));
270 show_name(sb
, current_and_HEAD
);
272 strbuf_addstr(sb
, color_reset
);
276 decoration
= decoration
->next
;
278 strbuf_addstr(sb
, color_commit
);
279 strbuf_addstr(sb
, suffix
);
280 strbuf_addstr(sb
, color_reset
);
283 void show_decorations(struct rev_info
*opt
, struct commit
*commit
)
285 struct strbuf sb
= STRBUF_INIT
;
287 if (opt
->show_source
&& commit
->util
)
288 printf("\t%s", (char *) commit
->util
);
289 if (!opt
->show_decorations
)
291 format_decorations(&sb
, commit
, opt
->diffopt
.use_color
);
292 fputs(sb
.buf
, stdout
);
296 static unsigned int digits_in_number(unsigned int number
)
298 unsigned int i
= 10, result
= 1;
299 while (i
<= number
) {
306 void fmt_output_subject(struct strbuf
*filename
,
308 struct rev_info
*info
)
310 const char *suffix
= info
->patch_suffix
;
312 int start_len
= filename
->len
;
313 int max_len
= start_len
+ FORMAT_PATCH_NAME_MAX
- (strlen(suffix
) + 1);
315 if (0 < info
->reroll_count
)
316 strbuf_addf(filename
, "v%d-", info
->reroll_count
);
317 strbuf_addf(filename
, "%04d-%s", nr
, subject
);
319 if (max_len
< filename
->len
)
320 strbuf_setlen(filename
, max_len
);
321 strbuf_addstr(filename
, suffix
);
324 void fmt_output_commit(struct strbuf
*filename
,
325 struct commit
*commit
,
326 struct rev_info
*info
)
328 struct pretty_print_context ctx
= {0};
329 struct strbuf subject
= STRBUF_INIT
;
331 format_commit_message(commit
, "%f", &subject
, &ctx
);
332 fmt_output_subject(filename
, subject
.buf
, info
);
333 strbuf_release(&subject
);
336 void log_write_email_headers(struct rev_info
*opt
, struct commit
*commit
,
337 const char **subject_p
,
338 const char **extra_headers_p
,
339 int *need_8bit_cte_p
)
341 const char *subject
= NULL
;
342 const char *extra_headers
= opt
->extra_headers
;
343 const char *name
= sha1_to_hex(commit
->object
.sha1
);
345 *need_8bit_cte_p
= 0; /* unknown */
346 if (opt
->total
> 0) {
347 static char buffer
[64];
348 snprintf(buffer
, sizeof(buffer
),
349 "Subject: [%s%s%0*d/%d] ",
351 *opt
->subject_prefix
? " " : "",
352 digits_in_number(opt
->total
),
353 opt
->nr
, opt
->total
);
355 } else if (opt
->total
== 0 && opt
->subject_prefix
&& *opt
->subject_prefix
) {
356 static char buffer
[256];
357 snprintf(buffer
, sizeof(buffer
),
359 opt
->subject_prefix
);
362 subject
= "Subject: ";
365 printf("From %s Mon Sep 17 00:00:00 2001\n", name
);
366 graph_show_oneline(opt
->graph
);
367 if (opt
->message_id
) {
368 printf("Message-Id: <%s>\n", opt
->message_id
);
369 graph_show_oneline(opt
->graph
);
371 if (opt
->ref_message_ids
&& opt
->ref_message_ids
->nr
> 0) {
373 n
= opt
->ref_message_ids
->nr
;
374 printf("In-Reply-To: <%s>\n", opt
->ref_message_ids
->items
[n
-1].string
);
375 for (i
= 0; i
< n
; i
++)
376 printf("%s<%s>\n", (i
> 0 ? "\t" : "References: "),
377 opt
->ref_message_ids
->items
[i
].string
);
378 graph_show_oneline(opt
->graph
);
380 if (opt
->mime_boundary
) {
381 static char subject_buffer
[1024];
382 static char buffer
[1024];
383 struct strbuf filename
= STRBUF_INIT
;
384 *need_8bit_cte_p
= -1; /* NEVER */
385 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
387 "MIME-Version: 1.0\n"
388 "Content-Type: multipart/mixed;"
389 " boundary=\"%s%s\"\n"
391 "This is a multi-part message in MIME "
394 "Content-Type: text/plain; "
395 "charset=UTF-8; format=fixed\n"
396 "Content-Transfer-Encoding: 8bit\n\n",
397 extra_headers
? extra_headers
: "",
398 mime_boundary_leader
, opt
->mime_boundary
,
399 mime_boundary_leader
, opt
->mime_boundary
);
400 extra_headers
= subject_buffer
;
402 if (opt
->numbered_files
)
403 strbuf_addf(&filename
, "%d", opt
->nr
);
405 fmt_output_commit(&filename
, commit
, opt
);
406 snprintf(buffer
, sizeof(buffer
) - 1,
408 "Content-Type: text/x-patch;"
410 "Content-Transfer-Encoding: 8bit\n"
411 "Content-Disposition: %s;"
412 " filename=\"%s\"\n\n",
413 mime_boundary_leader
, opt
->mime_boundary
,
415 opt
->no_inline
? "attachment" : "inline",
417 opt
->diffopt
.stat_sep
= buffer
;
418 strbuf_release(&filename
);
420 *subject_p
= subject
;
421 *extra_headers_p
= extra_headers
;
424 static void show_sig_lines(struct rev_info
*opt
, int status
, const char *bol
)
426 const char *color
, *reset
, *eol
;
428 color
= diff_get_color_opt(&opt
->diffopt
,
429 status
? DIFF_WHITESPACE
: DIFF_FRAGINFO
);
430 reset
= diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
);
432 eol
= strchrnul(bol
, '\n');
433 printf("%s%.*s%s%s", color
, (int)(eol
- bol
), bol
, reset
,
435 graph_show_oneline(opt
->graph
);
436 bol
= (*eol
) ? (eol
+ 1) : eol
;
440 static void show_signature(struct rev_info
*opt
, struct commit
*commit
)
442 struct strbuf payload
= STRBUF_INIT
;
443 struct strbuf signature
= STRBUF_INIT
;
444 struct strbuf gpg_output
= STRBUF_INIT
;
447 if (parse_signed_commit(commit
, &payload
, &signature
) <= 0)
450 status
= verify_signed_buffer(payload
.buf
, payload
.len
,
451 signature
.buf
, signature
.len
,
453 if (status
&& !gpg_output
.len
)
454 strbuf_addstr(&gpg_output
, "No signature\n");
456 show_sig_lines(opt
, status
, gpg_output
.buf
);
459 strbuf_release(&gpg_output
);
460 strbuf_release(&payload
);
461 strbuf_release(&signature
);
464 static int which_parent(const unsigned char *sha1
, const struct commit
*commit
)
467 const struct commit_list
*parent
;
469 for (nth
= 0, parent
= commit
->parents
; parent
; parent
= parent
->next
) {
470 if (!hashcmp(parent
->item
->object
.sha1
, sha1
))
477 static int is_common_merge(const struct commit
*commit
)
479 return (commit
->parents
480 && commit
->parents
->next
481 && !commit
->parents
->next
->next
);
484 static void show_one_mergetag(struct commit
*commit
,
485 struct commit_extra_header
*extra
,
488 struct rev_info
*opt
= (struct rev_info
*)data
;
489 unsigned char sha1
[20];
491 struct strbuf verify_message
;
493 size_t payload_size
, gpg_message_offset
;
495 hash_sha1_file(extra
->value
, extra
->len
, typename(OBJ_TAG
), sha1
);
496 tag
= lookup_tag(sha1
);
498 return; /* error message already given */
500 strbuf_init(&verify_message
, 256);
501 if (parse_tag_buffer(tag
, extra
->value
, extra
->len
))
502 strbuf_addstr(&verify_message
, "malformed mergetag\n");
503 else if (is_common_merge(commit
) &&
504 !hashcmp(tag
->tagged
->sha1
,
505 commit
->parents
->next
->item
->object
.sha1
))
506 strbuf_addf(&verify_message
,
507 "merged tag '%s'\n", tag
->tag
);
508 else if ((nth
= which_parent(tag
->tagged
->sha1
, commit
)) < 0)
509 strbuf_addf(&verify_message
, "tag %s names a non-parent %s\n",
510 tag
->tag
, tag
->tagged
->sha1
);
512 strbuf_addf(&verify_message
,
513 "parent #%d, tagged '%s'\n", nth
+ 1, tag
->tag
);
514 gpg_message_offset
= verify_message
.len
;
516 payload_size
= parse_signature(extra
->value
, extra
->len
);
518 if (extra
->len
> payload_size
) {
519 /* could have a good signature */
520 if (!verify_signed_buffer(extra
->value
, payload_size
,
521 extra
->value
+ payload_size
,
522 extra
->len
- payload_size
,
523 &verify_message
, NULL
))
524 status
= 0; /* good */
525 else if (verify_message
.len
<= gpg_message_offset
)
526 strbuf_addstr(&verify_message
, "No signature\n");
527 /* otherwise we couldn't verify, which is shown as bad */
530 show_sig_lines(opt
, status
, verify_message
.buf
);
531 strbuf_release(&verify_message
);
534 static void show_mergetag(struct rev_info
*opt
, struct commit
*commit
)
536 for_each_mergetag(show_one_mergetag
, commit
, opt
);
539 void show_log(struct rev_info
*opt
)
541 struct strbuf msgbuf
= STRBUF_INIT
;
542 struct log_info
*log
= opt
->loginfo
;
543 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
544 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: 40;
545 const char *extra_headers
= opt
->extra_headers
;
546 struct pretty_print_context ctx
= {0};
549 if (!opt
->verbose_header
) {
550 graph_show_commit(opt
->graph
);
553 put_revision_mark(opt
, commit
);
554 fputs(find_unique_abbrev(commit
->object
.sha1
, abbrev_commit
), stdout
);
555 if (opt
->print_parents
)
556 show_parents(commit
, abbrev_commit
);
557 if (opt
->children
.name
)
558 show_children(opt
, commit
, abbrev_commit
);
559 show_decorations(opt
, commit
);
560 if (opt
->graph
&& !graph_is_commit_finished(opt
->graph
)) {
562 graph_show_remainder(opt
->graph
);
564 putchar(opt
->diffopt
.line_termination
);
569 * If use_terminator is set, we already handled any record termination
570 * at the end of the last record.
571 * Otherwise, add a diffopt.line_termination character before all
572 * entries but the first. (IOW, as a separator between entries)
574 if (opt
->shown_one
&& !opt
->use_terminator
) {
576 * If entries are separated by a newline, the output
577 * should look human-readable. If the last entry ended
578 * with a newline, print the graph output before this
579 * newline. Otherwise it will end up as a completely blank
580 * line and will look like a gap in the graph.
582 * If the entry separator is not a newline, the output is
583 * primarily intended for programmatic consumption, and we
584 * never want the extra graph output before the entry
587 if (opt
->diffopt
.line_termination
== '\n' &&
588 !opt
->missing_newline
)
589 graph_show_padding(opt
->graph
);
590 putchar(opt
->diffopt
.line_termination
);
595 * If the history graph was requested,
596 * print the graph, up to this commit's line
598 graph_show_commit(opt
->graph
);
601 * Print header line of header..
604 if (opt
->commit_format
== CMIT_FMT_EMAIL
) {
605 log_write_email_headers(opt
, commit
, &ctx
.subject
, &extra_headers
,
607 } else if (opt
->commit_format
!= CMIT_FMT_USERFORMAT
) {
608 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_COMMIT
), stdout
);
609 if (opt
->commit_format
!= CMIT_FMT_ONELINE
)
610 fputs("commit ", stdout
);
613 put_revision_mark(opt
, commit
);
614 fputs(find_unique_abbrev(commit
->object
.sha1
, abbrev_commit
),
616 if (opt
->print_parents
)
617 show_parents(commit
, abbrev_commit
);
618 if (opt
->children
.name
)
619 show_children(opt
, commit
, abbrev_commit
);
622 find_unique_abbrev(parent
->object
.sha1
,
624 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
), stdout
);
625 show_decorations(opt
, commit
);
626 if (opt
->commit_format
== CMIT_FMT_ONELINE
) {
630 graph_show_oneline(opt
->graph
);
632 if (opt
->reflog_info
) {
634 * setup_revisions() ensures that opt->reflog_info
635 * and opt->graph cannot both be set,
636 * so we don't need to worry about printing the
639 show_reflog_message(opt
->reflog_info
,
640 opt
->commit_format
== CMIT_FMT_ONELINE
,
642 opt
->date_mode_explicit
);
643 if (opt
->commit_format
== CMIT_FMT_ONELINE
)
648 if (opt
->show_signature
) {
649 show_signature(opt
, commit
);
650 show_mergetag(opt
, commit
);
653 if (!get_cached_commit_buffer(commit
, NULL
))
656 if (opt
->show_notes
) {
658 struct strbuf notebuf
= STRBUF_INIT
;
660 raw
= (opt
->commit_format
== CMIT_FMT_USERFORMAT
);
661 format_display_notes(commit
->object
.sha1
, ¬ebuf
,
662 get_log_output_encoding(), raw
);
663 ctx
.notes_message
= notebuf
.len
664 ? strbuf_detach(¬ebuf
, NULL
)
669 * And then the pretty-printed message itself
671 if (ctx
.need_8bit_cte
>= 0 && opt
->add_signoff
)
673 has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"),
674 getenv("GIT_COMMITTER_EMAIL")));
675 ctx
.date_mode
= opt
->date_mode
;
676 ctx
.date_mode_explicit
= opt
->date_mode_explicit
;
677 ctx
.abbrev
= opt
->diffopt
.abbrev
;
678 ctx
.after_subject
= extra_headers
;
679 ctx
.preserve_subject
= opt
->preserve_subject
;
680 ctx
.reflog_info
= opt
->reflog_info
;
681 ctx
.fmt
= opt
->commit_format
;
682 ctx
.mailmap
= opt
->mailmap
;
683 ctx
.color
= opt
->diffopt
.use_color
;
684 ctx
.output_encoding
= get_log_output_encoding();
685 if (opt
->from_ident
.mail_begin
&& opt
->from_ident
.name_begin
)
686 ctx
.from_ident
= &opt
->from_ident
;
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 (ctx
.fmt
== CMIT_FMT_EMAIL
) {
695 strbuf_addstr(&msgbuf
, "---\n");
696 opt
->shown_dashes
= 1;
698 strbuf_addstr(&msgbuf
, ctx
.notes_message
);
701 if (opt
->show_log_size
) {
702 printf("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;
716 graph_show_commit_msg(opt
->graph
, &msgbuf
);
718 fwrite(msgbuf
.buf
, sizeof(char), msgbuf
.len
, stdout
);
719 if (opt
->use_terminator
&& !commit_format_is_empty(opt
->commit_format
)) {
720 if (!opt
->missing_newline
)
721 graph_show_padding(opt
->graph
);
722 putchar(opt
->diffopt
.line_termination
);
725 strbuf_release(&msgbuf
);
726 free(ctx
.notes_message
);
729 int log_tree_diff_flush(struct rev_info
*opt
)
731 opt
->shown_dashes
= 0;
732 diffcore_std(&opt
->diffopt
);
734 if (diff_queue_is_empty()) {
735 int saved_fmt
= opt
->diffopt
.output_format
;
736 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
737 diff_flush(&opt
->diffopt
);
738 opt
->diffopt
.output_format
= saved_fmt
;
742 if (opt
->loginfo
&& !opt
->no_commit_id
) {
744 if ((opt
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
) &&
745 opt
->verbose_header
&&
746 opt
->commit_format
!= CMIT_FMT_ONELINE
&&
747 !commit_format_is_empty(opt
->commit_format
)) {
749 * When showing a verbose header (i.e. log message),
750 * and not in --pretty=oneline format, we would want
751 * an extra newline between the end of log and the
752 * diff/diffstat output for readability.
754 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
755 if (opt
->diffopt
.output_prefix
) {
756 struct strbuf
*msg
= NULL
;
757 msg
= opt
->diffopt
.output_prefix(&opt
->diffopt
,
758 opt
->diffopt
.output_prefix_data
);
759 fwrite(msg
->buf
, msg
->len
, 1, stdout
);
763 * We may have shown three-dashes line early
764 * between notes and the log message, in which
765 * case we only want a blank line after the
766 * notes without (an extra) three-dashes line.
767 * Otherwise, we show the three-dashes line if
768 * we are showing the patch with diffstat, but
769 * in that case, there is no extra blank line
770 * after the three-dashes line.
772 if (!opt
->shown_dashes
&&
773 (pch
& opt
->diffopt
.output_format
) == pch
)
778 diff_flush(&opt
->diffopt
);
782 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
784 diff_tree_combined_merge(commit
, opt
->dense_combined_merges
, opt
);
785 return !opt
->loginfo
;
789 * Show the diff of a commit.
791 * Return true if we printed any log info messages
793 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
796 struct commit_list
*parents
;
797 unsigned const char *sha1
;
799 if (!opt
->diff
&& !DIFF_OPT_TST(&opt
->diffopt
, EXIT_WITH_STATUS
))
802 parse_commit_or_die(commit
);
803 sha1
= commit
->tree
->object
.sha1
;
806 parents
= get_saved_parents(opt
, commit
);
808 if (opt
->show_root_diff
) {
809 diff_root_tree_sha1(sha1
, "", &opt
->diffopt
);
810 log_tree_diff_flush(opt
);
812 return !opt
->loginfo
;
815 /* More than one parent? */
816 if (parents
&& parents
->next
) {
817 if (opt
->ignore_merges
)
819 else if (opt
->combine_merges
)
820 return do_diff_combined(opt
, commit
);
821 else if (opt
->first_parent_only
) {
823 * Generate merge log entry only for the first
824 * parent, showing summary diff of the others
827 parse_commit_or_die(parents
->item
);
828 diff_tree_sha1(parents
->item
->tree
->object
.sha1
,
829 sha1
, "", &opt
->diffopt
);
830 log_tree_diff_flush(opt
);
831 return !opt
->loginfo
;
834 /* If we show individual diffs, show the parent info */
835 log
->parent
= parents
->item
;
840 struct commit
*parent
= parents
->item
;
842 parse_commit_or_die(parent
);
843 diff_tree_sha1(parent
->tree
->object
.sha1
,
844 sha1
, "", &opt
->diffopt
);
845 log_tree_diff_flush(opt
);
847 showed_log
|= !opt
->loginfo
;
849 /* Set up the log info for the next parent, if any.. */
850 parents
= parents
->next
;
853 log
->parent
= parents
->item
;
859 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
868 if (opt
->line_level_traverse
)
869 return line_log_print(opt
, commit
);
871 if (opt
->track_linear
&& !opt
->linear
&& !opt
->reverse_output_stage
)
872 printf("\n%s\n", opt
->break_bar
);
873 shown
= log_tree_diff(opt
, commit
, &log
);
874 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {
879 if (opt
->track_linear
&& !opt
->linear
&& opt
->reverse_output_stage
)
880 printf("\n%s\n", opt
->break_bar
);
882 maybe_flush_or_die(stdout
, "stdout");