Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1 | #include "cache.h" |
Elijah Newren | db757e8 | 2022-02-02 02:37:28 +0000 | [diff] [blame] | 2 | #include "commit-reach.h" |
Brandon Williams | b2141fc | 2017-06-14 11:07:36 -0700 | [diff] [blame] | 3 | #include "config.h" |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 4 | #include "diff.h" |
Stefan Beller | cbd53a2 | 2018-05-15 16:42:15 -0700 | [diff] [blame] | 5 | #include "object-store.h" |
Stefan Beller | 109cd76 | 2018-06-28 18:21:51 -0700 | [diff] [blame] | 6 | #include "repository.h" |
Elijah Newren | 7b90ab4 | 2022-02-02 02:37:29 +0000 | [diff] [blame] | 7 | #include "tmp-objdir.h" |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 8 | #include "commit.h" |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 9 | #include "tag.h" |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 10 | #include "graph.h" |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 11 | #include "log-tree.h" |
Elijah Newren | db757e8 | 2022-02-02 02:37:28 +0000 | [diff] [blame] | 12 | #include "merge-ort.h" |
Johannes Schindelin | 8860fd4 | 2007-01-11 11:47:48 +0100 | [diff] [blame] | 13 | #include "reflog-walk.h" |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 14 | #include "refs.h" |
Thomas Rast | b079c50 | 2009-02-19 22:26:31 +0100 | [diff] [blame] | 15 | #include "string-list.h" |
Nazri Ramliy | 67a4b58 | 2010-06-19 09:37:35 +0800 | [diff] [blame] | 16 | #include "color.h" |
Junio C Hamano | 0c37f1f | 2011-10-18 15:53:23 -0700 | [diff] [blame] | 17 | #include "gpg-interface.h" |
Brandon Casey | 959a262 | 2013-02-12 02:17:39 -0800 | [diff] [blame] | 18 | #include "sequencer.h" |
Thomas Rast | 12da1d1 | 2013-03-28 17:47:32 +0100 | [diff] [blame] | 19 | #include "line-log.h" |
Nguyễn Thái Ngọc Duy | 3ac68a9 | 2018-05-26 15:55:24 +0200 | [diff] [blame] | 20 | #include "help.h" |
Eric Sunshine | 40ce416 | 2018-07-22 05:57:17 -0400 | [diff] [blame] | 21 | #include "range-diff.h" |
Elijah Newren | 20323d1 | 2022-02-02 02:37:35 +0000 | [diff] [blame] | 22 | #include "strmap.h" |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 23 | |
Jeff King | 2608c24 | 2014-08-26 06:23:54 -0400 | [diff] [blame] | 24 | static struct decoration name_decoration = { "object names" }; |
Junio C Hamano | 76c61fb | 2015-05-13 10:25:18 -0700 | [diff] [blame] | 25 | static int decoration_loaded; |
| 26 | static int decoration_flags; |
Nazri Ramliy | a752412 | 2010-06-19 09:37:34 +0800 | [diff] [blame] | 27 | |
Nazri Ramliy | 67a4b58 | 2010-06-19 09:37:35 +0800 | [diff] [blame] | 28 | static char decoration_colors[][COLOR_MAXLEN] = { |
| 29 | GIT_COLOR_RESET, |
| 30 | GIT_COLOR_BOLD_GREEN, /* REF_LOCAL */ |
| 31 | GIT_COLOR_BOLD_RED, /* REF_REMOTE */ |
| 32 | GIT_COLOR_BOLD_YELLOW, /* REF_TAG */ |
| 33 | GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */ |
| 34 | GIT_COLOR_BOLD_CYAN, /* REF_HEAD */ |
Nguyễn Thái Ngọc Duy | 76f5df3 | 2011-08-18 19:29:37 +0700 | [diff] [blame] | 35 | GIT_COLOR_BOLD_BLUE, /* GRAFTED */ |
Nazri Ramliy | 67a4b58 | 2010-06-19 09:37:35 +0800 | [diff] [blame] | 36 | }; |
| 37 | |
Nguyễn Thái Ngọc Duy | a73b368 | 2018-05-26 15:55:21 +0200 | [diff] [blame] | 38 | static const char *color_decorate_slots[] = { |
| 39 | [DECORATION_REF_LOCAL] = "branch", |
| 40 | [DECORATION_REF_REMOTE] = "remoteBranch", |
| 41 | [DECORATION_REF_TAG] = "tag", |
| 42 | [DECORATION_REF_STASH] = "stash", |
| 43 | [DECORATION_REF_HEAD] = "HEAD", |
Nguyễn Thái Ngọc Duy | 09c4ba4 | 2018-05-26 15:55:31 +0200 | [diff] [blame] | 44 | [DECORATION_GRAFTED] = "grafted", |
Nguyễn Thái Ngọc Duy | a73b368 | 2018-05-26 15:55:21 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
Nazri Ramliy | 67a4b58 | 2010-06-19 09:37:35 +0800 | [diff] [blame] | 47 | static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix) |
| 48 | { |
Jeff King | daa0c3d | 2011-08-17 22:04:23 -0700 | [diff] [blame] | 49 | if (want_color(decorate_use_color)) |
Nazri Ramliy | 67a4b58 | 2010-06-19 09:37:35 +0800 | [diff] [blame] | 50 | return decoration_colors[ix]; |
| 51 | return ""; |
| 52 | } |
| 53 | |
Nguyễn Thái Ngọc Duy | 3ac68a9 | 2018-05-26 15:55:24 +0200 | [diff] [blame] | 54 | define_list_config_array(color_decorate_slots); |
Nazri Ramliy | 5e11bee | 2010-06-24 08:21:16 +0800 | [diff] [blame] | 55 | |
Jonathan Nieder | 8852117 | 2014-10-07 15:16:57 -0400 | [diff] [blame] | 56 | int parse_decorate_color_config(const char *var, const char *slot_name, const char *value) |
Nazri Ramliy | 5e11bee | 2010-06-24 08:21:16 +0800 | [diff] [blame] | 57 | { |
Nguyễn Thái Ngọc Duy | a73b368 | 2018-05-26 15:55:21 +0200 | [diff] [blame] | 58 | int slot = LOOKUP_CONFIG(color_decorate_slots, slot_name); |
Nazri Ramliy | 5e11bee | 2010-06-24 08:21:16 +0800 | [diff] [blame] | 59 | if (slot < 0) |
| 60 | return 0; |
| 61 | if (!value) |
| 62 | return config_error_nonbool(var); |
Jeff King | f6c5a29 | 2014-10-07 15:33:09 -0400 | [diff] [blame] | 63 | return color_parse(value, decoration_colors[slot]); |
Nazri Ramliy | 5e11bee | 2010-06-24 08:21:16 +0800 | [diff] [blame] | 64 | } |
| 65 | |
Nazri Ramliy | 67a4b58 | 2010-06-19 09:37:35 +0800 | [diff] [blame] | 66 | /* |
| 67 | * log-tree.c uses DIFF_OPT_TST for determining whether to use color |
| 68 | * for showing the commit sha1, use the same check for --decorate |
| 69 | */ |
| 70 | #define decorate_get_color_opt(o, ix) \ |
Jeff King | f1c9626 | 2011-08-17 22:03:12 -0700 | [diff] [blame] | 71 | decorate_get_color((o)->use_color, ix) |
Nazri Ramliy | 67a4b58 | 2010-06-19 09:37:35 +0800 | [diff] [blame] | 72 | |
Jeff King | 662174d | 2014-08-26 06:23:36 -0400 | [diff] [blame] | 73 | void add_name_decoration(enum decoration_type type, const char *name, struct object *obj) |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 74 | { |
Jeff King | 96ffc06 | 2016-02-22 17:44:32 -0500 | [diff] [blame] | 75 | struct name_decoration *res; |
| 76 | FLEX_ALLOC_STR(res, name, name); |
Nazri Ramliy | a752412 | 2010-06-19 09:37:34 +0800 | [diff] [blame] | 77 | res->type = type; |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 78 | res->next = add_decoration(&name_decoration, obj, res); |
| 79 | } |
| 80 | |
Jeff King | 2608c24 | 2014-08-26 06:23:54 -0400 | [diff] [blame] | 81 | const struct name_decoration *get_name_decoration(const struct object *obj) |
| 82 | { |
René Scharfe | 0cc7380 | 2019-09-08 19:58:51 +0200 | [diff] [blame] | 83 | load_ref_decorations(NULL, DECORATE_SHORT_REFS); |
Jeff King | 2608c24 | 2014-08-26 06:23:54 -0400 | [diff] [blame] | 84 | return lookup_decoration(&name_decoration, obj); |
| 85 | } |
| 86 | |
Derrick Stolee | c9f7a79 | 2020-04-16 14:15:48 +0000 | [diff] [blame] | 87 | static int match_ref_pattern(const char *refname, |
| 88 | const struct string_list_item *item) |
| 89 | { |
| 90 | int matched = 0; |
| 91 | if (item->util == NULL) { |
| 92 | if (!wildmatch(item->string, refname, 0)) |
| 93 | matched = 1; |
| 94 | } else { |
| 95 | const char *rest; |
| 96 | if (skip_prefix(refname, item->string, &rest) && |
| 97 | (!*rest || *rest == '/')) |
| 98 | matched = 1; |
| 99 | } |
| 100 | return matched; |
| 101 | } |
| 102 | |
| 103 | static int ref_filter_match(const char *refname, |
| 104 | const struct decoration_filter *filter) |
| 105 | { |
| 106 | struct string_list_item *item; |
| 107 | const struct string_list *exclude_patterns = filter->exclude_ref_pattern; |
| 108 | const struct string_list *include_patterns = filter->include_ref_pattern; |
Derrick Stolee | a6be5e6 | 2020-04-16 14:15:49 +0000 | [diff] [blame] | 109 | const struct string_list *exclude_patterns_config = |
| 110 | filter->exclude_ref_config_pattern; |
Derrick Stolee | c9f7a79 | 2020-04-16 14:15:48 +0000 | [diff] [blame] | 111 | |
| 112 | if (exclude_patterns && exclude_patterns->nr) { |
| 113 | for_each_string_list_item(item, exclude_patterns) { |
| 114 | if (match_ref_pattern(refname, item)) |
| 115 | return 0; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if (include_patterns && include_patterns->nr) { |
Derrick Stolee | c9f7a79 | 2020-04-16 14:15:48 +0000 | [diff] [blame] | 120 | for_each_string_list_item(item, include_patterns) { |
Derrick Stolee | a6be5e6 | 2020-04-16 14:15:49 +0000 | [diff] [blame] | 121 | if (match_ref_pattern(refname, item)) |
| 122 | return 1; |
Derrick Stolee | c9f7a79 | 2020-04-16 14:15:48 +0000 | [diff] [blame] | 123 | } |
Derrick Stolee | a6be5e6 | 2020-04-16 14:15:49 +0000 | [diff] [blame] | 124 | return 0; |
Derrick Stolee | c9f7a79 | 2020-04-16 14:15:48 +0000 | [diff] [blame] | 125 | } |
Derrick Stolee | a6be5e6 | 2020-04-16 14:15:49 +0000 | [diff] [blame] | 126 | |
| 127 | if (exclude_patterns_config && exclude_patterns_config->nr) { |
| 128 | for_each_string_list_item(item, exclude_patterns_config) { |
| 129 | if (match_ref_pattern(refname, item)) |
| 130 | return 0; |
| 131 | } |
| 132 | } |
| 133 | |
Derrick Stolee | c9f7a79 | 2020-04-16 14:15:48 +0000 | [diff] [blame] | 134 | return 1; |
| 135 | } |
| 136 | |
Michael Haggerty | f124b73 | 2015-05-25 18:38:57 +0000 | [diff] [blame] | 137 | static int add_ref_decoration(const char *refname, const struct object_id *oid, |
| 138 | int flags, void *cb_data) |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 139 | { |
Nguyễn Thái Ngọc Duy | 5267d29 | 2011-08-19 19:43:50 +0700 | [diff] [blame] | 140 | struct object *obj; |
Jeff King | 88473c8 | 2021-06-22 13:06:48 -0400 | [diff] [blame] | 141 | enum object_type objtype; |
Jeff King | 6afb265 | 2021-06-22 13:09:26 -0400 | [diff] [blame] | 142 | enum decoration_type deco_type = DECORATION_NONE; |
Rafael Ascensão | 65516f5 | 2017-11-21 21:33:41 +0000 | [diff] [blame] | 143 | struct decoration_filter *filter = (struct decoration_filter *)cb_data; |
Nguyễn Thái Ngọc Duy | 5267d29 | 2011-08-19 19:43:50 +0700 | [diff] [blame] | 144 | |
Derrick Stolee | c9f7a79 | 2020-04-16 14:15:48 +0000 | [diff] [blame] | 145 | if (filter && !ref_filter_match(refname, filter)) |
Rafael Ascensão | 65516f5 | 2017-11-21 21:33:41 +0000 | [diff] [blame] | 146 | return 0; |
Junio C Hamano | 429ad20 | 2015-05-13 12:40:35 -0700 | [diff] [blame] | 147 | |
Mike Hommey | 58d121b | 2015-06-12 06:34:59 +0900 | [diff] [blame] | 148 | if (starts_with(refname, git_replace_ref_base)) { |
Michael Haggerty | 3d79f65 | 2015-05-25 18:38:58 +0000 | [diff] [blame] | 149 | struct object_id original_oid; |
Jeff King | 6ebd1ca | 2018-07-18 16:45:20 -0400 | [diff] [blame] | 150 | if (!read_replace_refs) |
Michael J Gruber | b9ad500 | 2011-08-25 17:09:30 +0200 | [diff] [blame] | 151 | return 0; |
Junio C Hamano | 31a0ad5 | 2015-08-03 11:01:10 -0700 | [diff] [blame] | 152 | if (get_oid_hex(refname + strlen(git_replace_ref_base), |
| 153 | &original_oid)) { |
Nguyễn Thái Ngọc Duy | 5267d29 | 2011-08-19 19:43:50 +0700 | [diff] [blame] | 154 | warning("invalid replace ref %s", refname); |
| 155 | return 0; |
| 156 | } |
Stefan Beller | 109cd76 | 2018-06-28 18:21:51 -0700 | [diff] [blame] | 157 | obj = parse_object(the_repository, &original_oid); |
Nguyễn Thái Ngọc Duy | 5267d29 | 2011-08-19 19:43:50 +0700 | [diff] [blame] | 158 | if (obj) |
| 159 | add_name_decoration(DECORATION_GRAFTED, "replaced", obj); |
| 160 | return 0; |
| 161 | } |
| 162 | |
Jeff King | 88473c8 | 2021-06-22 13:06:48 -0400 | [diff] [blame] | 163 | objtype = oid_object_info(the_repository, oid, NULL); |
| 164 | if (objtype < 0) |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 165 | return 0; |
Jeff King | 88473c8 | 2021-06-22 13:06:48 -0400 | [diff] [blame] | 166 | obj = lookup_object_by_type(the_repository, oid, objtype); |
Nazri Ramliy | a752412 | 2010-06-19 09:37:34 +0800 | [diff] [blame] | 167 | |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 168 | if (starts_with(refname, "refs/heads/")) |
Jeff King | 6afb265 | 2021-06-22 13:09:26 -0400 | [diff] [blame] | 169 | deco_type = DECORATION_REF_LOCAL; |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 170 | else if (starts_with(refname, "refs/remotes/")) |
Jeff King | 6afb265 | 2021-06-22 13:09:26 -0400 | [diff] [blame] | 171 | deco_type = DECORATION_REF_REMOTE; |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 172 | else if (starts_with(refname, "refs/tags/")) |
Jeff King | 6afb265 | 2021-06-22 13:09:26 -0400 | [diff] [blame] | 173 | deco_type = DECORATION_REF_TAG; |
Nguyễn Thái Ngọc Duy | 97ba642 | 2012-01-05 19:39:40 +0700 | [diff] [blame] | 174 | else if (!strcmp(refname, "refs/stash")) |
Jeff King | 6afb265 | 2021-06-22 13:09:26 -0400 | [diff] [blame] | 175 | deco_type = DECORATION_REF_STASH; |
Nguyễn Thái Ngọc Duy | 97ba642 | 2012-01-05 19:39:40 +0700 | [diff] [blame] | 176 | else if (!strcmp(refname, "HEAD")) |
Jeff King | 6afb265 | 2021-06-22 13:09:26 -0400 | [diff] [blame] | 177 | deco_type = DECORATION_REF_HEAD; |
Nazri Ramliy | a752412 | 2010-06-19 09:37:34 +0800 | [diff] [blame] | 178 | |
Jeff King | 6afb265 | 2021-06-22 13:09:26 -0400 | [diff] [blame] | 179 | add_name_decoration(deco_type, refname, obj); |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 180 | while (obj->type == OBJ_TAG) { |
Jeff King | d1ed8d6 | 2021-07-14 12:31:36 -0400 | [diff] [blame] | 181 | if (!obj->parsed) |
| 182 | parse_object(the_repository, &obj->oid); |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 183 | obj = ((struct tag *)obj)->tagged; |
| 184 | if (!obj) |
| 185 | break; |
Nazri Ramliy | a752412 | 2010-06-19 09:37:34 +0800 | [diff] [blame] | 186 | add_name_decoration(DECORATION_REF_TAG, refname, obj); |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 187 | } |
| 188 | return 0; |
| 189 | } |
| 190 | |
Nguyễn Thái Ngọc Duy | 76f5df3 | 2011-08-18 19:29:37 +0700 | [diff] [blame] | 191 | static int add_graft_decoration(const struct commit_graft *graft, void *cb_data) |
| 192 | { |
Stefan Beller | c1f5eb4 | 2018-06-28 18:21:59 -0700 | [diff] [blame] | 193 | struct commit *commit = lookup_commit(the_repository, &graft->oid); |
Nguyễn Thái Ngọc Duy | 76f5df3 | 2011-08-18 19:29:37 +0700 | [diff] [blame] | 194 | if (!commit) |
| 195 | return 0; |
| 196 | add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object); |
| 197 | return 0; |
| 198 | } |
| 199 | |
Rafael Ascensão | 65516f5 | 2017-11-21 21:33:41 +0000 | [diff] [blame] | 200 | void load_ref_decorations(struct decoration_filter *filter, int flags) |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 201 | { |
Junio C Hamano | 76c61fb | 2015-05-13 10:25:18 -0700 | [diff] [blame] | 202 | if (!decoration_loaded) { |
Rafael Ascensão | 65516f5 | 2017-11-21 21:33:41 +0000 | [diff] [blame] | 203 | if (filter) { |
| 204 | struct string_list_item *item; |
| 205 | for_each_string_list_item(item, filter->exclude_ref_pattern) { |
| 206 | normalize_glob_ref(item, NULL, item->string); |
| 207 | } |
| 208 | for_each_string_list_item(item, filter->include_ref_pattern) { |
| 209 | normalize_glob_ref(item, NULL, item->string); |
| 210 | } |
Derrick Stolee | a6be5e6 | 2020-04-16 14:15:49 +0000 | [diff] [blame] | 211 | for_each_string_list_item(item, filter->exclude_ref_config_pattern) { |
| 212 | normalize_glob_ref(item, NULL, item->string); |
| 213 | } |
Rafael Ascensão | 65516f5 | 2017-11-21 21:33:41 +0000 | [diff] [blame] | 214 | } |
Junio C Hamano | 76c61fb | 2015-05-13 10:25:18 -0700 | [diff] [blame] | 215 | decoration_loaded = 1; |
| 216 | decoration_flags = flags; |
Rafael Ascensão | 65516f5 | 2017-11-21 21:33:41 +0000 | [diff] [blame] | 217 | for_each_ref(add_ref_decoration, filter); |
| 218 | head_ref(add_ref_decoration, filter); |
| 219 | for_each_commit_graft(add_graft_decoration, filter); |
René Scharfe | cab4feb | 2008-09-04 23:39:21 +0200 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 223 | static void show_parents(struct commit *commit, int abbrev, FILE *file) |
Linus Torvalds | c8c893c | 2006-05-03 07:59:00 -0700 | [diff] [blame] | 224 | { |
| 225 | struct commit_list *p; |
| 226 | for (p = commit->parents; p ; p = p->next) { |
| 227 | struct commit *parent = p->item; |
brian m. carlson | aab9583 | 2018-03-12 02:27:30 +0000 | [diff] [blame] | 228 | fprintf(file, " %s", find_unique_abbrev(&parent->object.oid, abbrev)); |
Linus Torvalds | c8c893c | 2006-05-03 07:59:00 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
Jay Soffian | 91b849b | 2011-10-04 10:02:03 -0400 | [diff] [blame] | 232 | static void show_children(struct rev_info *opt, struct commit *commit, int abbrev) |
| 233 | { |
| 234 | struct commit_list *p = lookup_decoration(&opt->children, &commit->object); |
| 235 | for ( ; p; p = p->next) { |
brian m. carlson | aab9583 | 2018-03-12 02:27:30 +0000 | [diff] [blame] | 236 | fprintf(opt->diffopt.file, " %s", find_unique_abbrev(&p->item->object.oid, abbrev)); |
Jay Soffian | 91b849b | 2011-10-04 10:02:03 -0400 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
Nguyễn Thái Ngọc Duy | 9d3f002 | 2013-04-19 09:08:43 +1000 | [diff] [blame] | 240 | /* |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 241 | * Do we have HEAD in the output, and also the branch it points at? |
| 242 | * If so, find that decoration entry for that current branch. |
| 243 | */ |
| 244 | static const struct name_decoration *current_pointed_by_HEAD(const struct name_decoration *decoration) |
| 245 | { |
| 246 | const struct name_decoration *list, *head = NULL; |
| 247 | const char *branch_name = NULL; |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 248 | int rru_flags; |
| 249 | |
| 250 | /* First find HEAD */ |
| 251 | for (list = decoration; list; list = list->next) |
| 252 | if (list->type == DECORATION_REF_HEAD) { |
| 253 | head = list; |
| 254 | break; |
| 255 | } |
| 256 | if (!head) |
| 257 | return NULL; |
| 258 | |
| 259 | /* Now resolve and find the matching current branch */ |
René Scharfe | 744c040 | 2017-09-23 11:45:04 +0200 | [diff] [blame] | 260 | branch_name = resolve_ref_unsafe("HEAD", 0, NULL, &rru_flags); |
Jeff King | d79be49 | 2017-10-19 13:49:01 -0400 | [diff] [blame] | 261 | if (!branch_name || !(rru_flags & REF_ISSYMREF)) |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 262 | return NULL; |
Junio C Hamano | 76c61fb | 2015-05-13 10:25:18 -0700 | [diff] [blame] | 263 | |
Junio C Hamano | 429ad20 | 2015-05-13 12:40:35 -0700 | [diff] [blame] | 264 | if (!starts_with(branch_name, "refs/")) |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 265 | return NULL; |
| 266 | |
| 267 | /* OK, do we have that ref in the list? */ |
| 268 | for (list = decoration; list; list = list->next) |
| 269 | if ((list->type == DECORATION_REF_LOCAL) && |
| 270 | !strcmp(branch_name, list->name)) { |
| 271 | return list; |
| 272 | } |
| 273 | |
| 274 | return NULL; |
| 275 | } |
| 276 | |
Junio C Hamano | 429ad20 | 2015-05-13 12:40:35 -0700 | [diff] [blame] | 277 | static void show_name(struct strbuf *sb, const struct name_decoration *decoration) |
| 278 | { |
| 279 | if (decoration_flags == DECORATE_SHORT_REFS) |
| 280 | strbuf_addstr(sb, prettify_refname(decoration->name)); |
| 281 | else |
| 282 | strbuf_addstr(sb, decoration->name); |
| 283 | } |
| 284 | |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 285 | /* |
Harry Jeffery | 9271095 | 2014-09-18 21:53:53 +0100 | [diff] [blame] | 286 | * The caller makes sure there is no funny color before calling. |
| 287 | * format_decorations_extended makes sure the same after return. |
Nguyễn Thái Ngọc Duy | 9d3f002 | 2013-04-19 09:08:43 +1000 | [diff] [blame] | 288 | */ |
Harry Jeffery | 9271095 | 2014-09-18 21:53:53 +0100 | [diff] [blame] | 289 | void format_decorations_extended(struct strbuf *sb, |
Nguyễn Thái Ngọc Duy | 9d3f002 | 2013-04-19 09:08:43 +1000 | [diff] [blame] | 290 | const struct commit *commit, |
Harry Jeffery | 9271095 | 2014-09-18 21:53:53 +0100 | [diff] [blame] | 291 | int use_color, |
| 292 | const char *prefix, |
| 293 | const char *separator, |
| 294 | const char *suffix) |
Linus Torvalds | ca135e7 | 2007-04-16 16:05:10 -0700 | [diff] [blame] | 295 | { |
Jeff King | 2608c24 | 2014-08-26 06:23:54 -0400 | [diff] [blame] | 296 | const struct name_decoration *decoration; |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 297 | const struct name_decoration *current_and_HEAD; |
Nazri Ramliy | 67a4b58 | 2010-06-19 09:37:35 +0800 | [diff] [blame] | 298 | const char *color_commit = |
Nguyễn Thái Ngọc Duy | 9d3f002 | 2013-04-19 09:08:43 +1000 | [diff] [blame] | 299 | diff_get_color(use_color, DIFF_COMMIT); |
Nazri Ramliy | 67a4b58 | 2010-06-19 09:37:35 +0800 | [diff] [blame] | 300 | const char *color_reset = |
Nguyễn Thái Ngọc Duy | 9d3f002 | 2013-04-19 09:08:43 +1000 | [diff] [blame] | 301 | decorate_get_color(use_color, DECORATION_NONE); |
Linus Torvalds | ca135e7 | 2007-04-16 16:05:10 -0700 | [diff] [blame] | 302 | |
Jeff King | 2608c24 | 2014-08-26 06:23:54 -0400 | [diff] [blame] | 303 | decoration = get_name_decoration(&commit->object); |
Linus Torvalds | ca135e7 | 2007-04-16 16:05:10 -0700 | [diff] [blame] | 304 | if (!decoration) |
| 305 | return; |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 306 | |
| 307 | current_and_HEAD = current_pointed_by_HEAD(decoration); |
Linus Torvalds | ca135e7 | 2007-04-16 16:05:10 -0700 | [diff] [blame] | 308 | while (decoration) { |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 309 | /* |
| 310 | * When both current and HEAD are there, only |
| 311 | * show HEAD->current where HEAD would have |
| 312 | * appeared, skipping the entry for current. |
| 313 | */ |
| 314 | if (decoration != current_and_HEAD) { |
| 315 | strbuf_addstr(sb, color_commit); |
| 316 | strbuf_addstr(sb, prefix); |
| 317 | strbuf_addstr(sb, color_reset); |
| 318 | strbuf_addstr(sb, decorate_get_color(use_color, decoration->type)); |
| 319 | if (decoration->type == DECORATION_REF_TAG) |
| 320 | strbuf_addstr(sb, "tag: "); |
| 321 | |
Junio C Hamano | 429ad20 | 2015-05-13 12:40:35 -0700 | [diff] [blame] | 322 | show_name(sb, decoration); |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 323 | |
| 324 | if (current_and_HEAD && |
| 325 | decoration->type == DECORATION_REF_HEAD) { |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 326 | strbuf_addstr(sb, " -> "); |
| 327 | strbuf_addstr(sb, color_reset); |
| 328 | strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); |
Junio C Hamano | 429ad20 | 2015-05-13 12:40:35 -0700 | [diff] [blame] | 329 | show_name(sb, current_and_HEAD); |
Junio C Hamano | 51ff0f2 | 2015-03-10 14:53:21 +0100 | [diff] [blame] | 330 | } |
| 331 | strbuf_addstr(sb, color_reset); |
| 332 | |
| 333 | prefix = separator; |
| 334 | } |
Linus Torvalds | ca135e7 | 2007-04-16 16:05:10 -0700 | [diff] [blame] | 335 | decoration = decoration->next; |
| 336 | } |
Nguyễn Thái Ngọc Duy | 9d3f002 | 2013-04-19 09:08:43 +1000 | [diff] [blame] | 337 | strbuf_addstr(sb, color_commit); |
Harry Jeffery | 9271095 | 2014-09-18 21:53:53 +0100 | [diff] [blame] | 338 | strbuf_addstr(sb, suffix); |
Nguyễn Thái Ngọc Duy | 9d3f002 | 2013-04-19 09:08:43 +1000 | [diff] [blame] | 339 | strbuf_addstr(sb, color_reset); |
| 340 | } |
| 341 | |
| 342 | void show_decorations(struct rev_info *opt, struct commit *commit) |
| 343 | { |
| 344 | struct strbuf sb = STRBUF_INIT; |
| 345 | |
Nguyễn Thái Ngọc Duy | 87be252 | 2018-05-19 07:28:24 +0200 | [diff] [blame] | 346 | if (opt->sources) { |
| 347 | char **slot = revision_sources_peek(opt->sources, commit); |
| 348 | |
| 349 | if (slot && *slot) |
| 350 | fprintf(opt->diffopt.file, "\t%s", *slot); |
| 351 | } |
Nguyễn Thái Ngọc Duy | 9d3f002 | 2013-04-19 09:08:43 +1000 | [diff] [blame] | 352 | if (!opt->show_decorations) |
| 353 | return; |
| 354 | format_decorations(&sb, commit, opt->diffopt.use_color); |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 355 | fputs(sb.buf, opt->diffopt.file); |
Nguyễn Thái Ngọc Duy | 9d3f002 | 2013-04-19 09:08:43 +1000 | [diff] [blame] | 356 | strbuf_release(&sb); |
Linus Torvalds | ca135e7 | 2007-04-16 16:05:10 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Johannes Schindelin | e00de24 | 2007-02-09 01:43:54 +0100 | [diff] [blame] | 359 | static unsigned int digits_in_number(unsigned int number) |
| 360 | { |
| 361 | unsigned int i = 10, result = 1; |
| 362 | while (i <= number) { |
| 363 | i *= 10; |
| 364 | result++; |
| 365 | } |
| 366 | return result; |
| 367 | } |
| 368 | |
Junio C Hamano | d28b5d4 | 2012-12-21 22:06:01 -0800 | [diff] [blame] | 369 | void fmt_output_subject(struct strbuf *filename, |
| 370 | const char *subject, |
Junio C Hamano | 021f2f4 | 2012-12-21 23:26:16 -0800 | [diff] [blame] | 371 | struct rev_info *info) |
Stephen Boyd | 6fa8e62 | 2009-03-22 19:14:04 -0700 | [diff] [blame] | 372 | { |
Junio C Hamano | 021f2f4 | 2012-12-21 23:26:16 -0800 | [diff] [blame] | 373 | const char *suffix = info->patch_suffix; |
| 374 | int nr = info->nr; |
Junio C Hamano | d28b5d4 | 2012-12-21 22:06:01 -0800 | [diff] [blame] | 375 | int start_len = filename->len; |
Junio C Hamano | 3baf58b | 2020-11-06 13:56:24 -0800 | [diff] [blame] | 376 | int max_len = start_len + info->patch_name_max - (strlen(suffix) + 1); |
Stephen Boyd | 6fa8e62 | 2009-03-22 19:14:04 -0700 | [diff] [blame] | 377 | |
ZheNing Hu | db91988 | 2021-03-23 11:12:25 +0000 | [diff] [blame] | 378 | if (info->reroll_count) { |
| 379 | struct strbuf temp = STRBUF_INIT; |
| 380 | |
| 381 | strbuf_addf(&temp, "v%s", info->reroll_count); |
| 382 | format_sanitized_subject(filename, temp.buf, temp.len); |
| 383 | strbuf_addstr(filename, "-"); |
| 384 | strbuf_release(&temp); |
| 385 | } |
Junio C Hamano | d28b5d4 | 2012-12-21 22:06:01 -0800 | [diff] [blame] | 386 | strbuf_addf(filename, "%04d-%s", nr, subject); |
Christian Couder | b09b868 | 2009-03-27 01:13:01 +0100 | [diff] [blame] | 387 | |
Junio C Hamano | d28b5d4 | 2012-12-21 22:06:01 -0800 | [diff] [blame] | 388 | if (max_len < filename->len) |
| 389 | strbuf_setlen(filename, max_len); |
| 390 | strbuf_addstr(filename, suffix); |
| 391 | } |
Jeff King | a21c2f9 | 2012-05-21 19:10:32 -0400 | [diff] [blame] | 392 | |
Junio C Hamano | d28b5d4 | 2012-12-21 22:06:01 -0800 | [diff] [blame] | 393 | void fmt_output_commit(struct strbuf *filename, |
| 394 | struct commit *commit, |
| 395 | struct rev_info *info) |
| 396 | { |
| 397 | struct pretty_print_context ctx = {0}; |
| 398 | struct strbuf subject = STRBUF_INIT; |
| 399 | |
| 400 | format_commit_message(commit, "%f", &subject, &ctx); |
| 401 | fmt_output_subject(filename, subject.buf, info); |
| 402 | strbuf_release(&subject); |
Stephen Boyd | 6fa8e62 | 2009-03-22 19:14:04 -0700 | [diff] [blame] | 403 | } |
| 404 | |
René Scharfe | 8ffc8dc | 2017-03-01 12:36:38 +0100 | [diff] [blame] | 405 | void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt) |
| 406 | { |
| 407 | if (opt->total > 0) { |
| 408 | strbuf_addf(sb, "Subject: [%s%s%0*d/%d] ", |
| 409 | opt->subject_prefix, |
| 410 | *opt->subject_prefix ? " " : "", |
| 411 | digits_in_number(opt->total), |
| 412 | opt->nr, opt->total); |
| 413 | } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) { |
| 414 | strbuf_addf(sb, "Subject: [%s] ", |
| 415 | opt->subject_prefix); |
| 416 | } else { |
| 417 | strbuf_addstr(sb, "Subject: "); |
| 418 | } |
| 419 | } |
| 420 | |
Stephen Boyd | 108dab2 | 2009-03-22 19:14:05 -0700 | [diff] [blame] | 421 | void log_write_email_headers(struct rev_info *opt, struct commit *commit, |
Junio C Hamano | 267123b | 2008-03-15 00:09:20 -0700 | [diff] [blame] | 422 | const char **extra_headers_p, |
brian m. carlson | 50cd54e | 2018-05-02 02:20:52 +0000 | [diff] [blame] | 423 | int *need_8bit_cte_p, |
| 424 | int maybe_multipart) |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 425 | { |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 426 | const char *extra_headers = opt->extra_headers; |
brian m. carlson | 3a30aa1 | 2015-12-15 01:52:04 +0000 | [diff] [blame] | 427 | const char *name = oid_to_hex(opt->zero_commit ? |
brian m. carlson | 1422844 | 2021-04-26 01:02:56 +0000 | [diff] [blame] | 428 | null_oid() : &commit->object.oid); |
Junio C Hamano | 267123b | 2008-03-15 00:09:20 -0700 | [diff] [blame] | 429 | |
| 430 | *need_8bit_cte_p = 0; /* unknown */ |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 431 | |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 432 | fprintf(opt->diffopt.file, "From %s Mon Sep 17 00:00:00 2001\n", name); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 433 | graph_show_oneline(opt->graph); |
| 434 | if (opt->message_id) { |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 435 | fprintf(opt->diffopt.file, "Message-Id: <%s>\n", opt->message_id); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 436 | graph_show_oneline(opt->graph); |
| 437 | } |
Thomas Rast | b079c50 | 2009-02-19 22:26:31 +0100 | [diff] [blame] | 438 | if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) { |
| 439 | int i, n; |
| 440 | n = opt->ref_message_ids->nr; |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 441 | fprintf(opt->diffopt.file, "In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string); |
Thomas Rast | b079c50 | 2009-02-19 22:26:31 +0100 | [diff] [blame] | 442 | for (i = 0; i < n; i++) |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 443 | fprintf(opt->diffopt.file, "%s<%s>\n", (i > 0 ? "\t" : "References: "), |
Thomas Rast | b079c50 | 2009-02-19 22:26:31 +0100 | [diff] [blame] | 444 | opt->ref_message_ids->items[i].string); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 445 | graph_show_oneline(opt->graph); |
| 446 | } |
brian m. carlson | 50cd54e | 2018-05-02 02:20:52 +0000 | [diff] [blame] | 447 | if (opt->mime_boundary && maybe_multipart) { |
Jeff King | d50b69b | 2018-05-18 18:57:44 -0700 | [diff] [blame] | 448 | static struct strbuf subject_buffer = STRBUF_INIT; |
| 449 | static struct strbuf buffer = STRBUF_INIT; |
Stephen Boyd | 108dab2 | 2009-03-22 19:14:05 -0700 | [diff] [blame] | 450 | struct strbuf filename = STRBUF_INIT; |
Junio C Hamano | 267123b | 2008-03-15 00:09:20 -0700 | [diff] [blame] | 451 | *need_8bit_cte_p = -1; /* NEVER */ |
Jeff King | d50b69b | 2018-05-18 18:57:44 -0700 | [diff] [blame] | 452 | |
| 453 | strbuf_reset(&subject_buffer); |
| 454 | strbuf_reset(&buffer); |
| 455 | |
| 456 | strbuf_addf(&subject_buffer, |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 457 | "%s" |
| 458 | "MIME-Version: 1.0\n" |
| 459 | "Content-Type: multipart/mixed;" |
| 460 | " boundary=\"%s%s\"\n" |
| 461 | "\n" |
| 462 | "This is a multi-part message in MIME " |
| 463 | "format.\n" |
| 464 | "--%s%s\n" |
| 465 | "Content-Type: text/plain; " |
| 466 | "charset=UTF-8; format=fixed\n" |
| 467 | "Content-Transfer-Encoding: 8bit\n\n", |
| 468 | extra_headers ? extra_headers : "", |
| 469 | mime_boundary_leader, opt->mime_boundary, |
| 470 | mime_boundary_leader, opt->mime_boundary); |
Jeff King | d50b69b | 2018-05-18 18:57:44 -0700 | [diff] [blame] | 471 | extra_headers = subject_buffer.buf; |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 472 | |
Junio C Hamano | 38ec23a | 2012-12-21 21:39:37 -0800 | [diff] [blame] | 473 | if (opt->numbered_files) |
| 474 | strbuf_addf(&filename, "%d", opt->nr); |
| 475 | else |
Junio C Hamano | d28b5d4 | 2012-12-21 22:06:01 -0800 | [diff] [blame] | 476 | fmt_output_commit(&filename, commit, opt); |
Jeff King | d50b69b | 2018-05-18 18:57:44 -0700 | [diff] [blame] | 477 | strbuf_addf(&buffer, |
Kevin Ballard | 6b2fbaa | 2008-07-29 22:49:33 -0700 | [diff] [blame] | 478 | "\n--%s%s\n" |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 479 | "Content-Type: text/x-patch;" |
Stephen Boyd | 108dab2 | 2009-03-22 19:14:05 -0700 | [diff] [blame] | 480 | " name=\"%s\"\n" |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 481 | "Content-Transfer-Encoding: 8bit\n" |
| 482 | "Content-Disposition: %s;" |
Stephen Boyd | 108dab2 | 2009-03-22 19:14:05 -0700 | [diff] [blame] | 483 | " filename=\"%s\"\n\n", |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 484 | mime_boundary_leader, opt->mime_boundary, |
Stephen Boyd | 108dab2 | 2009-03-22 19:14:05 -0700 | [diff] [blame] | 485 | filename.buf, |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 486 | opt->no_inline ? "attachment" : "inline", |
Stephen Boyd | 108dab2 | 2009-03-22 19:14:05 -0700 | [diff] [blame] | 487 | filename.buf); |
Jeff King | d50b69b | 2018-05-18 18:57:44 -0700 | [diff] [blame] | 488 | opt->diffopt.stat_sep = buffer.buf; |
Stephen Boyd | 108dab2 | 2009-03-22 19:14:05 -0700 | [diff] [blame] | 489 | strbuf_release(&filename); |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 490 | } |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 491 | *extra_headers_p = extra_headers; |
| 492 | } |
| 493 | |
Junio C Hamano | c6b3ec4 | 2012-01-04 13:48:45 -0800 | [diff] [blame] | 494 | static void show_sig_lines(struct rev_info *opt, int status, const char *bol) |
| 495 | { |
| 496 | const char *color, *reset, *eol; |
| 497 | |
| 498 | color = diff_get_color_opt(&opt->diffopt, |
| 499 | status ? DIFF_WHITESPACE : DIFF_FRAGINFO); |
| 500 | reset = diff_get_color_opt(&opt->diffopt, DIFF_RESET); |
| 501 | while (*bol) { |
| 502 | eol = strchrnul(bol, '\n'); |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 503 | fprintf(opt->diffopt.file, "%s%.*s%s%s", color, (int)(eol - bol), bol, reset, |
Junio C Hamano | c6b3ec4 | 2012-01-04 13:48:45 -0800 | [diff] [blame] | 504 | *eol ? "\n" : ""); |
Zoltan Klinger | cf3983d | 2014-07-09 12:10:21 +1000 | [diff] [blame] | 505 | graph_show_oneline(opt->graph); |
Junio C Hamano | c6b3ec4 | 2012-01-04 13:48:45 -0800 | [diff] [blame] | 506 | bol = (*eol) ? (eol + 1) : eol; |
| 507 | } |
| 508 | } |
| 509 | |
Junio C Hamano | 0c37f1f | 2011-10-18 15:53:23 -0700 | [diff] [blame] | 510 | static void show_signature(struct rev_info *opt, struct commit *commit) |
| 511 | { |
| 512 | struct strbuf payload = STRBUF_INIT; |
| 513 | struct strbuf signature = STRBUF_INIT; |
Hans Jerry Illikainen | 6794898 | 2020-03-04 11:48:04 +0000 | [diff] [blame] | 514 | struct signature_check sigc = { 0 }; |
Junio C Hamano | 0c37f1f | 2011-10-18 15:53:23 -0700 | [diff] [blame] | 515 | int status; |
Junio C Hamano | 0c37f1f | 2011-10-18 15:53:23 -0700 | [diff] [blame] | 516 | |
brian m. carlson | 1fb5cf0 | 2021-01-18 23:49:11 +0000 | [diff] [blame] | 517 | if (parse_signed_commit(commit, &payload, &signature, the_hash_algo) <= 0) |
Junio C Hamano | 0c37f1f | 2011-10-18 15:53:23 -0700 | [diff] [blame] | 518 | goto out; |
| 519 | |
Fabian Stelzer | 4bbf378 | 2021-12-09 09:52:46 +0100 | [diff] [blame] | 520 | sigc.payload_type = SIGNATURE_PAYLOAD_COMMIT; |
Fabian Stelzer | 0276943 | 2021-12-09 09:52:43 +0100 | [diff] [blame] | 521 | sigc.payload = strbuf_detach(&payload, &sigc.payload_len); |
| 522 | status = check_signature(&sigc, signature.buf, signature.len); |
Fabian Stelzer | b5726a5 | 2021-09-10 20:07:34 +0000 | [diff] [blame] | 523 | if (status && !sigc.output) |
Hans Jerry Illikainen | 6794898 | 2020-03-04 11:48:04 +0000 | [diff] [blame] | 524 | show_sig_lines(opt, status, "No signature\n"); |
| 525 | else |
Fabian Stelzer | b5726a5 | 2021-09-10 20:07:34 +0000 | [diff] [blame] | 526 | show_sig_lines(opt, status, sigc.output); |
Hans Jerry Illikainen | 6794898 | 2020-03-04 11:48:04 +0000 | [diff] [blame] | 527 | signature_check_clear(&sigc); |
Junio C Hamano | 0c37f1f | 2011-10-18 15:53:23 -0700 | [diff] [blame] | 528 | |
| 529 | out: |
Junio C Hamano | 0c37f1f | 2011-10-18 15:53:23 -0700 | [diff] [blame] | 530 | strbuf_release(&payload); |
| 531 | strbuf_release(&signature); |
| 532 | } |
| 533 | |
brian m. carlson | a92ea68 | 2017-05-06 22:10:18 +0000 | [diff] [blame] | 534 | static int which_parent(const struct object_id *oid, const struct commit *commit) |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 535 | { |
| 536 | int nth; |
| 537 | const struct commit_list *parent; |
| 538 | |
| 539 | for (nth = 0, parent = commit->parents; parent; parent = parent->next) { |
Jeff King | 4a7e27e | 2018-08-28 17:22:40 -0400 | [diff] [blame] | 540 | if (oideq(&parent->item->object.oid, oid)) |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 541 | return nth; |
| 542 | nth++; |
| 543 | } |
| 544 | return -1; |
| 545 | } |
| 546 | |
Junio C Hamano | d041ffa | 2012-01-04 16:23:12 -0800 | [diff] [blame] | 547 | static int is_common_merge(const struct commit *commit) |
| 548 | { |
| 549 | return (commit->parents |
| 550 | && commit->parents->next |
| 551 | && !commit->parents->next->next); |
| 552 | } |
| 553 | |
Johannes Schindelin | fef461e | 2018-04-25 11:54:04 +0200 | [diff] [blame] | 554 | static int show_one_mergetag(struct commit *commit, |
| 555 | struct commit_extra_header *extra, |
| 556 | void *data) |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 557 | { |
Christian Couder | 063da62 | 2014-07-07 08:35:37 +0200 | [diff] [blame] | 558 | struct rev_info *opt = (struct rev_info *)data; |
brian m. carlson | a92ea68 | 2017-05-06 22:10:18 +0000 | [diff] [blame] | 559 | struct object_id oid; |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 560 | struct tag *tag; |
| 561 | struct strbuf verify_message; |
Hans Jerry Illikainen | 6794898 | 2020-03-04 11:48:04 +0000 | [diff] [blame] | 562 | struct signature_check sigc = { 0 }; |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 563 | int status, nth; |
brian m. carlson | 482c119 | 2021-02-11 02:08:03 +0000 | [diff] [blame] | 564 | struct strbuf payload = STRBUF_INIT; |
| 565 | struct strbuf signature = STRBUF_INIT; |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 566 | |
Matheus Tavares | 2dcde20 | 2020-01-30 17:32:22 -0300 | [diff] [blame] | 567 | hash_object_file(the_hash_algo, extra->value, extra->len, |
| 568 | type_name(OBJ_TAG), &oid); |
Stefan Beller | ce71efb | 2018-06-28 18:22:03 -0700 | [diff] [blame] | 569 | tag = lookup_tag(the_repository, &oid); |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 570 | if (!tag) |
Johannes Schindelin | fef461e | 2018-04-25 11:54:04 +0200 | [diff] [blame] | 571 | return -1; /* error message already given */ |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 572 | |
| 573 | strbuf_init(&verify_message, 256); |
Stefan Beller | 0e740fe | 2018-06-28 18:22:04 -0700 | [diff] [blame] | 574 | if (parse_tag_buffer(the_repository, tag, extra->value, extra->len)) |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 575 | strbuf_addstr(&verify_message, "malformed mergetag\n"); |
Junio C Hamano | d041ffa | 2012-01-04 16:23:12 -0800 | [diff] [blame] | 576 | else if (is_common_merge(commit) && |
Jeff King | 4a7e27e | 2018-08-28 17:22:40 -0400 | [diff] [blame] | 577 | oideq(&tag->tagged->oid, |
| 578 | &commit->parents->next->item->object.oid)) |
Junio C Hamano | d041ffa | 2012-01-04 16:23:12 -0800 | [diff] [blame] | 579 | strbuf_addf(&verify_message, |
| 580 | "merged tag '%s'\n", tag->tag); |
brian m. carlson | a92ea68 | 2017-05-06 22:10:18 +0000 | [diff] [blame] | 581 | else if ((nth = which_parent(&tag->tagged->oid, commit)) < 0) |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 582 | strbuf_addf(&verify_message, "tag %s names a non-parent %s\n", |
Harald van Dijk | 237a281 | 2020-02-29 13:07:57 +0000 | [diff] [blame] | 583 | tag->tag, oid_to_hex(&tag->tagged->oid)); |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 584 | else |
| 585 | strbuf_addf(&verify_message, |
| 586 | "parent #%d, tagged '%s'\n", nth + 1, tag->tag); |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 587 | |
Michael J Gruber | 1315093 | 2013-02-14 17:04:43 +0100 | [diff] [blame] | 588 | status = -1; |
brian m. carlson | 482c119 | 2021-02-11 02:08:03 +0000 | [diff] [blame] | 589 | if (parse_signature(extra->value, extra->len, &payload, &signature)) { |
Michael J Gruber | 42c55ce | 2014-06-27 15:18:36 +0200 | [diff] [blame] | 590 | /* could have a good signature */ |
Fabian Stelzer | 4bbf378 | 2021-12-09 09:52:46 +0100 | [diff] [blame] | 591 | sigc.payload_type = SIGNATURE_PAYLOAD_TAG; |
Fabian Stelzer | 0276943 | 2021-12-09 09:52:43 +0100 | [diff] [blame] | 592 | sigc.payload = strbuf_detach(&payload, &sigc.payload_len); |
| 593 | status = check_signature(&sigc, signature.buf, signature.len); |
Fabian Stelzer | b5726a5 | 2021-09-10 20:07:34 +0000 | [diff] [blame] | 594 | if (sigc.output) |
| 595 | strbuf_addstr(&verify_message, sigc.output); |
Hans Jerry Illikainen | 6794898 | 2020-03-04 11:48:04 +0000 | [diff] [blame] | 596 | else |
Michael J Gruber | 42c55ce | 2014-06-27 15:18:36 +0200 | [diff] [blame] | 597 | strbuf_addstr(&verify_message, "No signature\n"); |
Hans Jerry Illikainen | 6794898 | 2020-03-04 11:48:04 +0000 | [diff] [blame] | 598 | signature_check_clear(&sigc); |
Michael J Gruber | 42c55ce | 2014-06-27 15:18:36 +0200 | [diff] [blame] | 599 | /* otherwise we couldn't verify, which is shown as bad */ |
| 600 | } |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 601 | |
| 602 | show_sig_lines(opt, status, verify_message.buf); |
| 603 | strbuf_release(&verify_message); |
brian m. carlson | 482c119 | 2021-02-11 02:08:03 +0000 | [diff] [blame] | 604 | strbuf_release(&payload); |
| 605 | strbuf_release(&signature); |
Johannes Schindelin | fef461e | 2018-04-25 11:54:04 +0200 | [diff] [blame] | 606 | return 0; |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 607 | } |
| 608 | |
Johannes Schindelin | fef461e | 2018-04-25 11:54:04 +0200 | [diff] [blame] | 609 | static int show_mergetag(struct rev_info *opt, struct commit *commit) |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 610 | { |
Johannes Schindelin | fef461e | 2018-04-25 11:54:04 +0200 | [diff] [blame] | 611 | return for_each_mergetag(show_one_mergetag, commit, opt); |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Eric Sunshine | 3fcc7a2 | 2018-07-22 05:57:08 -0400 | [diff] [blame] | 614 | static void next_commentary_block(struct rev_info *opt, struct strbuf *sb) |
| 615 | { |
| 616 | const char *x = opt->shown_dashes ? "\n" : "---\n"; |
| 617 | if (sb) |
| 618 | strbuf_addstr(sb, x); |
| 619 | else |
| 620 | fputs(x, opt->diffopt.file); |
| 621 | opt->shown_dashes = 1; |
| 622 | } |
| 623 | |
Adam Simpkins | 0286565 | 2008-04-29 01:32:59 -0700 | [diff] [blame] | 624 | void show_log(struct rev_info *opt) |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 625 | { |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 626 | struct strbuf msgbuf = STRBUF_INIT; |
Timo Hirvonen | 39bc9a6 | 2006-06-25 13:54:14 +0300 | [diff] [blame] | 627 | struct log_info *log = opt->loginfo; |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 628 | struct commit *commit = log->commit, *parent = log->parent; |
brian m. carlson | 2ed1960 | 2018-07-16 01:28:06 +0000 | [diff] [blame] | 629 | int abbrev_commit = opt->abbrev_commit ? opt->abbrev : the_hash_algo->hexsz; |
Thomas Rast | dd2e794 | 2009-10-19 17:48:08 +0200 | [diff] [blame] | 630 | const char *extra_headers = opt->extra_headers; |
| 631 | struct pretty_print_context ctx = {0}; |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 632 | |
| 633 | opt->loginfo = NULL; |
| 634 | if (!opt->verbose_header) { |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 635 | graph_show_commit(opt->graph); |
| 636 | |
Michael J Gruber | 1df2d65 | 2011-03-07 13:31:39 +0100 | [diff] [blame] | 637 | if (!opt->graph) |
Michael J Gruber | b1b4755 | 2011-03-10 15:45:03 +0100 | [diff] [blame] | 638 | put_revision_mark(opt, commit); |
brian m. carlson | aab9583 | 2018-03-12 02:27:30 +0000 | [diff] [blame] | 639 | fputs(find_unique_abbrev(&commit->object.oid, abbrev_commit), opt->diffopt.file); |
Adam Simpkins | 885cf80 | 2008-05-04 03:36:52 -0700 | [diff] [blame] | 640 | if (opt->print_parents) |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 641 | show_parents(commit, abbrev_commit, opt->diffopt.file); |
Jay Soffian | 91b849b | 2011-10-04 10:02:03 -0400 | [diff] [blame] | 642 | if (opt->children.name) |
| 643 | show_children(opt, commit, abbrev_commit); |
Linus Torvalds | 0f3a290 | 2008-10-27 12:51:59 -0700 | [diff] [blame] | 644 | show_decorations(opt, commit); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 645 | if (opt->graph && !graph_is_commit_finished(opt->graph)) { |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 646 | putc('\n', opt->diffopt.file); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 647 | graph_show_remainder(opt->graph); |
| 648 | } |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 649 | putc(opt->diffopt.line_termination, opt->diffopt.file); |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 650 | return; |
| 651 | } |
| 652 | |
| 653 | /* |
Jeff King | 8715227 | 2009-07-01 03:26:28 -0400 | [diff] [blame] | 654 | * If use_terminator is set, we already handled any record termination |
| 655 | * at the end of the last record. |
Adam Simpkins | 0286565 | 2008-04-29 01:32:59 -0700 | [diff] [blame] | 656 | * Otherwise, add a diffopt.line_termination character before all |
| 657 | * entries but the first. (IOW, as a separator between entries) |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 658 | */ |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 659 | if (opt->shown_one && !opt->use_terminator) { |
| 660 | /* |
| 661 | * If entries are separated by a newline, the output |
| 662 | * should look human-readable. If the last entry ended |
| 663 | * with a newline, print the graph output before this |
| 664 | * newline. Otherwise it will end up as a completely blank |
| 665 | * line and will look like a gap in the graph. |
| 666 | * |
| 667 | * If the entry separator is not a newline, the output is |
| 668 | * primarily intended for programmatic consumption, and we |
| 669 | * never want the extra graph output before the entry |
| 670 | * separator. |
| 671 | */ |
| 672 | if (opt->diffopt.line_termination == '\n' && |
| 673 | !opt->missing_newline) |
| 674 | graph_show_padding(opt->graph); |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 675 | putc(opt->diffopt.line_termination, opt->diffopt.file); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 676 | } |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 677 | opt->shown_one = 1; |
| 678 | |
| 679 | /* |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 680 | * If the history graph was requested, |
| 681 | * print the graph, up to this commit's line |
| 682 | */ |
| 683 | graph_show_commit(opt->graph); |
| 684 | |
| 685 | /* |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 686 | * Print header line of header.. |
| 687 | */ |
Junio C Hamano | 3eefc18 | 2006-04-18 16:45:27 -0700 | [diff] [blame] | 688 | |
Eric Wong | 9f23e04 | 2016-06-05 04:46:39 +0000 | [diff] [blame] | 689 | if (cmit_fmt_is_mail(opt->commit_format)) { |
René Scharfe | 6d167fd | 2017-03-01 12:37:07 +0100 | [diff] [blame] | 690 | log_write_email_headers(opt, commit, &extra_headers, |
brian m. carlson | 50cd54e | 2018-05-02 02:20:52 +0000 | [diff] [blame] | 691 | &ctx.need_8bit_cte, 1); |
René Scharfe | 6d167fd | 2017-03-01 12:37:07 +0100 | [diff] [blame] | 692 | ctx.rev = opt; |
| 693 | ctx.print_email_subject = 1; |
Johannes Schindelin | e52a5de | 2007-02-23 01:35:03 +0100 | [diff] [blame] | 694 | } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 695 | fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), opt->diffopt.file); |
Junio C Hamano | 74bd902 | 2006-12-16 15:31:25 -0800 | [diff] [blame] | 696 | if (opt->commit_format != CMIT_FMT_ONELINE) |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 697 | fputs("commit ", opt->diffopt.file); |
Adam Simpkins | 7528f27 | 2008-05-25 00:07:21 -0700 | [diff] [blame] | 698 | |
Michael J Gruber | 1df2d65 | 2011-03-07 13:31:39 +0100 | [diff] [blame] | 699 | if (!opt->graph) |
Michael J Gruber | b1b4755 | 2011-03-10 15:45:03 +0100 | [diff] [blame] | 700 | put_revision_mark(opt, commit); |
brian m. carlson | aab9583 | 2018-03-12 02:27:30 +0000 | [diff] [blame] | 701 | fputs(find_unique_abbrev(&commit->object.oid, |
| 702 | abbrev_commit), |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 703 | opt->diffopt.file); |
Adam Simpkins | 885cf80 | 2008-05-04 03:36:52 -0700 | [diff] [blame] | 704 | if (opt->print_parents) |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 705 | show_parents(commit, abbrev_commit, opt->diffopt.file); |
Jay Soffian | 91b849b | 2011-10-04 10:02:03 -0400 | [diff] [blame] | 706 | if (opt->children.name) |
| 707 | show_children(opt, commit, abbrev_commit); |
Junio C Hamano | 73f0a15 | 2006-05-24 12:19:47 -0700 | [diff] [blame] | 708 | if (parent) |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 709 | fprintf(opt->diffopt.file, " (from %s)", |
brian m. carlson | aab9583 | 2018-03-12 02:27:30 +0000 | [diff] [blame] | 710 | find_unique_abbrev(&parent->object.oid, abbrev_commit)); |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 711 | fputs(diff_get_color_opt(&opt->diffopt, DIFF_RESET), opt->diffopt.file); |
Linus Torvalds | 0f3a290 | 2008-10-27 12:51:59 -0700 | [diff] [blame] | 712 | show_decorations(opt, commit); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 713 | if (opt->commit_format == CMIT_FMT_ONELINE) { |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 714 | putc(' ', opt->diffopt.file); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 715 | } else { |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 716 | putc('\n', opt->diffopt.file); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 717 | graph_show_oneline(opt->graph); |
| 718 | } |
Nicolas Pitre | 903b45f | 2007-01-27 22:40:36 -0500 | [diff] [blame] | 719 | if (opt->reflog_info) { |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 720 | /* |
| 721 | * setup_revisions() ensures that opt->reflog_info |
| 722 | * and opt->graph cannot both be set, |
| 723 | * so we don't need to worry about printing the |
| 724 | * graph info here. |
| 725 | */ |
Junio C Hamano | 4d12a47 | 2007-01-20 00:51:41 -0800 | [diff] [blame] | 726 | show_reflog_message(opt->reflog_info, |
Junio C Hamano | 55ccf85 | 2012-05-07 14:11:32 -0700 | [diff] [blame] | 727 | opt->commit_format == CMIT_FMT_ONELINE, |
Jeff King | a5481a6 | 2015-06-25 12:55:02 -0400 | [diff] [blame] | 728 | &opt->date_mode, |
Junio C Hamano | 55ccf85 | 2012-05-07 14:11:32 -0700 | [diff] [blame] | 729 | opt->date_mode_explicit); |
Adam Simpkins | 0286565 | 2008-04-29 01:32:59 -0700 | [diff] [blame] | 730 | if (opt->commit_format == CMIT_FMT_ONELINE) |
Nicolas Pitre | 903b45f | 2007-01-27 22:40:36 -0500 | [diff] [blame] | 731 | return; |
Nicolas Pitre | 903b45f | 2007-01-27 22:40:36 -0500 | [diff] [blame] | 732 | } |
Junio C Hamano | 3eefc18 | 2006-04-18 16:45:27 -0700 | [diff] [blame] | 733 | } |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 734 | |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 735 | if (opt->show_signature) { |
Junio C Hamano | 0c37f1f | 2011-10-18 15:53:23 -0700 | [diff] [blame] | 736 | show_signature(opt, commit); |
Junio C Hamano | 824958e | 2012-01-04 13:51:28 -0800 | [diff] [blame] | 737 | show_mergetag(opt, commit); |
| 738 | } |
Junio C Hamano | 0c37f1f | 2011-10-18 15:53:23 -0700 | [diff] [blame] | 739 | |
Junio C Hamano | ddf333f | 2012-10-17 18:51:47 -0700 | [diff] [blame] | 740 | if (opt->show_notes) { |
| 741 | int raw; |
| 742 | struct strbuf notebuf = STRBUF_INIT; |
| 743 | |
| 744 | raw = (opt->commit_format == CMIT_FMT_USERFORMAT); |
brian m. carlson | fb61e4d | 2017-05-30 10:30:41 -0700 | [diff] [blame] | 745 | format_display_notes(&commit->object.oid, ¬ebuf, |
Junio C Hamano | ddf333f | 2012-10-17 18:51:47 -0700 | [diff] [blame] | 746 | get_log_output_encoding(), raw); |
René Scharfe | 82f51af | 2019-08-25 14:53:26 +0200 | [diff] [blame] | 747 | ctx.notes_message = strbuf_detach(¬ebuf, NULL); |
Junio C Hamano | ddf333f | 2012-10-17 18:51:47 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 750 | /* |
| 751 | * And then the pretty-printed message itself |
| 752 | */ |
Nguyễn Thái Ngọc Duy | 5289c56 | 2013-02-12 02:17:38 -0800 | [diff] [blame] | 753 | if (ctx.need_8bit_cte >= 0 && opt->add_signoff) |
| 754 | ctx.need_8bit_cte = |
William Hubbs | 39ab4d0 | 2019-02-04 12:48:50 -0600 | [diff] [blame] | 755 | has_non_ascii(fmt_name(WANT_COMMITTER_IDENT)); |
Thomas Rast | dd2e794 | 2009-10-19 17:48:08 +0200 | [diff] [blame] | 756 | ctx.date_mode = opt->date_mode; |
Jeff King | f026c75 | 2012-05-04 01:25:18 -0400 | [diff] [blame] | 757 | ctx.date_mode_explicit = opt->date_mode_explicit; |
Thomas Rast | dd2e794 | 2009-10-19 17:48:08 +0200 | [diff] [blame] | 758 | ctx.abbrev = opt->diffopt.abbrev; |
| 759 | ctx.after_subject = extra_headers; |
Jeff King | 9553d2b | 2011-05-26 18:28:17 -0400 | [diff] [blame] | 760 | ctx.preserve_subject = opt->preserve_subject; |
Emma Brooks | 19d097e | 2020-04-08 04:31:38 +0000 | [diff] [blame] | 761 | ctx.encode_email_headers = opt->encode_email_headers; |
Thomas Rast | 8f8f547 | 2009-10-19 17:48:10 +0200 | [diff] [blame] | 762 | ctx.reflog_info = opt->reflog_info; |
Jeff King | 6bf1394 | 2011-05-26 18:27:49 -0400 | [diff] [blame] | 763 | ctx.fmt = opt->commit_format; |
Antoine Pelisse | 0e2913b | 2013-01-05 22:26:41 +0100 | [diff] [blame] | 764 | ctx.mailmap = opt->mailmap; |
Junio C Hamano | 3082517 | 2012-12-17 17:56:49 -0500 | [diff] [blame] | 765 | ctx.color = opt->diffopt.use_color; |
Linus Torvalds | 7cc13c7 | 2016-03-16 09:15:53 -0700 | [diff] [blame] | 766 | ctx.expand_tabs_in_log = opt->expand_tabs_in_log; |
Alexey Shumkin | ecaee80 | 2013-06-26 14:19:50 +0400 | [diff] [blame] | 767 | ctx.output_encoding = get_log_output_encoding(); |
Issac Trotts | ad6f028 | 2019-01-10 22:30:46 -0800 | [diff] [blame] | 768 | ctx.rev = opt; |
Jeff King | a908047 | 2013-07-03 03:08:22 -0400 | [diff] [blame] | 769 | if (opt->from_ident.mail_begin && opt->from_ident.name_begin) |
| 770 | ctx.from_ident = &opt->from_ident; |
Josef Kufner | 3ad87c8 | 2016-06-16 20:18:37 +0700 | [diff] [blame] | 771 | if (opt->graph) |
| 772 | ctx.graph_width = graph_width(opt->graph); |
Jeff King | 6bf1394 | 2011-05-26 18:27:49 -0400 | [diff] [blame] | 773 | pretty_print_commit(&ctx, commit, &msgbuf); |
Junio C Hamano | 212620f | 2012-10-17 20:48:25 -0700 | [diff] [blame] | 774 | |
| 775 | if (opt->add_signoff) |
Nguyễn Thái Ngọc Duy | 5289c56 | 2013-02-12 02:17:38 -0800 | [diff] [blame] | 776 | append_signoff(&msgbuf, 0, APPEND_SIGNOFF_DEDUP); |
Junio C Hamano | 212620f | 2012-10-17 20:48:25 -0700 | [diff] [blame] | 777 | |
Junio C Hamano | 5a664cf | 2012-10-17 19:02:46 -0700 | [diff] [blame] | 778 | if ((ctx.fmt != CMIT_FMT_USERFORMAT) && |
Junio C Hamano | bd1470b | 2012-10-17 21:27:22 -0700 | [diff] [blame] | 779 | ctx.notes_message && *ctx.notes_message) { |
Eric Sunshine | 3fcc7a2 | 2018-07-22 05:57:08 -0400 | [diff] [blame] | 780 | if (cmit_fmt_is_mail(ctx.fmt)) |
| 781 | next_commentary_block(opt, &msgbuf); |
Junio C Hamano | 5a664cf | 2012-10-17 19:02:46 -0700 | [diff] [blame] | 782 | strbuf_addstr(&msgbuf, ctx.notes_message); |
Junio C Hamano | bd1470b | 2012-10-17 21:27:22 -0700 | [diff] [blame] | 783 | } |
Junio C Hamano | cf2251b | 2006-05-31 15:11:49 -0700 | [diff] [blame] | 784 | |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 785 | if (opt->show_log_size) { |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 786 | fprintf(opt->diffopt.file, "log size %i\n", (int)msgbuf.len); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 787 | graph_show_oneline(opt->graph); |
| 788 | } |
Marco Costalba | 9fa3465 | 2007-07-20 20:15:13 +0200 | [diff] [blame] | 789 | |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 790 | /* |
| 791 | * Set opt->missing_newline if msgbuf doesn't |
| 792 | * end in a newline (including if it is empty) |
| 793 | */ |
| 794 | if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n') |
| 795 | opt->missing_newline = 1; |
| 796 | else |
| 797 | opt->missing_newline = 0; |
| 798 | |
Jacob Keller | 660e113 | 2016-08-31 16:27:20 -0700 | [diff] [blame] | 799 | graph_show_commit_msg(opt->graph, opt->diffopt.file, &msgbuf); |
Jeff King | b9c7d6e | 2014-07-29 13:56:48 -0400 | [diff] [blame] | 800 | if (opt->use_terminator && !commit_format_is_empty(opt->commit_format)) { |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 801 | if (!opt->missing_newline) |
| 802 | graph_show_padding(opt->graph); |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 803 | putc(opt->diffopt.line_termination, opt->diffopt.file); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Pierre Habouzit | 674d172 | 2007-09-10 12:35:06 +0200 | [diff] [blame] | 806 | strbuf_release(&msgbuf); |
Junio C Hamano | ddf333f | 2012-10-17 18:51:47 -0700 | [diff] [blame] | 807 | free(ctx.notes_message); |
Eric Sunshine | ee6cbf7 | 2018-07-22 05:57:09 -0400 | [diff] [blame] | 808 | |
| 809 | if (cmit_fmt_is_mail(ctx.fmt) && opt->idiff_oid1) { |
| 810 | struct diff_queue_struct dq; |
| 811 | |
| 812 | memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff)); |
| 813 | DIFF_QUEUE_CLEAR(&diff_queued_diff); |
| 814 | |
| 815 | next_commentary_block(opt, NULL); |
| 816 | fprintf_ln(opt->diffopt.file, "%s", opt->idiff_title); |
Eric Sunshine | 72a7239 | 2020-09-08 03:16:09 -0400 | [diff] [blame] | 817 | show_interdiff(opt->idiff_oid1, opt->idiff_oid2, 2, |
| 818 | &opt->diffopt); |
Eric Sunshine | ee6cbf7 | 2018-07-22 05:57:09 -0400 | [diff] [blame] | 819 | |
| 820 | memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff)); |
| 821 | } |
Eric Sunshine | 40ce416 | 2018-07-22 05:57:17 -0400 | [diff] [blame] | 822 | |
| 823 | if (cmit_fmt_is_mail(ctx.fmt) && opt->rdiff1) { |
| 824 | struct diff_queue_struct dq; |
Martin Ågren | ac0edf1 | 2018-12-03 16:21:31 -0500 | [diff] [blame] | 825 | struct diff_options opts; |
Johannes Schindelin | f1ce6c1 | 2021-02-05 14:46:11 +0000 | [diff] [blame] | 826 | struct range_diff_options range_diff_opts = { |
| 827 | .creation_factor = opt->creation_factor, |
| 828 | .dual_color = 1, |
| 829 | .diffopt = &opts |
| 830 | }; |
Eric Sunshine | 40ce416 | 2018-07-22 05:57:17 -0400 | [diff] [blame] | 831 | |
| 832 | memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff)); |
| 833 | DIFF_QUEUE_CLEAR(&diff_queued_diff); |
| 834 | |
| 835 | next_commentary_block(opt, NULL); |
| 836 | fprintf_ln(opt->diffopt.file, "%s", opt->rdiff_title); |
Martin Ågren | ac0edf1 | 2018-12-03 16:21:31 -0500 | [diff] [blame] | 837 | /* |
| 838 | * Pass minimum required diff-options to range-diff; others |
| 839 | * can be added later if deemed desirable. |
| 840 | */ |
| 841 | diff_setup(&opts); |
| 842 | opts.file = opt->diffopt.file; |
| 843 | opts.use_color = opt->diffopt.use_color; |
| 844 | diff_setup_done(&opts); |
Johannes Schindelin | f1ce6c1 | 2021-02-05 14:46:11 +0000 | [diff] [blame] | 845 | show_range_diff(opt->rdiff1, opt->rdiff2, &range_diff_opts); |
Eric Sunshine | 40ce416 | 2018-07-22 05:57:17 -0400 | [diff] [blame] | 846 | |
| 847 | memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff)); |
| 848 | } |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 851 | int log_tree_diff_flush(struct rev_info *opt) |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 852 | { |
Junio C Hamano | bd1470b | 2012-10-17 21:27:22 -0700 | [diff] [blame] | 853 | opt->shown_dashes = 0; |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 854 | diffcore_std(&opt->diffopt); |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 855 | |
Elijah Newren | 95433ee | 2022-02-02 02:37:34 +0000 | [diff] [blame] | 856 | if (diff_queue_is_empty(&opt->diffopt)) { |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 857 | int saved_fmt = opt->diffopt.output_format; |
| 858 | opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT; |
| 859 | diff_flush(&opt->diffopt); |
| 860 | opt->diffopt.output_format = saved_fmt; |
| 861 | return 0; |
| 862 | } |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 863 | |
Junio C Hamano | 3969cf7 | 2006-06-27 15:08:19 -0700 | [diff] [blame] | 864 | if (opt->loginfo && !opt->no_commit_id) { |
Adam Simpkins | 0286565 | 2008-04-29 01:32:59 -0700 | [diff] [blame] | 865 | show_log(opt); |
Linus Torvalds | 304b5af | 2007-10-09 09:35:22 -0700 | [diff] [blame] | 866 | if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) && |
| 867 | opt->verbose_header && |
Jeff King | b9c7d6e | 2014-07-29 13:56:48 -0400 | [diff] [blame] | 868 | opt->commit_format != CMIT_FMT_ONELINE && |
| 869 | !commit_format_is_empty(opt->commit_format)) { |
Junio C Hamano | 1d34c50 | 2012-11-13 10:09:07 -0800 | [diff] [blame] | 870 | /* |
| 871 | * When showing a verbose header (i.e. log message), |
| 872 | * and not in --pretty=oneline format, we would want |
| 873 | * an extra newline between the end of log and the |
| 874 | * diff/diffstat output for readability. |
| 875 | */ |
Junio C Hamano | 3969cf7 | 2006-06-27 15:08:19 -0700 | [diff] [blame] | 876 | int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH; |
Bo Yang | 81bd1b2 | 2010-05-26 15:08:03 +0800 | [diff] [blame] | 877 | if (opt->diffopt.output_prefix) { |
| 878 | struct strbuf *msg = NULL; |
| 879 | msg = opt->diffopt.output_prefix(&opt->diffopt, |
| 880 | opt->diffopt.output_prefix_data); |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 881 | fwrite(msg->buf, msg->len, 1, opt->diffopt.file); |
Bo Yang | 81bd1b2 | 2010-05-26 15:08:03 +0800 | [diff] [blame] | 882 | } |
Junio C Hamano | 1d34c50 | 2012-11-13 10:09:07 -0800 | [diff] [blame] | 883 | |
| 884 | /* |
| 885 | * We may have shown three-dashes line early |
Eric Sunshine | 3fcc7a2 | 2018-07-22 05:57:08 -0400 | [diff] [blame] | 886 | * between generated commentary (notes, etc.) |
| 887 | * and the log message, in which case we only |
| 888 | * want a blank line after the commentary |
| 889 | * without (an extra) three-dashes line. |
Junio C Hamano | 1d34c50 | 2012-11-13 10:09:07 -0800 | [diff] [blame] | 890 | * Otherwise, we show the three-dashes line if |
| 891 | * we are showing the patch with diffstat, but |
| 892 | * in that case, there is no extra blank line |
| 893 | * after the three-dashes line. |
| 894 | */ |
| 895 | if (!opt->shown_dashes && |
| 896 | (pch & opt->diffopt.output_format) == pch) |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 897 | fprintf(opt->diffopt.file, "---"); |
| 898 | putc('\n', opt->diffopt.file); |
Junio C Hamano | 3969cf7 | 2006-06-27 15:08:19 -0700 | [diff] [blame] | 899 | } |
| 900 | } |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 901 | diff_flush(&opt->diffopt); |
| 902 | return 1; |
| 903 | } |
| 904 | |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 905 | static int do_diff_combined(struct rev_info *opt, struct commit *commit) |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 906 | { |
Sergey Organov | d01141d | 2020-09-29 14:31:22 +0300 | [diff] [blame] | 907 | diff_tree_combined_merge(commit, opt); |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 908 | return !opt->loginfo; |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Elijah Newren | 20323d1 | 2022-02-02 02:37:35 +0000 | [diff] [blame] | 911 | static void setup_additional_headers(struct diff_options *o, |
| 912 | struct strmap *all_headers) |
| 913 | { |
| 914 | struct hashmap_iter iter; |
| 915 | struct strmap_entry *entry; |
| 916 | |
| 917 | /* |
| 918 | * Make o->additional_path_headers contain the subset of all_headers |
| 919 | * that match o->pathspec. If there aren't any that match o->pathspec, |
| 920 | * then make o->additional_path_headers be NULL. |
| 921 | */ |
| 922 | |
| 923 | if (!o->pathspec.nr) { |
| 924 | o->additional_path_headers = all_headers; |
| 925 | return; |
| 926 | } |
| 927 | |
| 928 | o->additional_path_headers = xmalloc(sizeof(struct strmap)); |
| 929 | strmap_init_with_options(o->additional_path_headers, NULL, 0); |
| 930 | strmap_for_each_entry(all_headers, &iter, entry) { |
| 931 | if (match_pathspec(the_repository->index, &o->pathspec, |
| 932 | entry->key, strlen(entry->key), |
| 933 | 0 /* prefix */, NULL /* seen */, |
| 934 | 0 /* is_dir */)) |
| 935 | strmap_put(o->additional_path_headers, |
| 936 | entry->key, entry->value); |
| 937 | } |
| 938 | if (!strmap_get_size(o->additional_path_headers)) { |
| 939 | strmap_clear(o->additional_path_headers, 0); |
| 940 | FREE_AND_NULL(o->additional_path_headers); |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | static void cleanup_additional_headers(struct diff_options *o) |
| 945 | { |
| 946 | if (!o->pathspec.nr) { |
| 947 | o->additional_path_headers = NULL; |
| 948 | return; |
| 949 | } |
| 950 | if (!o->additional_path_headers) |
| 951 | return; |
| 952 | |
| 953 | strmap_clear(o->additional_path_headers, 0); |
| 954 | FREE_AND_NULL(o->additional_path_headers); |
| 955 | } |
| 956 | |
Elijah Newren | db757e8 | 2022-02-02 02:37:28 +0000 | [diff] [blame] | 957 | static int do_remerge_diff(struct rev_info *opt, |
| 958 | struct commit_list *parents, |
| 959 | struct object_id *oid, |
| 960 | struct commit *commit) |
| 961 | { |
| 962 | struct merge_options o; |
| 963 | struct commit_list *bases; |
| 964 | struct merge_result res = {0}; |
| 965 | struct pretty_print_context ctx = {0}; |
| 966 | struct commit *parent1 = parents->item; |
| 967 | struct commit *parent2 = parents->next->item; |
| 968 | struct strbuf parent1_desc = STRBUF_INIT; |
| 969 | struct strbuf parent2_desc = STRBUF_INIT; |
| 970 | |
| 971 | /* Setup merge options */ |
| 972 | init_merge_options(&o, the_repository); |
| 973 | o.show_rename_progress = 0; |
Elijah Newren | 20323d1 | 2022-02-02 02:37:35 +0000 | [diff] [blame] | 974 | o.record_conflict_msgs_as_headers = 1; |
| 975 | o.msg_header_prefix = "remerge"; |
Elijah Newren | db757e8 | 2022-02-02 02:37:28 +0000 | [diff] [blame] | 976 | |
| 977 | ctx.abbrev = DEFAULT_ABBREV; |
| 978 | format_commit_message(parent1, "%h (%s)", &parent1_desc, &ctx); |
| 979 | format_commit_message(parent2, "%h (%s)", &parent2_desc, &ctx); |
| 980 | o.branch1 = parent1_desc.buf; |
| 981 | o.branch2 = parent2_desc.buf; |
| 982 | |
| 983 | /* Parse the relevant commits and get the merge bases */ |
| 984 | parse_commit_or_die(parent1); |
| 985 | parse_commit_or_die(parent2); |
| 986 | bases = get_merge_bases(parent1, parent2); |
| 987 | |
| 988 | /* Re-merge the parents */ |
| 989 | merge_incore_recursive(&o, bases, parent1, parent2, &res); |
| 990 | |
| 991 | /* Show the diff */ |
Elijah Newren | 20323d1 | 2022-02-02 02:37:35 +0000 | [diff] [blame] | 992 | setup_additional_headers(&opt->diffopt, res.path_messages); |
Elijah Newren | db757e8 | 2022-02-02 02:37:28 +0000 | [diff] [blame] | 993 | diff_tree_oid(&res.tree->object.oid, oid, "", &opt->diffopt); |
| 994 | log_tree_diff_flush(opt); |
| 995 | |
| 996 | /* Cleanup */ |
Elijah Newren | 20323d1 | 2022-02-02 02:37:35 +0000 | [diff] [blame] | 997 | cleanup_additional_headers(&opt->diffopt); |
Elijah Newren | db757e8 | 2022-02-02 02:37:28 +0000 | [diff] [blame] | 998 | strbuf_release(&parent1_desc); |
| 999 | strbuf_release(&parent2_desc); |
| 1000 | merge_finalize(&o, &res); |
Elijah Newren | 7b90ab4 | 2022-02-02 02:37:29 +0000 | [diff] [blame] | 1001 | |
| 1002 | /* Clean up the contents of the temporary object directory */ |
| 1003 | if (opt->remerge_objdir) |
| 1004 | tmp_objdir_discard_objects(opt->remerge_objdir); |
| 1005 | else |
| 1006 | BUG("did a remerge diff without remerge_objdir?!?"); |
Elijah Newren | db757e8 | 2022-02-02 02:37:28 +0000 | [diff] [blame] | 1007 | |
| 1008 | return !opt->loginfo; |
| 1009 | } |
| 1010 | |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1011 | /* |
| 1012 | * Show the diff of a commit. |
| 1013 | * |
| 1014 | * Return true if we printed any log info messages |
| 1015 | */ |
| 1016 | static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log) |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1017 | { |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1018 | int showed_log; |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1019 | struct commit_list *parents; |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 1020 | struct object_id *oid; |
Sergey Organov | a6d19ec | 2020-12-21 18:19:53 +0300 | [diff] [blame] | 1021 | int is_merge; |
| 1022 | int all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status; |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1023 | |
Sergey Organov | a6d19ec | 2020-12-21 18:19:53 +0300 | [diff] [blame] | 1024 | if (!all_need_diff && !opt->merges_need_diff) |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1025 | return 0; |
| 1026 | |
Jeff King | 7059dcc | 2013-10-24 04:52:36 -0400 | [diff] [blame] | 1027 | parse_commit_or_die(commit); |
Derrick Stolee | 2e27bd7 | 2018-04-06 19:09:38 +0000 | [diff] [blame] | 1028 | oid = get_commit_tree_oid(commit); |
Thomas Rast | d1b9b76 | 2013-03-28 09:19:34 +0100 | [diff] [blame] | 1029 | |
Thomas Rast | 53d00b3 | 2013-07-31 22:13:20 +0200 | [diff] [blame] | 1030 | parents = get_saved_parents(opt, commit); |
Sergey Organov | a6d19ec | 2020-12-21 18:19:53 +0300 | [diff] [blame] | 1031 | is_merge = parents && parents->next; |
| 1032 | if (!is_merge && !all_need_diff) |
| 1033 | return 0; |
| 1034 | |
| 1035 | /* Root commit? */ |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1036 | if (!parents) { |
Rene Scharfe | 2b60356 | 2006-10-26 18:52:39 +0200 | [diff] [blame] | 1037 | if (opt->show_root_diff) { |
Brandon Williams | 7b8dea0 | 2017-05-30 10:30:57 -0700 | [diff] [blame] | 1038 | diff_root_tree_oid(oid, "", &opt->diffopt); |
Rene Scharfe | 2b60356 | 2006-10-26 18:52:39 +0200 | [diff] [blame] | 1039 | log_tree_diff_flush(opt); |
| 1040 | } |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1041 | return !opt->loginfo; |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Sergey Organov | a6d19ec | 2020-12-21 18:19:53 +0300 | [diff] [blame] | 1044 | if (is_merge) { |
Elijah Newren | db757e8 | 2022-02-02 02:37:28 +0000 | [diff] [blame] | 1045 | int octopus = (parents->next->next != NULL); |
| 1046 | |
| 1047 | if (opt->remerge_diff) { |
| 1048 | if (octopus) { |
| 1049 | show_log(opt); |
| 1050 | fprintf(opt->diffopt.file, |
| 1051 | "diff: warning: Skipping remerge-diff " |
| 1052 | "for octopus merges.\n"); |
| 1053 | return 1; |
| 1054 | } |
| 1055 | return do_remerge_diff(opt, parents, oid, commit); |
| 1056 | } |
Sergey Organov | 1a2c4d8 | 2020-12-21 18:19:46 +0300 | [diff] [blame] | 1057 | if (opt->combine_merges) |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1058 | return do_diff_combined(opt, commit); |
Sergey Organov | 1a2c4d8 | 2020-12-21 18:19:46 +0300 | [diff] [blame] | 1059 | if (opt->separate_merges) { |
| 1060 | if (!opt->first_parent_merges) { |
| 1061 | /* Show parent info for multiple diffs */ |
| 1062 | log->parent = parents->item; |
| 1063 | } |
| 1064 | } else |
| 1065 | return 0; |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1068 | showed_log = 0; |
| 1069 | for (;;) { |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1070 | struct commit *parent = parents->item; |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1071 | |
Jeff King | 7059dcc | 2013-10-24 04:52:36 -0400 | [diff] [blame] | 1072 | parse_commit_or_die(parent); |
Derrick Stolee | 2e27bd7 | 2018-04-06 19:09:38 +0000 | [diff] [blame] | 1073 | diff_tree_oid(get_commit_tree_oid(parent), |
Brandon Williams | 66f414f | 2017-05-30 10:31:03 -0700 | [diff] [blame] | 1074 | oid, "", &opt->diffopt); |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1075 | log_tree_diff_flush(opt); |
| 1076 | |
| 1077 | showed_log |= !opt->loginfo; |
| 1078 | |
| 1079 | /* Set up the log info for the next parent, if any.. */ |
| 1080 | parents = parents->next; |
Sergey Organov | 3291eea | 2020-12-21 18:19:40 +0300 | [diff] [blame] | 1081 | if (!parents || opt->first_parent_merges) |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1082 | break; |
| 1083 | log->parent = parents->item; |
| 1084 | opt->loginfo = log; |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1085 | } |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1086 | return showed_log; |
| 1087 | } |
| 1088 | |
| 1089 | int log_tree_commit(struct rev_info *opt, struct commit *commit) |
| 1090 | { |
| 1091 | struct log_info log; |
Ævar Arnfjörð Bjarmason | e900d49 | 2021-02-11 11:45:34 +0100 | [diff] [blame] | 1092 | int shown; |
| 1093 | /* maybe called by e.g. cmd_log_walk(), maybe stand-alone */ |
| 1094 | int no_free = opt->diffopt.no_free; |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1095 | |
| 1096 | log.commit = commit; |
| 1097 | log.parent = NULL; |
| 1098 | opt->loginfo = &log; |
Ævar Arnfjörð Bjarmason | e900d49 | 2021-02-11 11:45:34 +0100 | [diff] [blame] | 1099 | opt->diffopt.no_free = 1; |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1100 | |
Thomas Rast | 12da1d1 | 2013-03-28 17:47:32 +0100 | [diff] [blame] | 1101 | if (opt->line_level_traverse) |
| 1102 | return line_log_print(opt, commit); |
| 1103 | |
Nguyễn Thái Ngọc Duy | 1b32dec | 2014-03-25 20:23:27 +0700 | [diff] [blame] | 1104 | if (opt->track_linear && !opt->linear && !opt->reverse_output_stage) |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 1105 | fprintf(opt->diffopt.file, "\n%s\n", opt->break_bar); |
Junio C Hamano | 3eefc18 | 2006-04-18 16:45:27 -0700 | [diff] [blame] | 1106 | shown = log_tree_diff(opt, commit, &log); |
| 1107 | if (!shown && opt->loginfo && opt->always_show_header) { |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1108 | log.parent = NULL; |
Adam Simpkins | 0286565 | 2008-04-29 01:32:59 -0700 | [diff] [blame] | 1109 | show_log(opt); |
Junio C Hamano | 3eefc18 | 2006-04-18 16:45:27 -0700 | [diff] [blame] | 1110 | shown = 1; |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1111 | } |
Nguyễn Thái Ngọc Duy | 1b32dec | 2014-03-25 20:23:27 +0700 | [diff] [blame] | 1112 | if (opt->track_linear && !opt->linear && opt->reverse_output_stage) |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 1113 | fprintf(opt->diffopt.file, "\n%s\n", opt->break_bar); |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 1114 | opt->loginfo = NULL; |
Johannes Schindelin | 4d7b0ef | 2016-06-22 17:01:32 +0200 | [diff] [blame] | 1115 | maybe_flush_or_die(opt->diffopt.file, "stdout"); |
Ævar Arnfjörð Bjarmason | e900d49 | 2021-02-11 11:45:34 +0100 | [diff] [blame] | 1116 | opt->diffopt.no_free = no_free; |
| 1117 | diff_free(&opt->diffopt); |
Junio C Hamano | 3eefc18 | 2006-04-18 16:45:27 -0700 | [diff] [blame] | 1118 | return shown; |
Junio C Hamano | 5f1c3f0 | 2006-04-09 01:11:11 -0700 | [diff] [blame] | 1119 | } |