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