6 void show_log(struct rev_info
*opt
, struct log_info
*log
, const char *sep
)
8 static char this_header
[16384];
9 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
10 int abbrev
= opt
->diffopt
.abbrev
;
11 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: 40;
15 if (!opt
->verbose_header
) {
16 puts(sha1_to_hex(commit
->object
.sha1
));
21 * Whitespace between commit messages, unless we are oneline
23 if (opt
->shown_one
&& opt
->commit_format
!= CMIT_FMT_ONELINE
)
28 * Print header line of header..
31 opt
->commit_format
== CMIT_FMT_ONELINE
? "" : "commit ",
32 diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
));
34 printf(" (from %s)", diff_unique_abbrev(parent
->object
.sha1
, abbrev_commit
));
35 putchar(opt
->commit_format
== CMIT_FMT_ONELINE
? ' ' : '\n');
38 * And then the pretty-printed message itself
40 len
= pretty_print_commit(opt
->commit_format
, commit
, ~0u, this_header
, sizeof(this_header
), abbrev
);
41 printf("%s%s", this_header
, sep
);
44 int log_tree_diff_flush(struct rev_info
*opt
)
46 diffcore_std(&opt
->diffopt
);
48 if (diff_queue_is_empty()) {
49 int saved_fmt
= opt
->diffopt
.output_format
;
50 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
51 diff_flush(&opt
->diffopt
);
52 opt
->diffopt
.output_format
= saved_fmt
;
56 if (opt
->loginfo
&& !opt
->no_commit_id
)
57 show_log(opt
, opt
->loginfo
, opt
->diffopt
.with_stat
? "---\n" : "\n");
58 diff_flush(&opt
->diffopt
);
62 static int diff_root_tree(struct rev_info
*opt
,
63 const unsigned char *new, const char *base
)
67 struct tree_desc empty
, real
;
69 tree
= read_object_with_reference(new, tree_type
, &real
.size
, NULL
);
71 die("unable to read root tree (%s)", sha1_to_hex(new));
76 retval
= diff_tree(&empty
, &real
, base
, &opt
->diffopt
);
78 log_tree_diff_flush(opt
);
82 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
84 unsigned const char *sha1
= commit
->object
.sha1
;
86 diff_tree_combined_merge(sha1
, opt
->dense_combined_merges
, opt
);
91 * Show the diff of a commit.
93 * Return true if we printed any log info messages
95 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
98 struct commit_list
*parents
;
99 unsigned const char *sha1
= commit
->object
.sha1
;
105 parents
= commit
->parents
;
107 if (opt
->show_root_diff
)
108 diff_root_tree(opt
, sha1
, "");
109 return !opt
->loginfo
;
112 /* More than one parent? */
113 if (parents
&& parents
->next
) {
114 if (opt
->ignore_merges
)
116 else if (opt
->combine_merges
)
117 return do_diff_combined(opt
, commit
);
119 /* If we show individual diffs, show the parent info */
120 log
->parent
= parents
->item
;
125 struct commit
*parent
= parents
->item
;
127 diff_tree_sha1(parent
->object
.sha1
, sha1
, "", &opt
->diffopt
);
128 log_tree_diff_flush(opt
);
130 showed_log
|= !opt
->loginfo
;
132 /* Set up the log info for the next parent, if any.. */
133 parents
= parents
->next
;
136 log
->parent
= parents
->item
;
142 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
150 if (!log_tree_diff(opt
, commit
, &log
) && opt
->loginfo
&& opt
->always_show_header
) {
152 show_log(opt
, opt
->loginfo
, "");