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