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