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;
17 if (!opt
->verbose_header
) {
18 puts(sha1_to_hex(commit
->object
.sha1
));
23 * The "oneline" format has several special cases:
24 * - The pretty-printed commit lacks a newline at the end
25 * of the buffer, but we do want to make sure that we
26 * have a newline there. If the separator isn't already
27 * a newline, add an extra one.
28 * - unlike other log messages, the one-line format does
29 * not have an empty line between entries.
32 if (*sep
!= '\n' && opt
->commit_format
== CMIT_FMT_ONELINE
)
34 if (opt
->shown_one
&& opt
->commit_format
!= CMIT_FMT_ONELINE
)
39 * Print header line of header..
42 if (opt
->commit_format
== CMIT_FMT_EMAIL
) {
44 static char buffer
[64];
45 snprintf(buffer
, sizeof(buffer
),
46 "Subject: [PATCH %d/%d] ",
49 } else if (opt
->total
== 0)
50 subject
= "Subject: [PATCH] ";
52 subject
= "Subject: ";
54 printf("From %s Thu Apr 7 15:13:13 2005\n",
55 sha1_to_hex(commit
->object
.sha1
));
58 opt
->commit_format
== CMIT_FMT_ONELINE
? "" : "commit ",
59 diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
));
62 diff_unique_abbrev(parent
->object
.sha1
,
64 putchar(opt
->commit_format
== CMIT_FMT_ONELINE
? ' ' : '\n');
68 * And then the pretty-printed message itself
70 len
= pretty_print_commit(opt
->commit_format
, commit
, ~0u, this_header
, sizeof(this_header
), abbrev
, subject
);
71 printf("%s%s%s", this_header
, extra
, sep
);
74 int log_tree_diff_flush(struct rev_info
*opt
)
76 diffcore_std(&opt
->diffopt
);
78 if (diff_queue_is_empty()) {
79 int saved_fmt
= opt
->diffopt
.output_format
;
80 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
81 diff_flush(&opt
->diffopt
);
82 opt
->diffopt
.output_format
= saved_fmt
;
86 if (opt
->loginfo
&& !opt
->no_commit_id
)
87 show_log(opt
, opt
->loginfo
, opt
->diffopt
.with_stat
? "---\n" : "\n");
88 diff_flush(&opt
->diffopt
);
92 static int diff_root_tree(struct rev_info
*opt
,
93 const unsigned char *new, const char *base
)
97 struct tree_desc empty
, real
;
99 tree
= read_object_with_reference(new, tree_type
, &real
.size
, NULL
);
101 die("unable to read root tree (%s)", sha1_to_hex(new));
106 retval
= diff_tree(&empty
, &real
, base
, &opt
->diffopt
);
108 log_tree_diff_flush(opt
);
112 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
114 unsigned const char *sha1
= commit
->object
.sha1
;
116 diff_tree_combined_merge(sha1
, opt
->dense_combined_merges
, opt
);
117 return !opt
->loginfo
;
121 * Show the diff of a commit.
123 * Return true if we printed any log info messages
125 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
128 struct commit_list
*parents
;
129 unsigned const char *sha1
= commit
->object
.sha1
;
135 parents
= commit
->parents
;
137 if (opt
->show_root_diff
)
138 diff_root_tree(opt
, sha1
, "");
139 return !opt
->loginfo
;
142 /* More than one parent? */
143 if (parents
&& parents
->next
) {
144 if (opt
->ignore_merges
)
146 else if (opt
->combine_merges
)
147 return do_diff_combined(opt
, commit
);
149 /* If we show individual diffs, show the parent info */
150 log
->parent
= parents
->item
;
155 struct commit
*parent
= parents
->item
;
157 diff_tree_sha1(parent
->object
.sha1
, sha1
, "", &opt
->diffopt
);
158 log_tree_diff_flush(opt
);
160 showed_log
|= !opt
->loginfo
;
162 /* Set up the log info for the next parent, if any.. */
163 parents
= parents
->next
;
166 log
->parent
= parents
->item
;
172 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
181 shown
= log_tree_diff(opt
, commit
, &log
);
182 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {
184 show_log(opt
, opt
->loginfo
, "");