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