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