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