]> git.ipfire.org Git - thirdparty/git.git/blame - log-tree.c
pretty: add pointer and tag options to %(decorate)
[thirdparty/git.git] / log-tree.c
CommitLineData
d812c3b6 1#include "git-compat-util.h"
db757e8b 2#include "commit-reach.h"
b2141fc1 3#include "config.h"
5f1c3f07 4#include "diff.h"
32a8f510 5#include "environment.h"
41771fa4 6#include "hex.h"
dabab1d6 7#include "object-name.h"
a034e910 8#include "object-store-ll.h"
109cd76d 9#include "repository.h"
7b90ab46 10#include "tmp-objdir.h"
5f1c3f07 11#include "commit.h"
cab4feb6 12#include "tag.h"
7fefda5c 13#include "graph.h"
5f1c3f07 14#include "log-tree.h"
db757e8b 15#include "merge-ort.h"
8860fd42 16#include "reflog-walk.h"
cab4feb6 17#include "refs.h"
cbeab747 18#include "replace-object.h"
0fd2e215 19#include "revision.h"
b079c50e 20#include "string-list.h"
67a4b586 21#include "color.h"
0c37f1fc 22#include "gpg-interface.h"
959a2623 23#include "sequencer.h"
12da1d1f 24#include "line-log.h"
3ac68a93 25#include "help.h"
40ce4160 26#include "range-diff.h"
20323d10 27#include "strmap.h"
d4a4f929 28#include "tree.h"
dd77d587 29#include "wildmatch.h"
d48be35c 30#include "write-or-die.h"
5f1c3f07 31
2608c249 32static struct decoration name_decoration = { "object names" };
76c61fbd
JH
33static int decoration_loaded;
34static int decoration_flags;
a7524128 35
67a4b586
NR
36static char decoration_colors[][COLOR_MAXLEN] = {
37 GIT_COLOR_RESET,
38 GIT_COLOR_BOLD_GREEN, /* REF_LOCAL */
39 GIT_COLOR_BOLD_RED, /* REF_REMOTE */
40 GIT_COLOR_BOLD_YELLOW, /* REF_TAG */
41 GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */
42 GIT_COLOR_BOLD_CYAN, /* REF_HEAD */
76f5df30 43 GIT_COLOR_BOLD_BLUE, /* GRAFTED */
67a4b586
NR
44};
45
a73b3680
NTND
46static const char *color_decorate_slots[] = {
47 [DECORATION_REF_LOCAL] = "branch",
48 [DECORATION_REF_REMOTE] = "remoteBranch",
49 [DECORATION_REF_TAG] = "tag",
50 [DECORATION_REF_STASH] = "stash",
51 [DECORATION_REF_HEAD] = "HEAD",
09c4ba41 52 [DECORATION_GRAFTED] = "grafted",
a73b3680
NTND
53};
54
67a4b586
NR
55static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
56{
daa0c3d9 57 if (want_color(decorate_use_color))
67a4b586
NR
58 return decoration_colors[ix];
59 return "";
60}
61
3ac68a93 62define_list_config_array(color_decorate_slots);
5e11bee6 63
8852117a 64int parse_decorate_color_config(const char *var, const char *slot_name, const char *value)
5e11bee6 65{
a73b3680 66 int slot = LOOKUP_CONFIG(color_decorate_slots, slot_name);
5e11bee6
NR
67 if (slot < 0)
68 return 0;
69 if (!value)
70 return config_error_nonbool(var);
f6c5a296 71 return color_parse(value, decoration_colors[slot]);
5e11bee6
NR
72}
73
67a4b586
NR
74/*
75 * log-tree.c uses DIFF_OPT_TST for determining whether to use color
76 * for showing the commit sha1, use the same check for --decorate
77 */
78#define decorate_get_color_opt(o, ix) \
f1c96261 79 decorate_get_color((o)->use_color, ix)
67a4b586 80
662174d2 81void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
cab4feb6 82{
96ffc06f
JK
83 struct name_decoration *res;
84 FLEX_ALLOC_STR(res, name, name);
a7524128 85 res->type = type;
cab4feb6
RS
86 res->next = add_decoration(&name_decoration, obj, res);
87}
88
2608c249
JK
89const struct name_decoration *get_name_decoration(const struct object *obj)
90{
0cc7380d 91 load_ref_decorations(NULL, DECORATE_SHORT_REFS);
2608c249
JK
92 return lookup_decoration(&name_decoration, obj);
93}
94
c9f7a793
DS
95static int match_ref_pattern(const char *refname,
96 const struct string_list_item *item)
97{
98 int matched = 0;
afe8a907 99 if (!item->util) {
c9f7a793
DS
100 if (!wildmatch(item->string, refname, 0))
101 matched = 1;
102 } else {
103 const char *rest;
104 if (skip_prefix(refname, item->string, &rest) &&
105 (!*rest || *rest == '/'))
106 matched = 1;
107 }
108 return matched;
109}
110
111static int ref_filter_match(const char *refname,
112 const struct decoration_filter *filter)
113{
114 struct string_list_item *item;
115 const struct string_list *exclude_patterns = filter->exclude_ref_pattern;
116 const struct string_list *include_patterns = filter->include_ref_pattern;
a6be5e67
DS
117 const struct string_list *exclude_patterns_config =
118 filter->exclude_ref_config_pattern;
c9f7a793
DS
119
120 if (exclude_patterns && exclude_patterns->nr) {
121 for_each_string_list_item(item, exclude_patterns) {
122 if (match_ref_pattern(refname, item))
123 return 0;
124 }
125 }
126
127 if (include_patterns && include_patterns->nr) {
c9f7a793 128 for_each_string_list_item(item, include_patterns) {
a6be5e67
DS
129 if (match_ref_pattern(refname, item))
130 return 1;
c9f7a793 131 }
a6be5e67
DS
132 return 0;
133 }
c9f7a793 134
a6be5e67
DS
135 if (exclude_patterns_config && exclude_patterns_config->nr) {
136 for_each_string_list_item(item, exclude_patterns_config) {
137 if (match_ref_pattern(refname, item))
138 return 0;
139 }
c9f7a793 140 }
a6be5e67 141
c9f7a793
DS
142 return 1;
143}
144
f124b730 145static int add_ref_decoration(const char *refname, const struct object_id *oid,
5cf88fd8 146 int flags UNUSED,
63e14ee2 147 void *cb_data)
cab4feb6 148{
94d421b8 149 int i;
5267d292 150 struct object *obj;
88473c8b 151 enum object_type objtype;
6afb265b 152 enum decoration_type deco_type = DECORATION_NONE;
65516f58 153 struct decoration_filter *filter = (struct decoration_filter *)cb_data;
97e61e0f 154 const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
5267d292 155
c9f7a793 156 if (filter && !ref_filter_match(refname, filter))
65516f58 157 return 0;
429ad204 158
58d121b2 159 if (starts_with(refname, git_replace_ref_base)) {
3d79f657 160 struct object_id original_oid;
f1178380 161 if (!replace_refs_enabled(the_repository))
b9ad5002 162 return 0;
31a0ad54
JH
163 if (get_oid_hex(refname + strlen(git_replace_ref_base),
164 &original_oid)) {
5267d292
NTND
165 warning("invalid replace ref %s", refname);
166 return 0;
167 }
109cd76d 168 obj = parse_object(the_repository, &original_oid);
5267d292
NTND
169 if (obj)
170 add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
171 return 0;
172 }
173
88473c8b
JK
174 objtype = oid_object_info(the_repository, oid, NULL);
175 if (objtype < 0)
cab4feb6 176 return 0;
88473c8b 177 obj = lookup_object_by_type(the_repository, oid, objtype);
a7524128 178
94d421b8
DS
179 for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
180 struct ref_namespace_info *info = &ref_namespace[i];
181
182 if (!info->decoration)
183 continue;
184 if (info->exact) {
185 if (!strcmp(refname, info->ref)) {
186 deco_type = info->decoration;
187 break;
188 }
189 } else if (starts_with(refname, info->ref)) {
190 deco_type = info->decoration;
191 break;
192 }
193 }
a7524128 194
6afb265b 195 add_name_decoration(deco_type, refname, obj);
cab4feb6 196 while (obj->type == OBJ_TAG) {
d1ed8d6c
JK
197 if (!obj->parsed)
198 parse_object(the_repository, &obj->oid);
cab4feb6
RS
199 obj = ((struct tag *)obj)->tagged;
200 if (!obj)
201 break;
a7524128 202 add_name_decoration(DECORATION_REF_TAG, refname, obj);
cab4feb6
RS
203 }
204 return 0;
205}
206
43090008
JK
207static int add_graft_decoration(const struct commit_graft *graft,
208 void *cb_data UNUSED)
76f5df30 209{
c1f5eb49 210 struct commit *commit = lookup_commit(the_repository, &graft->oid);
76f5df30
NTND
211 if (!commit)
212 return 0;
213 add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
214 return 0;
215}
216
65516f58 217void load_ref_decorations(struct decoration_filter *filter, int flags)
cab4feb6 218{
76c61fbd 219 if (!decoration_loaded) {
65516f58
RA
220 if (filter) {
221 struct string_list_item *item;
222 for_each_string_list_item(item, filter->exclude_ref_pattern) {
223 normalize_glob_ref(item, NULL, item->string);
224 }
225 for_each_string_list_item(item, filter->include_ref_pattern) {
226 normalize_glob_ref(item, NULL, item->string);
227 }
a6be5e67
DS
228 for_each_string_list_item(item, filter->exclude_ref_config_pattern) {
229 normalize_glob_ref(item, NULL, item->string);
230 }
65516f58 231 }
76c61fbd
JH
232 decoration_loaded = 1;
233 decoration_flags = flags;
65516f58
RA
234 for_each_ref(add_ref_decoration, filter);
235 head_ref(add_ref_decoration, filter);
236 for_each_commit_graft(add_graft_decoration, filter);
cab4feb6
RS
237 }
238}
239
4d7b0efc 240static void show_parents(struct commit *commit, int abbrev, FILE *file)
c8c893c6
LT
241{
242 struct commit_list *p;
243 for (p = commit->parents; p ; p = p->next) {
244 struct commit *parent = p->item;
d850b7a5
ÆAB
245 fprintf(file, " %s",
246 repo_find_unique_abbrev(the_repository, &parent->object.oid, abbrev));
c8c893c6
LT
247 }
248}
249
91b849b2
JS
250static void show_children(struct rev_info *opt, struct commit *commit, int abbrev)
251{
252 struct commit_list *p = lookup_decoration(&opt->children, &commit->object);
253 for ( ; p; p = p->next) {
d850b7a5
ÆAB
254 fprintf(opt->diffopt.file, " %s",
255 repo_find_unique_abbrev(the_repository, &p->item->object.oid, abbrev));
91b849b2
JS
256 }
257}
258
51ff0f27
JH
259/*
260 * Do we have HEAD in the output, and also the branch it points at?
261 * If so, find that decoration entry for that current branch.
262 */
263static const struct name_decoration *current_pointed_by_HEAD(const struct name_decoration *decoration)
264{
265 const struct name_decoration *list, *head = NULL;
266 const char *branch_name = NULL;
51ff0f27
JH
267 int rru_flags;
268
269 /* First find HEAD */
270 for (list = decoration; list; list = list->next)
271 if (list->type == DECORATION_REF_HEAD) {
272 head = list;
273 break;
274 }
275 if (!head)
276 return NULL;
277
278 /* Now resolve and find the matching current branch */
744c040b 279 branch_name = resolve_ref_unsafe("HEAD", 0, NULL, &rru_flags);
d79be498 280 if (!branch_name || !(rru_flags & REF_ISSYMREF))
51ff0f27 281 return NULL;
76c61fbd 282
429ad204 283 if (!starts_with(branch_name, "refs/"))
51ff0f27
JH
284 return NULL;
285
286 /* OK, do we have that ref in the list? */
287 for (list = decoration; list; list = list->next)
288 if ((list->type == DECORATION_REF_LOCAL) &&
289 !strcmp(branch_name, list->name)) {
290 return list;
291 }
292
293 return NULL;
294}
295
429ad204
JH
296static void show_name(struct strbuf *sb, const struct name_decoration *decoration)
297{
298 if (decoration_flags == DECORATE_SHORT_REFS)
299 strbuf_addstr(sb, prettify_refname(decoration->name));
300 else
301 strbuf_addstr(sb, decoration->name);
302}
303
9d3f002f 304/*
9271095c 305 * The caller makes sure there is no funny color before calling.
a3883a65 306 * format_decorations ensures the same after return.
9d3f002f 307 */
a3883a65 308void format_decorations(struct strbuf *sb,
9d3f002f 309 const struct commit *commit,
9271095c 310 int use_color,
a3883a65 311 const struct decoration_options *opts)
ca135e7a 312{
2608c249 313 const struct name_decoration *decoration;
51ff0f27 314 const struct name_decoration *current_and_HEAD;
b87a9a2c 315 const char *color_commit, *color_reset;
ca135e7a 316
a3883a65
AK
317 const char *prefix = " (";
318 const char *suffix = ")";
319 const char *separator = ", ";
f1f8a258
AK
320 const char *pointer = " -> ";
321 const char *tag = "tag: ";
a3883a65 322
2608c249 323 decoration = get_name_decoration(&commit->object);
ca135e7a
LT
324 if (!decoration)
325 return;
51ff0f27 326
a3883a65
AK
327 if (opts) {
328 if (opts->prefix)
329 prefix = opts->prefix;
330 if (opts->suffix)
331 suffix = opts->suffix;
332 if (opts->separator)
333 separator = opts->separator;
f1f8a258
AK
334 if (opts->pointer)
335 pointer = opts->pointer;
336 if (opts->tag)
337 tag = opts->tag;
a3883a65
AK
338 }
339
b87a9a2c
AK
340 color_commit = diff_get_color(use_color, DIFF_COMMIT);
341 color_reset = decorate_get_color(use_color, DECORATION_NONE);
342
51ff0f27 343 current_and_HEAD = current_pointed_by_HEAD(decoration);
ca135e7a 344 while (decoration) {
51ff0f27
JH
345 /*
346 * When both current and HEAD are there, only
347 * show HEAD->current where HEAD would have
348 * appeared, skipping the entry for current.
349 */
350 if (decoration != current_and_HEAD) {
dcb347f8
AK
351 const char *color =
352 decorate_get_color(use_color, decoration->type);
353
b87a9a2c
AK
354 if (*prefix) {
355 strbuf_addstr(sb, color_commit);
356 strbuf_addstr(sb, prefix);
357 strbuf_addstr(sb, color_reset);
358 }
359
f1f8a258 360 if (*tag && decoration->type == DECORATION_REF_TAG) {
dcb347f8 361 strbuf_addstr(sb, color);
f1f8a258 362 strbuf_addstr(sb, tag);
dcb347f8
AK
363 strbuf_addstr(sb, color_reset);
364 }
51ff0f27 365
dcb347f8 366 strbuf_addstr(sb, color);
429ad204 367 show_name(sb, decoration);
dcb347f8 368 strbuf_addstr(sb, color_reset);
51ff0f27
JH
369
370 if (current_and_HEAD &&
371 decoration->type == DECORATION_REF_HEAD) {
dcb347f8 372 strbuf_addstr(sb, color);
f1f8a258 373 strbuf_addstr(sb, pointer);
51ff0f27
JH
374 strbuf_addstr(sb, color_reset);
375 strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type));
429ad204 376 show_name(sb, current_and_HEAD);
dcb347f8 377 strbuf_addstr(sb, color_reset);
51ff0f27 378 }
51ff0f27
JH
379
380 prefix = separator;
381 }
ca135e7a
LT
382 decoration = decoration->next;
383 }
b87a9a2c
AK
384 if (*suffix) {
385 strbuf_addstr(sb, color_commit);
386 strbuf_addstr(sb, suffix);
387 strbuf_addstr(sb, color_reset);
388 }
9d3f002f
NTND
389}
390
391void show_decorations(struct rev_info *opt, struct commit *commit)
392{
393 struct strbuf sb = STRBUF_INIT;
394
87be2523
NTND
395 if (opt->sources) {
396 char **slot = revision_sources_peek(opt->sources, commit);
397
398 if (slot && *slot)
399 fprintf(opt->diffopt.file, "\t%s", *slot);
400 }
9d3f002f
NTND
401 if (!opt->show_decorations)
402 return;
a3883a65 403 format_decorations(&sb, commit, opt->diffopt.use_color, NULL);
4d7b0efc 404 fputs(sb.buf, opt->diffopt.file);
9d3f002f 405 strbuf_release(&sb);
ca135e7a
LT
406}
407
e00de24b
JS
408static unsigned int digits_in_number(unsigned int number)
409{
410 unsigned int i = 10, result = 1;
411 while (i <= number) {
412 i *= 10;
413 result++;
414 }
415 return result;
416}
417
d28b5d47
JH
418void fmt_output_subject(struct strbuf *filename,
419 const char *subject,
021f2f4c 420 struct rev_info *info)
6fa8e627 421{
021f2f4c
JH
422 const char *suffix = info->patch_suffix;
423 int nr = info->nr;
d28b5d47 424 int start_len = filename->len;
3baf58bf 425 int max_len = start_len + info->patch_name_max - (strlen(suffix) + 1);
d28b5d47 426
db91988a
ZH
427 if (info->reroll_count) {
428 struct strbuf temp = STRBUF_INIT;
429
430 strbuf_addf(&temp, "v%s", info->reroll_count);
431 format_sanitized_subject(filename, temp.buf, temp.len);
432 strbuf_addstr(filename, "-");
433 strbuf_release(&temp);
434 }
d28b5d47
JH
435 strbuf_addf(filename, "%04d-%s", nr, subject);
436
437 if (max_len < filename->len)
438 strbuf_setlen(filename, max_len);
439 strbuf_addstr(filename, suffix);
440}
441
442void fmt_output_commit(struct strbuf *filename,
443 struct commit *commit,
444 struct rev_info *info)
445{
446 struct pretty_print_context ctx = {0};
447 struct strbuf subject = STRBUF_INIT;
448
bab82164
ÆAB
449 repo_format_commit_message(the_repository, commit, "%f", &subject,
450 &ctx);
d28b5d47
JH
451 fmt_output_subject(filename, subject.buf, info);
452 strbuf_release(&subject);
6fa8e627
SB
453}
454
8ffc8dc6
RS
455void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
456{
457 if (opt->total > 0) {
458 strbuf_addf(sb, "Subject: [%s%s%0*d/%d] ",
459 opt->subject_prefix,
460 *opt->subject_prefix ? " " : "",
461 digits_in_number(opt->total),
462 opt->nr, opt->total);
463 } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
464 strbuf_addf(sb, "Subject: [%s] ",
465 opt->subject_prefix);
466 } else {
467 strbuf_addstr(sb, "Subject: ");
468 }
469}
470
108dab28 471void log_write_email_headers(struct rev_info *opt, struct commit *commit,
267123b4 472 const char **extra_headers_p,
50cd54ef 473 int *need_8bit_cte_p,
474 int maybe_multipart)
b02bd65f 475{
b02bd65f 476 const char *extra_headers = opt->extra_headers;
3a30aa17 477 const char *name = oid_to_hex(opt->zero_commit ?
14228447 478 null_oid() : &commit->object.oid);
267123b4
JH
479
480 *need_8bit_cte_p = 0; /* unknown */
b02bd65f 481
4d7b0efc 482 fprintf(opt->diffopt.file, "From %s Mon Sep 17 00:00:00 2001\n", name);
7fefda5c
AS
483 graph_show_oneline(opt->graph);
484 if (opt->message_id) {
ba4324c4 485 fprintf(opt->diffopt.file, "Message-ID: <%s>\n", opt->message_id);
7fefda5c
AS
486 graph_show_oneline(opt->graph);
487 }
b079c50e
TR
488 if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) {
489 int i, n;
490 n = opt->ref_message_ids->nr;
4d7b0efc 491 fprintf(opt->diffopt.file, "In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string);
b079c50e 492 for (i = 0; i < n; i++)
4d7b0efc 493 fprintf(opt->diffopt.file, "%s<%s>\n", (i > 0 ? "\t" : "References: "),
b079c50e 494 opt->ref_message_ids->items[i].string);
7fefda5c
AS
495 graph_show_oneline(opt->graph);
496 }
50cd54ef 497 if (opt->mime_boundary && maybe_multipart) {
d50b69b8
JK
498 static struct strbuf subject_buffer = STRBUF_INIT;
499 static struct strbuf buffer = STRBUF_INIT;
108dab28 500 struct strbuf filename = STRBUF_INIT;
267123b4 501 *need_8bit_cte_p = -1; /* NEVER */
d50b69b8
JK
502
503 strbuf_reset(&subject_buffer);
504 strbuf_reset(&buffer);
505
506 strbuf_addf(&subject_buffer,
b02bd65f
DB
507 "%s"
508 "MIME-Version: 1.0\n"
509 "Content-Type: multipart/mixed;"
510 " boundary=\"%s%s\"\n"
511 "\n"
512 "This is a multi-part message in MIME "
513 "format.\n"
514 "--%s%s\n"
515 "Content-Type: text/plain; "
516 "charset=UTF-8; format=fixed\n"
517 "Content-Transfer-Encoding: 8bit\n\n",
518 extra_headers ? extra_headers : "",
519 mime_boundary_leader, opt->mime_boundary,
520 mime_boundary_leader, opt->mime_boundary);
d50b69b8 521 extra_headers = subject_buffer.buf;
b02bd65f 522
38ec23ac
JH
523 if (opt->numbered_files)
524 strbuf_addf(&filename, "%d", opt->nr);
525 else
d28b5d47 526 fmt_output_commit(&filename, commit, opt);
d50b69b8 527 strbuf_addf(&buffer,
6b2fbaaf 528 "\n--%s%s\n"
b02bd65f 529 "Content-Type: text/x-patch;"
108dab28 530 " name=\"%s\"\n"
b02bd65f
DB
531 "Content-Transfer-Encoding: 8bit\n"
532 "Content-Disposition: %s;"
108dab28 533 " filename=\"%s\"\n\n",
b02bd65f 534 mime_boundary_leader, opt->mime_boundary,
108dab28 535 filename.buf,
b02bd65f 536 opt->no_inline ? "attachment" : "inline",
108dab28 537 filename.buf);
d50b69b8 538 opt->diffopt.stat_sep = buffer.buf;
108dab28 539 strbuf_release(&filename);
b02bd65f 540 }
b02bd65f
DB
541 *extra_headers_p = extra_headers;
542}
543
c6b3ec41
JH
544static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
545{
546 const char *color, *reset, *eol;
547
548 color = diff_get_color_opt(&opt->diffopt,
549 status ? DIFF_WHITESPACE : DIFF_FRAGINFO);
550 reset = diff_get_color_opt(&opt->diffopt, DIFF_RESET);
551 while (*bol) {
552 eol = strchrnul(bol, '\n');
4d7b0efc 553 fprintf(opt->diffopt.file, "%s%.*s%s%s", color, (int)(eol - bol), bol, reset,
c6b3ec41 554 *eol ? "\n" : "");
cf3983d1 555 graph_show_oneline(opt->graph);
c6b3ec41
JH
556 bol = (*eol) ? (eol + 1) : eol;
557 }
558}
559
0c37f1fc
JH
560static void show_signature(struct rev_info *opt, struct commit *commit)
561{
562 struct strbuf payload = STRBUF_INIT;
563 struct strbuf signature = STRBUF_INIT;
67948981 564 struct signature_check sigc = { 0 };
0c37f1fc 565 int status;
0c37f1fc 566
1fb5cf0d 567 if (parse_signed_commit(commit, &payload, &signature, the_hash_algo) <= 0)
0c37f1fc
JH
568 goto out;
569
4bbf3780 570 sigc.payload_type = SIGNATURE_PAYLOAD_COMMIT;
02769437
FS
571 sigc.payload = strbuf_detach(&payload, &sigc.payload_len);
572 status = check_signature(&sigc, signature.buf, signature.len);
b5726a5d 573 if (status && !sigc.output)
67948981
HJI
574 show_sig_lines(opt, status, "No signature\n");
575 else
b5726a5d 576 show_sig_lines(opt, status, sigc.output);
67948981 577 signature_check_clear(&sigc);
0c37f1fc
JH
578
579 out:
0c37f1fc
JH
580 strbuf_release(&payload);
581 strbuf_release(&signature);
582}
583
a92ea68f 584static int which_parent(const struct object_id *oid, const struct commit *commit)
824958e5
JH
585{
586 int nth;
587 const struct commit_list *parent;
588
589 for (nth = 0, parent = commit->parents; parent; parent = parent->next) {
4a7e27e9 590 if (oideq(&parent->item->object.oid, oid))
824958e5
JH
591 return nth;
592 nth++;
593 }
594 return -1;
595}
596
d041ffa5
JH
597static int is_common_merge(const struct commit *commit)
598{
599 return (commit->parents
600 && commit->parents->next
601 && !commit->parents->next->next);
602}
603
fef461ea
JS
604static int show_one_mergetag(struct commit *commit,
605 struct commit_extra_header *extra,
606 void *data)
824958e5 607{
063da62b 608 struct rev_info *opt = (struct rev_info *)data;
a92ea68f 609 struct object_id oid;
824958e5
JH
610 struct tag *tag;
611 struct strbuf verify_message;
67948981 612 struct signature_check sigc = { 0 };
824958e5 613 int status, nth;
482c1191 614 struct strbuf payload = STRBUF_INIT;
615 struct strbuf signature = STRBUF_INIT;
824958e5 616
2dcde20e 617 hash_object_file(the_hash_algo, extra->value, extra->len,
44439c1c 618 OBJ_TAG, &oid);
ce71efb7 619 tag = lookup_tag(the_repository, &oid);
824958e5 620 if (!tag)
fef461ea 621 return -1; /* error message already given */
824958e5
JH
622
623 strbuf_init(&verify_message, 256);
0e740fed 624 if (parse_tag_buffer(the_repository, tag, extra->value, extra->len))
824958e5 625 strbuf_addstr(&verify_message, "malformed mergetag\n");
d041ffa5 626 else if (is_common_merge(commit) &&
4a7e27e9
JK
627 oideq(&tag->tagged->oid,
628 &commit->parents->next->item->object.oid))
d041ffa5
JH
629 strbuf_addf(&verify_message,
630 "merged tag '%s'\n", tag->tag);
a92ea68f 631 else if ((nth = which_parent(&tag->tagged->oid, commit)) < 0)
824958e5 632 strbuf_addf(&verify_message, "tag %s names a non-parent %s\n",
237a2817 633 tag->tag, oid_to_hex(&tag->tagged->oid));
824958e5
JH
634 else
635 strbuf_addf(&verify_message,
636 "parent #%d, tagged '%s'\n", nth + 1, tag->tag);
824958e5 637
1315093f 638 status = -1;
482c1191 639 if (parse_signature(extra->value, extra->len, &payload, &signature)) {
42c55ce4 640 /* could have a good signature */
4bbf3780 641 sigc.payload_type = SIGNATURE_PAYLOAD_TAG;
02769437
FS
642 sigc.payload = strbuf_detach(&payload, &sigc.payload_len);
643 status = check_signature(&sigc, signature.buf, signature.len);
b5726a5d
FS
644 if (sigc.output)
645 strbuf_addstr(&verify_message, sigc.output);
67948981 646 else
42c55ce4 647 strbuf_addstr(&verify_message, "No signature\n");
67948981 648 signature_check_clear(&sigc);
42c55ce4
MG
649 /* otherwise we couldn't verify, which is shown as bad */
650 }
824958e5
JH
651
652 show_sig_lines(opt, status, verify_message.buf);
653 strbuf_release(&verify_message);
482c1191 654 strbuf_release(&payload);
655 strbuf_release(&signature);
fef461ea 656 return 0;
824958e5
JH
657}
658
fef461ea 659static int show_mergetag(struct rev_info *opt, struct commit *commit)
824958e5 660{
fef461ea 661 return for_each_mergetag(show_one_mergetag, commit, opt);
824958e5
JH
662}
663
3fcc7a23
ES
664static void next_commentary_block(struct rev_info *opt, struct strbuf *sb)
665{
666 const char *x = opt->shown_dashes ? "\n" : "---\n";
667 if (sb)
668 strbuf_addstr(sb, x);
669 else
670 fputs(x, opt->diffopt.file);
671 opt->shown_dashes = 1;
672}
673
02865655 674void show_log(struct rev_info *opt)
91539833 675{
f285a2d7 676 struct strbuf msgbuf = STRBUF_INIT;
39bc9a6c 677 struct log_info *log = opt->loginfo;
91539833 678 struct commit *commit = log->commit, *parent = log->parent;
2ed1960a 679 int abbrev_commit = opt->abbrev_commit ? opt->abbrev : the_hash_algo->hexsz;
dd2e794a
TR
680 const char *extra_headers = opt->extra_headers;
681 struct pretty_print_context ctx = {0};
91539833
LT
682
683 opt->loginfo = NULL;
684 if (!opt->verbose_header) {
7fefda5c
AS
685 graph_show_commit(opt->graph);
686
1df2d656 687 if (!opt->graph)
b1b47554 688 put_revision_mark(opt, commit);
d850b7a5
ÆAB
689 fputs(repo_find_unique_abbrev(the_repository, &commit->object.oid, abbrev_commit),
690 opt->diffopt.file);
885cf808 691 if (opt->print_parents)
4d7b0efc 692 show_parents(commit, abbrev_commit, opt->diffopt.file);
91b849b2
JS
693 if (opt->children.name)
694 show_children(opt, commit, abbrev_commit);
0f3a290b 695 show_decorations(opt, commit);
7fefda5c 696 if (opt->graph && !graph_is_commit_finished(opt->graph)) {
4d7b0efc 697 putc('\n', opt->diffopt.file);
7fefda5c
AS
698 graph_show_remainder(opt->graph);
699 }
4d7b0efc 700 putc(opt->diffopt.line_termination, opt->diffopt.file);
91539833
LT
701 return;
702 }
703
704 /*
8715227d
JK
705 * If use_terminator is set, we already handled any record termination
706 * at the end of the last record.
02865655
AS
707 * Otherwise, add a diffopt.line_termination character before all
708 * entries but the first. (IOW, as a separator between entries)
91539833 709 */
7fefda5c
AS
710 if (opt->shown_one && !opt->use_terminator) {
711 /*
712 * If entries are separated by a newline, the output
713 * should look human-readable. If the last entry ended
714 * with a newline, print the graph output before this
715 * newline. Otherwise it will end up as a completely blank
716 * line and will look like a gap in the graph.
717 *
718 * If the entry separator is not a newline, the output is
719 * primarily intended for programmatic consumption, and we
720 * never want the extra graph output before the entry
721 * separator.
722 */
723 if (opt->diffopt.line_termination == '\n' &&
724 !opt->missing_newline)
725 graph_show_padding(opt->graph);
4d7b0efc 726 putc(opt->diffopt.line_termination, opt->diffopt.file);
7fefda5c 727 }
91539833
LT
728 opt->shown_one = 1;
729
7fefda5c
AS
730 /*
731 * If the history graph was requested,
732 * print the graph, up to this commit's line
733 */
734 graph_show_commit(opt->graph);
735
91539833
LT
736 /*
737 * Print header line of header..
738 */
3eefc189 739
9f23e040 740 if (cmit_fmt_is_mail(opt->commit_format)) {
6d167fd7 741 log_write_email_headers(opt, commit, &extra_headers,
50cd54ef 742 &ctx.need_8bit_cte, 1);
6d167fd7
RS
743 ctx.rev = opt;
744 ctx.print_email_subject = 1;
e52a5de4 745 } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
4d7b0efc 746 fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), opt->diffopt.file);
74bd9029 747 if (opt->commit_format != CMIT_FMT_ONELINE)
4d7b0efc 748 fputs("commit ", opt->diffopt.file);
7528f27d 749
1df2d656 750 if (!opt->graph)
b1b47554 751 put_revision_mark(opt, commit);
d850b7a5
ÆAB
752 fputs(repo_find_unique_abbrev(the_repository, &commit->object.oid,
753 abbrev_commit),
4d7b0efc 754 opt->diffopt.file);
885cf808 755 if (opt->print_parents)
4d7b0efc 756 show_parents(commit, abbrev_commit, opt->diffopt.file);
91b849b2
JS
757 if (opt->children.name)
758 show_children(opt, commit, abbrev_commit);
73f0a157 759 if (parent)
4d7b0efc 760 fprintf(opt->diffopt.file, " (from %s)",
d850b7a5 761 repo_find_unique_abbrev(the_repository, &parent->object.oid, abbrev_commit));
4d7b0efc 762 fputs(diff_get_color_opt(&opt->diffopt, DIFF_RESET), opt->diffopt.file);
0f3a290b 763 show_decorations(opt, commit);
7fefda5c 764 if (opt->commit_format == CMIT_FMT_ONELINE) {
4d7b0efc 765 putc(' ', opt->diffopt.file);
7fefda5c 766 } else {
4d7b0efc 767 putc('\n', opt->diffopt.file);
7fefda5c
AS
768 graph_show_oneline(opt->graph);
769 }
903b45fe 770 if (opt->reflog_info) {
7fefda5c
AS
771 /*
772 * setup_revisions() ensures that opt->reflog_info
773 * and opt->graph cannot both be set,
774 * so we don't need to worry about printing the
775 * graph info here.
776 */
4d12a471 777 show_reflog_message(opt->reflog_info,
55ccf85a 778 opt->commit_format == CMIT_FMT_ONELINE,
a5481a6c 779 &opt->date_mode,
55ccf85a 780 opt->date_mode_explicit);
02865655 781 if (opt->commit_format == CMIT_FMT_ONELINE)
903b45fe 782 return;
903b45fe 783 }
3eefc189 784 }
91539833 785
824958e5 786 if (opt->show_signature) {
0c37f1fc 787 show_signature(opt, commit);
824958e5
JH
788 show_mergetag(opt, commit);
789 }
0c37f1fc 790
ddf333f6
JH
791 if (opt->show_notes) {
792 int raw;
793 struct strbuf notebuf = STRBUF_INIT;
794
795 raw = (opt->commit_format == CMIT_FMT_USERFORMAT);
fb61e4d3 796 format_display_notes(&commit->object.oid, &notebuf,
ddf333f6 797 get_log_output_encoding(), raw);
82f51af3 798 ctx.notes_message = strbuf_detach(&notebuf, NULL);
ddf333f6
JH
799 }
800
91539833
LT
801 /*
802 * And then the pretty-printed message itself
803 */
5289c56a
NTND
804 if (ctx.need_8bit_cte >= 0 && opt->add_signoff)
805 ctx.need_8bit_cte =
39ab4d09 806 has_non_ascii(fmt_name(WANT_COMMITTER_IDENT));
dd2e794a 807 ctx.date_mode = opt->date_mode;
f026c756 808 ctx.date_mode_explicit = opt->date_mode_explicit;
dd2e794a
TR
809 ctx.abbrev = opt->diffopt.abbrev;
810 ctx.after_subject = extra_headers;
9553d2b2 811 ctx.preserve_subject = opt->preserve_subject;
19d097e3 812 ctx.encode_email_headers = opt->encode_email_headers;
8f8f5476 813 ctx.reflog_info = opt->reflog_info;
6bf13944 814 ctx.fmt = opt->commit_format;
0e2913b0 815 ctx.mailmap = opt->mailmap;
30825178 816 ctx.color = opt->diffopt.use_color;
7cc13c71 817 ctx.expand_tabs_in_log = opt->expand_tabs_in_log;
ecaee805 818 ctx.output_encoding = get_log_output_encoding();
ad6f028f 819 ctx.rev = opt;
a9080475
JK
820 if (opt->from_ident.mail_begin && opt->from_ident.name_begin)
821 ctx.from_ident = &opt->from_ident;
3ad87c80
JK
822 if (opt->graph)
823 ctx.graph_width = graph_width(opt->graph);
6bf13944 824 pretty_print_commit(&ctx, commit, &msgbuf);
212620fe
JH
825
826 if (opt->add_signoff)
5289c56a 827 append_signoff(&msgbuf, 0, APPEND_SIGNOFF_DEDUP);
212620fe 828
5a664cf2 829 if ((ctx.fmt != CMIT_FMT_USERFORMAT) &&
bd1470b8 830 ctx.notes_message && *ctx.notes_message) {
3fcc7a23
ES
831 if (cmit_fmt_is_mail(ctx.fmt))
832 next_commentary_block(opt, &msgbuf);
5a664cf2 833 strbuf_addstr(&msgbuf, ctx.notes_message);
bd1470b8 834 }
cf2251b6 835
7fefda5c 836 if (opt->show_log_size) {
4d7b0efc 837 fprintf(opt->diffopt.file, "log size %i\n", (int)msgbuf.len);
7fefda5c
AS
838 graph_show_oneline(opt->graph);
839 }
9fa3465d 840
7fefda5c
AS
841 /*
842 * Set opt->missing_newline if msgbuf doesn't
843 * end in a newline (including if it is empty)
844 */
845 if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n')
846 opt->missing_newline = 1;
847 else
848 opt->missing_newline = 0;
849
660e113c 850 graph_show_commit_msg(opt->graph, opt->diffopt.file, &msgbuf);
b9c7d6e4 851 if (opt->use_terminator && !commit_format_is_empty(opt->commit_format)) {
7fefda5c
AS
852 if (!opt->missing_newline)
853 graph_show_padding(opt->graph);
4d7b0efc 854 putc(opt->diffopt.line_termination, opt->diffopt.file);
7fefda5c
AS
855 }
856
674d1727 857 strbuf_release(&msgbuf);
ddf333f6 858 free(ctx.notes_message);
ee6cbf71
ES
859
860 if (cmit_fmt_is_mail(ctx.fmt) && opt->idiff_oid1) {
861 struct diff_queue_struct dq;
862
863 memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
864 DIFF_QUEUE_CLEAR(&diff_queued_diff);
865
866 next_commentary_block(opt, NULL);
867 fprintf_ln(opt->diffopt.file, "%s", opt->idiff_title);
72a72390
ES
868 show_interdiff(opt->idiff_oid1, opt->idiff_oid2, 2,
869 &opt->diffopt);
ee6cbf71
ES
870
871 memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
872 }
40ce4160
ES
873
874 if (cmit_fmt_is_mail(ctx.fmt) && opt->rdiff1) {
875 struct diff_queue_struct dq;
ac0edf1f 876 struct diff_options opts;
f1ce6c19
JS
877 struct range_diff_options range_diff_opts = {
878 .creation_factor = opt->creation_factor,
879 .dual_color = 1,
880 .diffopt = &opts
881 };
40ce4160
ES
882
883 memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
884 DIFF_QUEUE_CLEAR(&diff_queued_diff);
885
886 next_commentary_block(opt, NULL);
887 fprintf_ln(opt->diffopt.file, "%s", opt->rdiff_title);
ac0edf1f
888 /*
889 * Pass minimum required diff-options to range-diff; others
890 * can be added later if deemed desirable.
891 */
08539032 892 repo_diff_setup(the_repository, &opts);
ac0edf1f
893 opts.file = opt->diffopt.file;
894 opts.use_color = opt->diffopt.use_color;
895 diff_setup_done(&opts);
f1ce6c19 896 show_range_diff(opt->rdiff1, opt->rdiff2, &range_diff_opts);
40ce4160
ES
897
898 memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
899 }
91539833
LT
900}
901
cd2bdc53 902int log_tree_diff_flush(struct rev_info *opt)
5f1c3f07 903{
bd1470b8 904 opt->shown_dashes = 0;
5f1c3f07 905 diffcore_std(&opt->diffopt);
91539833 906
95433eee 907 if (diff_queue_is_empty(&opt->diffopt)) {
5f1c3f07
JH
908 int saved_fmt = opt->diffopt.output_format;
909 opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
910 diff_flush(&opt->diffopt);
911 opt->diffopt.output_format = saved_fmt;
912 return 0;
913 }
91539833 914
3969cf7d 915 if (opt->loginfo && !opt->no_commit_id) {
02865655 916 show_log(opt);
304b5af6
LT
917 if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
918 opt->verbose_header &&
b9c7d6e4
JK
919 opt->commit_format != CMIT_FMT_ONELINE &&
920 !commit_format_is_empty(opt->commit_format)) {
1d34c50f
JH
921 /*
922 * When showing a verbose header (i.e. log message),
923 * and not in --pretty=oneline format, we would want
924 * an extra newline between the end of log and the
925 * diff/diffstat output for readability.
926 */
3969cf7d 927 int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
81bd1b2a
BY
928 if (opt->diffopt.output_prefix) {
929 struct strbuf *msg = NULL;
930 msg = opt->diffopt.output_prefix(&opt->diffopt,
931 opt->diffopt.output_prefix_data);
4d7b0efc 932 fwrite(msg->buf, msg->len, 1, opt->diffopt.file);
81bd1b2a 933 }
1d34c50f
JH
934
935 /*
936 * We may have shown three-dashes line early
3fcc7a23
ES
937 * between generated commentary (notes, etc.)
938 * and the log message, in which case we only
939 * want a blank line after the commentary
940 * without (an extra) three-dashes line.
1d34c50f
JH
941 * Otherwise, we show the three-dashes line if
942 * we are showing the patch with diffstat, but
943 * in that case, there is no extra blank line
944 * after the three-dashes line.
945 */
946 if (!opt->shown_dashes &&
947 (pch & opt->diffopt.output_format) == pch)
4d7b0efc
JS
948 fprintf(opt->diffopt.file, "---");
949 putc('\n', opt->diffopt.file);
3969cf7d
JH
950 }
951 }
5f1c3f07
JH
952 diff_flush(&opt->diffopt);
953 return 1;
954}
955
cd2bdc53 956static int do_diff_combined(struct rev_info *opt, struct commit *commit)
5f1c3f07 957{
d01141de 958 diff_tree_combined_merge(commit, opt);
91539833 959 return !opt->loginfo;
5f1c3f07
JH
960}
961
20323d10
EN
962static void setup_additional_headers(struct diff_options *o,
963 struct strmap *all_headers)
964{
965 struct hashmap_iter iter;
966 struct strmap_entry *entry;
967
968 /*
969 * Make o->additional_path_headers contain the subset of all_headers
970 * that match o->pathspec. If there aren't any that match o->pathspec,
971 * then make o->additional_path_headers be NULL.
972 */
973
974 if (!o->pathspec.nr) {
975 o->additional_path_headers = all_headers;
976 return;
977 }
978
979 o->additional_path_headers = xmalloc(sizeof(struct strmap));
980 strmap_init_with_options(o->additional_path_headers, NULL, 0);
981 strmap_for_each_entry(all_headers, &iter, entry) {
982 if (match_pathspec(the_repository->index, &o->pathspec,
983 entry->key, strlen(entry->key),
984 0 /* prefix */, NULL /* seen */,
985 0 /* is_dir */))
986 strmap_put(o->additional_path_headers,
987 entry->key, entry->value);
988 }
989 if (!strmap_get_size(o->additional_path_headers)) {
990 strmap_clear(o->additional_path_headers, 0);
991 FREE_AND_NULL(o->additional_path_headers);
992 }
993}
994
995static void cleanup_additional_headers(struct diff_options *o)
996{
997 if (!o->pathspec.nr) {
998 o->additional_path_headers = NULL;
999 return;
1000 }
1001 if (!o->additional_path_headers)
1002 return;
1003
1004 strmap_clear(o->additional_path_headers, 0);
1005 FREE_AND_NULL(o->additional_path_headers);
1006}
1007
db757e8b
EN
1008static int do_remerge_diff(struct rev_info *opt,
1009 struct commit_list *parents,
e2841f70 1010 struct object_id *oid)
db757e8b
EN
1011{
1012 struct merge_options o;
1013 struct commit_list *bases;
1014 struct merge_result res = {0};
1015 struct pretty_print_context ctx = {0};
1016 struct commit *parent1 = parents->item;
1017 struct commit *parent2 = parents->next->item;
1018 struct strbuf parent1_desc = STRBUF_INIT;
1019 struct strbuf parent2_desc = STRBUF_INIT;
1020
1021 /* Setup merge options */
1022 init_merge_options(&o, the_repository);
1023 o.show_rename_progress = 0;
20323d10
EN
1024 o.record_conflict_msgs_as_headers = 1;
1025 o.msg_header_prefix = "remerge";
db757e8b
EN
1026
1027 ctx.abbrev = DEFAULT_ABBREV;
bab82164
ÆAB
1028 repo_format_commit_message(the_repository, parent1, "%h (%s)",
1029 &parent1_desc, &ctx);
1030 repo_format_commit_message(the_repository, parent2, "%h (%s)",
1031 &parent2_desc, &ctx);
db757e8b
EN
1032 o.branch1 = parent1_desc.buf;
1033 o.branch2 = parent2_desc.buf;
1034
1035 /* Parse the relevant commits and get the merge bases */
1036 parse_commit_or_die(parent1);
1037 parse_commit_or_die(parent2);
cb338c23 1038 bases = repo_get_merge_bases(the_repository, parent1, parent2);
db757e8b
EN
1039
1040 /* Re-merge the parents */
1041 merge_incore_recursive(&o, bases, parent1, parent2, &res);
1042
1043 /* Show the diff */
20323d10 1044 setup_additional_headers(&opt->diffopt, res.path_messages);
db757e8b
EN
1045 diff_tree_oid(&res.tree->object.oid, oid, "", &opt->diffopt);
1046 log_tree_diff_flush(opt);
1047
1048 /* Cleanup */
20323d10 1049 cleanup_additional_headers(&opt->diffopt);
db757e8b
EN
1050 strbuf_release(&parent1_desc);
1051 strbuf_release(&parent2_desc);
1052 merge_finalize(&o, &res);
7b90ab46
EN
1053
1054 /* Clean up the contents of the temporary object directory */
1055 if (opt->remerge_objdir)
1056 tmp_objdir_discard_objects(opt->remerge_objdir);
1057 else
1058 BUG("did a remerge diff without remerge_objdir?!?");
db757e8b
EN
1059
1060 return !opt->loginfo;
1061}
1062
91539833
LT
1063/*
1064 * Show the diff of a commit.
1065 *
1066 * Return true if we printed any log info messages
1067 */
1068static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
5f1c3f07 1069{
91539833 1070 int showed_log;
5f1c3f07 1071 struct commit_list *parents;
f2fd0760 1072 struct object_id *oid;
a6d19ecc
SO
1073 int is_merge;
1074 int all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
5f1c3f07 1075
a6d19ecc 1076 if (!all_need_diff && !opt->merges_need_diff)
91539833
LT
1077 return 0;
1078
7059dccc 1079 parse_commit_or_die(commit);
2e27bd77 1080 oid = get_commit_tree_oid(commit);
d1b9b767 1081
53d00b39 1082 parents = get_saved_parents(opt, commit);
a6d19ecc
SO
1083 is_merge = parents && parents->next;
1084 if (!is_merge && !all_need_diff)
1085 return 0;
1086
1087 /* Root commit? */
91539833 1088 if (!parents) {
2b60356d 1089 if (opt->show_root_diff) {
7b8dea0c 1090 diff_root_tree_oid(oid, "", &opt->diffopt);
2b60356d
RS
1091 log_tree_diff_flush(opt);
1092 }
91539833 1093 return !opt->loginfo;
5f1c3f07
JH
1094 }
1095
a6d19ecc 1096 if (is_merge) {
db757e8b
EN
1097 int octopus = (parents->next->next != NULL);
1098
1099 if (opt->remerge_diff) {
1100 if (octopus) {
1101 show_log(opt);
1102 fprintf(opt->diffopt.file,
1103 "diff: warning: Skipping remerge-diff "
1104 "for octopus merges.\n");
1105 return 1;
1106 }
e2841f70 1107 return do_remerge_diff(opt, parents, oid);
db757e8b 1108 }
1a2c4d80 1109 if (opt->combine_merges)
5f1c3f07 1110 return do_diff_combined(opt, commit);
1a2c4d80
SO
1111 if (opt->separate_merges) {
1112 if (!opt->first_parent_merges) {
1113 /* Show parent info for multiple diffs */
1114 log->parent = parents->item;
1115 }
1116 } else
1117 return 0;
5f1c3f07
JH
1118 }
1119
91539833
LT
1120 showed_log = 0;
1121 for (;;) {
5f1c3f07 1122 struct commit *parent = parents->item;
5f1c3f07 1123
7059dccc 1124 parse_commit_or_die(parent);
2e27bd77 1125 diff_tree_oid(get_commit_tree_oid(parent),
66f414f8 1126 oid, "", &opt->diffopt);
91539833
LT
1127 log_tree_diff_flush(opt);
1128
1129 showed_log |= !opt->loginfo;
1130
1131 /* Set up the log info for the next parent, if any.. */
1132 parents = parents->next;
3291eea3 1133 if (!parents || opt->first_parent_merges)
91539833
LT
1134 break;
1135 log->parent = parents->item;
1136 opt->loginfo = log;
1137 }
1138 return showed_log;
1139}
1140
1141int log_tree_commit(struct rev_info *opt, struct commit *commit)
1142{
1143 struct log_info log;
e900d494
ÆAB
1144 int shown;
1145 /* maybe called by e.g. cmd_log_walk(), maybe stand-alone */
1146 int no_free = opt->diffopt.no_free;
91539833
LT
1147
1148 log.commit = commit;
1149 log.parent = NULL;
1150 opt->loginfo = &log;
e900d494 1151 opt->diffopt.no_free = 1;
91539833 1152
f8781bfd 1153 /* NEEDSWORK: no restoring of no_free? Why? */
12da1d1f
TR
1154 if (opt->line_level_traverse)
1155 return line_log_print(opt, commit);
1156
1b32dece 1157 if (opt->track_linear && !opt->linear && !opt->reverse_output_stage)
4d7b0efc 1158 fprintf(opt->diffopt.file, "\n%s\n", opt->break_bar);
3eefc189
JH
1159 shown = log_tree_diff(opt, commit, &log);
1160 if (!shown && opt->loginfo && opt->always_show_header) {
91539833 1161 log.parent = NULL;
02865655 1162 show_log(opt);
3eefc189 1163 shown = 1;
5f1c3f07 1164 }
1b32dece 1165 if (opt->track_linear && !opt->linear && opt->reverse_output_stage)
4d7b0efc 1166 fprintf(opt->diffopt.file, "\n%s\n", opt->break_bar);
91539833 1167 opt->loginfo = NULL;
4d7b0efc 1168 maybe_flush_or_die(opt->diffopt.file, "stdout");
e900d494
ÆAB
1169 opt->diffopt.no_free = no_free;
1170 diff_free(&opt->diffopt);
3eefc189 1171 return shown;
5f1c3f07 1172}