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