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