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