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