| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "diff.h" |
| 3 | #include "commit.h" |
| René Scharfe | cab4feb | 2008-09-04 21:39:21 | [diff] [blame] | 4 | #include "tag.h" |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 5 | #include "graph.h" |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 6 | #include "log-tree.h" |
| Johannes Schindelin | 8860fd4 | 2007-01-11 10:47:48 | [diff] [blame] | 7 | #include "reflog-walk.h" |
| René Scharfe | cab4feb | 2008-09-04 21:39:21 | [diff] [blame] | 8 | #include "refs.h" |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 9 | |
| Linus Torvalds | ca135e7 | 2007-04-16 23:05:10 | [diff] [blame] | 10 | struct decoration name_decoration = { "object names" }; |
| 11 | |
| René Scharfe | cab4feb | 2008-09-04 21:39:21 | [diff] [blame] | 12 | static void add_name_decoration(const char *prefix, const char *name, struct object *obj) |
| 13 | { |
| 14 | int plen = strlen(prefix); |
| 15 | int nlen = strlen(name); |
| 16 | struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen); |
| 17 | memcpy(res->name, prefix, plen); |
| 18 | memcpy(res->name + plen, name, nlen + 1); |
| 19 | res->next = add_decoration(&name_decoration, obj, res); |
| 20 | } |
| 21 | |
| 22 | static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data) |
| 23 | { |
| 24 | struct object *obj = parse_object(sha1); |
| 25 | if (!obj) |
| 26 | return 0; |
| 27 | add_name_decoration("", refname, obj); |
| 28 | while (obj->type == OBJ_TAG) { |
| 29 | obj = ((struct tag *)obj)->tagged; |
| 30 | if (!obj) |
| 31 | break; |
| 32 | add_name_decoration("tag: ", refname, obj); |
| 33 | } |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | void load_ref_decorations(void) |
| 38 | { |
| 39 | static int loaded; |
| 40 | if (!loaded) { |
| 41 | loaded = 1; |
| 42 | for_each_ref(add_ref_decoration, NULL); |
| 43 | } |
| 44 | } |
| 45 | |
| Linus Torvalds | c8c893c | 2006-05-03 14:59:00 | [diff] [blame] | 46 | static void show_parents(struct commit *commit, int abbrev) |
| 47 | { |
| 48 | struct commit_list *p; |
| 49 | for (p = commit->parents; p ; p = p->next) { |
| 50 | struct commit *parent = p->item; |
| 51 | printf(" %s", diff_unique_abbrev(parent->object.sha1, abbrev)); |
| 52 | } |
| 53 | } |
| 54 | |
| Linus Torvalds | 0f3a290 | 2008-10-27 19:51:59 | [diff] [blame] | 55 | void show_decorations(struct rev_info *opt, struct commit *commit) |
| Linus Torvalds | ca135e7 | 2007-04-16 23:05:10 | [diff] [blame] | 56 | { |
| 57 | const char *prefix; |
| 58 | struct name_decoration *decoration; |
| 59 | |
| Linus Torvalds | 0f3a290 | 2008-10-27 19:51:59 | [diff] [blame] | 60 | if (opt->show_source && commit->util) |
| Linus Torvalds | 8c4021a | 2008-11-15 18:02:01 | [diff] [blame] | 61 | printf("\t%s", (char *) commit->util); |
| Linus Torvalds | d467a52 | 2008-11-03 19:23:57 | [diff] [blame] | 62 | if (!opt->show_decorations) |
| 63 | return; |
| Linus Torvalds | ca135e7 | 2007-04-16 23:05:10 | [diff] [blame] | 64 | decoration = lookup_decoration(&name_decoration, &commit->object); |
| 65 | if (!decoration) |
| 66 | return; |
| 67 | prefix = " ("; |
| 68 | while (decoration) { |
| 69 | printf("%s%s", prefix, decoration->name); |
| 70 | prefix = ", "; |
| 71 | decoration = decoration->next; |
| 72 | } |
| 73 | putchar(')'); |
| 74 | } |
| 75 | |
| Franck Bui-Huu | fc1c75e | 2006-08-29 11:37:06 | [diff] [blame] | 76 | /* |
| 77 | * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches |
| 78 | * Signed-off-by: and Acked-by: lines. |
| 79 | */ |
| 80 | static int detect_any_signoff(char *letter, int size) |
| 81 | { |
| 82 | char ch, *cp; |
| 83 | int seen_colon = 0; |
| 84 | int seen_at = 0; |
| 85 | int seen_name = 0; |
| 86 | int seen_head = 0; |
| 87 | |
| 88 | cp = letter + size; |
| 89 | while (letter <= --cp && (ch = *cp) == '\n') |
| 90 | continue; |
| 91 | |
| 92 | while (letter <= cp) { |
| 93 | ch = *cp--; |
| 94 | if (ch == '\n') |
| 95 | break; |
| 96 | |
| 97 | if (!seen_at) { |
| 98 | if (ch == '@') |
| 99 | seen_at = 1; |
| 100 | continue; |
| 101 | } |
| 102 | if (!seen_colon) { |
| 103 | if (ch == '@') |
| 104 | return 0; |
| 105 | else if (ch == ':') |
| 106 | seen_colon = 1; |
| 107 | else |
| 108 | seen_name = 1; |
| 109 | continue; |
| 110 | } |
| 111 | if (('A' <= ch && ch <= 'Z') || |
| 112 | ('a' <= ch && ch <= 'z') || |
| 113 | ch == '-') { |
| 114 | seen_head = 1; |
| 115 | continue; |
| 116 | } |
| 117 | /* no empty last line doesn't match */ |
| 118 | return 0; |
| 119 | } |
| 120 | return seen_head && seen_name; |
| 121 | } |
| 122 | |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 123 | static void append_signoff(struct strbuf *sb, const char *signoff) |
| Junio C Hamano | cf2251b | 2006-05-31 22:11:49 | [diff] [blame] | 124 | { |
| Junio C Hamano | cf2251b | 2006-05-31 22:11:49 | [diff] [blame] | 125 | static const char signed_off_by[] = "Signed-off-by: "; |
| Junio C Hamano | 80583c0 | 2007-06-11 07:34:54 | [diff] [blame] | 126 | size_t signoff_len = strlen(signoff); |
| Franck Bui-Huu | fc1c75e | 2006-08-29 11:37:06 | [diff] [blame] | 127 | int has_signoff = 0; |
| Junio C Hamano | 80583c0 | 2007-06-11 07:34:54 | [diff] [blame] | 128 | char *cp; |
| Junio C Hamano | cf2251b | 2006-05-31 22:11:49 | [diff] [blame] | 129 | |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 130 | cp = sb->buf; |
| Junio C Hamano | cf2251b | 2006-05-31 22:11:49 | [diff] [blame] | 131 | |
| 132 | /* First see if we already have the sign-off by the signer */ |
| Franck Bui-Huu | fc1c75e | 2006-08-29 11:37:06 | [diff] [blame] | 133 | while ((cp = strstr(cp, signed_off_by))) { |
| 134 | |
| 135 | has_signoff = 1; |
| 136 | |
| Junio C Hamano | cf2251b | 2006-05-31 22:11:49 | [diff] [blame] | 137 | cp += strlen(signed_off_by); |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 138 | if (cp + signoff_len >= sb->buf + sb->len) |
| Franck Bui-Huu | fc1c75e | 2006-08-29 11:37:06 | [diff] [blame] | 139 | break; |
| 140 | if (strncmp(cp, signoff, signoff_len)) |
| 141 | continue; |
| 142 | if (!isspace(cp[signoff_len])) |
| 143 | continue; |
| 144 | /* we already have him */ |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 145 | return; |
| Junio C Hamano | cf2251b | 2006-05-31 22:11:49 | [diff] [blame] | 146 | } |
| 147 | |
| Franck Bui-Huu | fc1c75e | 2006-08-29 11:37:06 | [diff] [blame] | 148 | if (!has_signoff) |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 149 | has_signoff = detect_any_signoff(sb->buf, sb->len); |
| Franck Bui-Huu | fc1c75e | 2006-08-29 11:37:06 | [diff] [blame] | 150 | |
| 151 | if (!has_signoff) |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 152 | strbuf_addch(sb, '\n'); |
| Franck Bui-Huu | c35f4c3 | 2006-08-13 18:30:27 | [diff] [blame] | 153 | |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 154 | strbuf_addstr(sb, signed_off_by); |
| 155 | strbuf_add(sb, signoff, signoff_len); |
| 156 | strbuf_addch(sb, '\n'); |
| Junio C Hamano | cf2251b | 2006-05-31 22:11:49 | [diff] [blame] | 157 | } |
| 158 | |
| Johannes Schindelin | e00de24 | 2007-02-09 00:43:54 | [diff] [blame] | 159 | static unsigned int digits_in_number(unsigned int number) |
| 160 | { |
| 161 | unsigned int i = 10, result = 1; |
| 162 | while (i <= number) { |
| 163 | i *= 10; |
| 164 | result++; |
| 165 | } |
| 166 | return result; |
| 167 | } |
| 168 | |
| Junio C Hamano | 4593fb8 | 2007-10-31 21:55:17 | [diff] [blame] | 169 | static int has_non_ascii(const char *s) |
| 170 | { |
| 171 | int ch; |
| 172 | if (!s) |
| 173 | return 0; |
| 174 | while ((ch = *s++) != '\0') { |
| 175 | if (non_ascii(ch)) |
| 176 | return 1; |
| 177 | } |
| 178 | return 0; |
| 179 | } |
| 180 | |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 181 | void log_write_email_headers(struct rev_info *opt, const char *name, |
| Junio C Hamano | 267123b | 2008-03-15 07:09:20 | [diff] [blame] | 182 | const char **subject_p, |
| 183 | const char **extra_headers_p, |
| 184 | int *need_8bit_cte_p) |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 185 | { |
| 186 | const char *subject = NULL; |
| 187 | const char *extra_headers = opt->extra_headers; |
| Junio C Hamano | 267123b | 2008-03-15 07:09:20 | [diff] [blame] | 188 | |
| 189 | *need_8bit_cte_p = 0; /* unknown */ |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 190 | if (opt->total > 0) { |
| 191 | static char buffer[64]; |
| 192 | snprintf(buffer, sizeof(buffer), |
| 193 | "Subject: [%s %0*d/%d] ", |
| 194 | opt->subject_prefix, |
| 195 | digits_in_number(opt->total), |
| 196 | opt->nr, opt->total); |
| 197 | subject = buffer; |
| 198 | } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) { |
| 199 | static char buffer[256]; |
| 200 | snprintf(buffer, sizeof(buffer), |
| 201 | "Subject: [%s] ", |
| 202 | opt->subject_prefix); |
| 203 | subject = buffer; |
| 204 | } else { |
| 205 | subject = "Subject: "; |
| 206 | } |
| 207 | |
| 208 | printf("From %s Mon Sep 17 00:00:00 2001\n", name); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 209 | graph_show_oneline(opt->graph); |
| 210 | if (opt->message_id) { |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 211 | printf("Message-Id: <%s>\n", opt->message_id); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 212 | graph_show_oneline(opt->graph); |
| 213 | } |
| 214 | if (opt->ref_message_id) { |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 215 | printf("In-Reply-To: <%s>\nReferences: <%s>\n", |
| 216 | opt->ref_message_id, opt->ref_message_id); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 217 | graph_show_oneline(opt->graph); |
| 218 | } |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 219 | if (opt->mime_boundary) { |
| 220 | static char subject_buffer[1024]; |
| 221 | static char buffer[1024]; |
| Junio C Hamano | 267123b | 2008-03-15 07:09:20 | [diff] [blame] | 222 | *need_8bit_cte_p = -1; /* NEVER */ |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 223 | snprintf(subject_buffer, sizeof(subject_buffer) - 1, |
| 224 | "%s" |
| 225 | "MIME-Version: 1.0\n" |
| 226 | "Content-Type: multipart/mixed;" |
| 227 | " boundary=\"%s%s\"\n" |
| 228 | "\n" |
| 229 | "This is a multi-part message in MIME " |
| 230 | "format.\n" |
| 231 | "--%s%s\n" |
| 232 | "Content-Type: text/plain; " |
| 233 | "charset=UTF-8; format=fixed\n" |
| 234 | "Content-Transfer-Encoding: 8bit\n\n", |
| 235 | extra_headers ? extra_headers : "", |
| 236 | mime_boundary_leader, opt->mime_boundary, |
| 237 | mime_boundary_leader, opt->mime_boundary); |
| 238 | extra_headers = subject_buffer; |
| 239 | |
| 240 | snprintf(buffer, sizeof(buffer) - 1, |
| Kevin Ballard | 6b2fbaa | 2008-07-30 05:49:33 | [diff] [blame] | 241 | "\n--%s%s\n" |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 242 | "Content-Type: text/x-patch;" |
| 243 | " name=\"%s.diff\"\n" |
| 244 | "Content-Transfer-Encoding: 8bit\n" |
| 245 | "Content-Disposition: %s;" |
| 246 | " filename=\"%s.diff\"\n\n", |
| 247 | mime_boundary_leader, opt->mime_boundary, |
| 248 | name, |
| 249 | opt->no_inline ? "attachment" : "inline", |
| 250 | name); |
| 251 | opt->diffopt.stat_sep = buffer; |
| 252 | } |
| 253 | *subject_p = subject; |
| 254 | *extra_headers_p = extra_headers; |
| 255 | } |
| 256 | |
| Adam Simpkins | 0286565 | 2008-04-29 08:32:59 | [diff] [blame] | 257 | void show_log(struct rev_info *opt) |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 258 | { |
| Brandon Casey | f285a2d | 2008-10-09 19:12:12 | [diff] [blame] | 259 | struct strbuf msgbuf = STRBUF_INIT; |
| Timo Hirvonen | 39bc9a6 | 2006-06-25 10:54:14 | [diff] [blame] | 260 | struct log_info *log = opt->loginfo; |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 261 | struct commit *commit = log->commit, *parent = log->parent; |
| 262 | int abbrev = opt->diffopt.abbrev; |
| 263 | int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; |
| Johannes Schindelin | 20ff068 | 2006-06-02 13:21:17 | [diff] [blame] | 264 | const char *subject = NULL, *extra_headers = opt->extra_headers; |
| Junio C Hamano | 6bf4f1b | 2008-03-15 00:10:09 | [diff] [blame] | 265 | int need_8bit_cte = 0; |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 266 | |
| 267 | opt->loginfo = NULL; |
| 268 | if (!opt->verbose_header) { |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 269 | graph_show_commit(opt->graph); |
| 270 | |
| Adam Simpkins | 7528f27 | 2008-05-25 07:07:21 | [diff] [blame] | 271 | if (!opt->graph) { |
| 272 | if (commit->object.flags & BOUNDARY) |
| 273 | putchar('-'); |
| 274 | else if (commit->object.flags & UNINTERESTING) |
| 275 | putchar('^'); |
| 276 | else if (opt->left_right) { |
| 277 | if (commit->object.flags & SYMMETRIC_LEFT) |
| 278 | putchar('<'); |
| 279 | else |
| 280 | putchar('>'); |
| 281 | } |
| Junio C Hamano | 74bd902 | 2006-12-16 23:31:25 | [diff] [blame] | 282 | } |
| Linus Torvalds | c8c893c | 2006-05-03 14:59:00 | [diff] [blame] | 283 | fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); |
| Adam Simpkins | 885cf80 | 2008-05-04 10:36:52 | [diff] [blame] | 284 | if (opt->print_parents) |
| Linus Torvalds | c8c893c | 2006-05-03 14:59:00 | [diff] [blame] | 285 | show_parents(commit, abbrev_commit); |
| Linus Torvalds | 0f3a290 | 2008-10-27 19:51:59 | [diff] [blame] | 286 | show_decorations(opt, commit); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 287 | if (opt->graph && !graph_is_commit_finished(opt->graph)) { |
| 288 | putchar('\n'); |
| 289 | graph_show_remainder(opt->graph); |
| 290 | } |
| Ryan Anderson | 1dcb692 | 2006-08-07 12:11:23 | [diff] [blame] | 291 | putchar(opt->diffopt.line_termination); |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 292 | return; |
| 293 | } |
| 294 | |
| 295 | /* |
| Adam Simpkins | 0286565 | 2008-04-29 08:32:59 | [diff] [blame] | 296 | * If use_terminator is set, add a newline at the end of the entry. |
| 297 | * Otherwise, add a diffopt.line_termination character before all |
| 298 | * entries but the first. (IOW, as a separator between entries) |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 299 | */ |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 300 | if (opt->shown_one && !opt->use_terminator) { |
| 301 | /* |
| 302 | * If entries are separated by a newline, the output |
| 303 | * should look human-readable. If the last entry ended |
| 304 | * with a newline, print the graph output before this |
| 305 | * newline. Otherwise it will end up as a completely blank |
| 306 | * line and will look like a gap in the graph. |
| 307 | * |
| 308 | * If the entry separator is not a newline, the output is |
| 309 | * primarily intended for programmatic consumption, and we |
| 310 | * never want the extra graph output before the entry |
| 311 | * separator. |
| 312 | */ |
| 313 | if (opt->diffopt.line_termination == '\n' && |
| 314 | !opt->missing_newline) |
| 315 | graph_show_padding(opt->graph); |
| Linus Torvalds | abd4e22 | 2007-02-07 19:49:56 | [diff] [blame] | 316 | putchar(opt->diffopt.line_termination); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 317 | } |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 318 | opt->shown_one = 1; |
| 319 | |
| 320 | /* |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 321 | * If the history graph was requested, |
| 322 | * print the graph, up to this commit's line |
| 323 | */ |
| 324 | graph_show_commit(opt->graph); |
| 325 | |
| 326 | /* |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 327 | * Print header line of header.. |
| 328 | */ |
| Junio C Hamano | 3eefc18 | 2006-04-18 23:45:27 | [diff] [blame] | 329 | |
| Johannes Schindelin | 596524b | 2006-05-05 02:30:52 | [diff] [blame] | 330 | if (opt->commit_format == CMIT_FMT_EMAIL) { |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 331 | log_write_email_headers(opt, sha1_to_hex(commit->object.sha1), |
| Junio C Hamano | 267123b | 2008-03-15 07:09:20 | [diff] [blame] | 332 | &subject, &extra_headers, |
| 333 | &need_8bit_cte); |
| Johannes Schindelin | e52a5de | 2007-02-23 00:35:03 | [diff] [blame] | 334 | } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { |
| Pierre Habouzit | 8f67f8a | 2007-11-10 19:05:14 | [diff] [blame] | 335 | fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout); |
| Junio C Hamano | 74bd902 | 2006-12-16 23:31:25 | [diff] [blame] | 336 | if (opt->commit_format != CMIT_FMT_ONELINE) |
| 337 | fputs("commit ", stdout); |
| Adam Simpkins | 7528f27 | 2008-05-25 07:07:21 | [diff] [blame] | 338 | |
| 339 | if (!opt->graph) { |
| 340 | if (commit->object.flags & BOUNDARY) |
| 341 | putchar('-'); |
| 342 | else if (commit->object.flags & UNINTERESTING) |
| 343 | putchar('^'); |
| 344 | else if (opt->left_right) { |
| 345 | if (commit->object.flags & SYMMETRIC_LEFT) |
| 346 | putchar('<'); |
| 347 | else |
| 348 | putchar('>'); |
| 349 | } |
| Junio C Hamano | 74bd902 | 2006-12-16 23:31:25 | [diff] [blame] | 350 | } |
| 351 | fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), |
| 352 | stdout); |
| Adam Simpkins | 885cf80 | 2008-05-04 10:36:52 | [diff] [blame] | 353 | if (opt->print_parents) |
| Junio C Hamano | c66b6c0 | 2006-05-06 21:42:08 | [diff] [blame] | 354 | show_parents(commit, abbrev_commit); |
| Junio C Hamano | 73f0a15 | 2006-05-24 19:19:47 | [diff] [blame] | 355 | if (parent) |
| Junio C Hamano | 3eefc18 | 2006-04-18 23:45:27 | [diff] [blame] | 356 | printf(" (from %s)", |
| 357 | diff_unique_abbrev(parent->object.sha1, |
| 358 | abbrev_commit)); |
| Linus Torvalds | 0f3a290 | 2008-10-27 19:51:59 | [diff] [blame] | 359 | show_decorations(opt, commit); |
| Pierre Habouzit | 8f67f8a | 2007-11-10 19:05:14 | [diff] [blame] | 360 | printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET)); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 361 | if (opt->commit_format == CMIT_FMT_ONELINE) { |
| 362 | putchar(' '); |
| 363 | } else { |
| 364 | putchar('\n'); |
| 365 | graph_show_oneline(opt->graph); |
| 366 | } |
| Nicolas Pitre | 903b45f | 2007-01-28 03:40:36 | [diff] [blame] | 367 | if (opt->reflog_info) { |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 368 | /* |
| 369 | * setup_revisions() ensures that opt->reflog_info |
| 370 | * and opt->graph cannot both be set, |
| 371 | * so we don't need to worry about printing the |
| 372 | * graph info here. |
| 373 | */ |
| Junio C Hamano | 4d12a47 | 2007-01-20 08:51:41 | [diff] [blame] | 374 | show_reflog_message(opt->reflog_info, |
| Johannes Schindelin | 4e244cb | 2007-02-08 20:58:33 | [diff] [blame] | 375 | opt->commit_format == CMIT_FMT_ONELINE, |
| Junio C Hamano | a7b02cc | 2007-04-25 06:36:22 | [diff] [blame] | 376 | opt->date_mode); |
| Adam Simpkins | 0286565 | 2008-04-29 08:32:59 | [diff] [blame] | 377 | if (opt->commit_format == CMIT_FMT_ONELINE) |
| Nicolas Pitre | 903b45f | 2007-01-28 03:40:36 | [diff] [blame] | 378 | return; |
| Nicolas Pitre | 903b45f | 2007-01-28 03:40:36 | [diff] [blame] | 379 | } |
| Junio C Hamano | 3eefc18 | 2006-04-18 23:45:27 | [diff] [blame] | 380 | } |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 381 | |
| Linus Torvalds | 3131b71 | 2008-02-09 22:02:07 | [diff] [blame] | 382 | if (!commit->buffer) |
| 383 | return; |
| 384 | |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 385 | /* |
| 386 | * And then the pretty-printed message itself |
| 387 | */ |
| Junio C Hamano | 6bf4f1b | 2008-03-15 00:10:09 | [diff] [blame] | 388 | if (need_8bit_cte >= 0) |
| 389 | need_8bit_cte = has_non_ascii(opt->add_signoff); |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 390 | pretty_print_commit(opt->commit_format, commit, &msgbuf, |
| Junio C Hamano | 4593fb8 | 2007-10-31 21:55:17 | [diff] [blame] | 391 | abbrev, subject, extra_headers, opt->date_mode, |
| Junio C Hamano | 6bf4f1b | 2008-03-15 00:10:09 | [diff] [blame] | 392 | need_8bit_cte); |
| Junio C Hamano | cf2251b | 2006-05-31 22:11:49 | [diff] [blame] | 393 | |
| 394 | if (opt->add_signoff) |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 395 | append_signoff(&msgbuf, opt->add_signoff); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 396 | if (opt->show_log_size) { |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 397 | printf("log size %i\n", (int)msgbuf.len); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 398 | graph_show_oneline(opt->graph); |
| 399 | } |
| Marco Costalba | 9fa3465 | 2007-07-20 18:15:13 | [diff] [blame] | 400 | |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 401 | /* |
| 402 | * Set opt->missing_newline if msgbuf doesn't |
| 403 | * end in a newline (including if it is empty) |
| 404 | */ |
| 405 | if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n') |
| 406 | opt->missing_newline = 1; |
| 407 | else |
| 408 | opt->missing_newline = 0; |
| 409 | |
| 410 | if (opt->graph) |
| 411 | graph_show_commit_msg(opt->graph, &msgbuf); |
| 412 | else |
| Govind Salinas | 42c8c74 | 2008-03-21 15:05:06 | [diff] [blame] | 413 | fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 414 | if (opt->use_terminator) { |
| 415 | if (!opt->missing_newline) |
| 416 | graph_show_padding(opt->graph); |
| Adam Simpkins | 9b58bfe | 2008-04-29 08:33:00 | [diff] [blame] | 417 | putchar('\n'); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 418 | } |
| 419 | |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 420 | strbuf_release(&msgbuf); |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 421 | } |
| 422 | |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 423 | int log_tree_diff_flush(struct rev_info *opt) |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 424 | { |
| 425 | diffcore_std(&opt->diffopt); |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 426 | |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 427 | if (diff_queue_is_empty()) { |
| 428 | int saved_fmt = opt->diffopt.output_format; |
| 429 | opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT; |
| 430 | diff_flush(&opt->diffopt); |
| 431 | opt->diffopt.output_format = saved_fmt; |
| 432 | return 0; |
| 433 | } |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 434 | |
| Junio C Hamano | 3969cf7 | 2006-06-27 22:08:19 | [diff] [blame] | 435 | if (opt->loginfo && !opt->no_commit_id) { |
| 436 | /* When showing a verbose header (i.e. log message), |
| 437 | * and not in --pretty=oneline format, we would want |
| 438 | * an extra newline between the end of log and the |
| 439 | * output for readability. |
| 440 | */ |
| Adam Simpkins | 0286565 | 2008-04-29 08:32:59 | [diff] [blame] | 441 | show_log(opt); |
| Linus Torvalds | 304b5af | 2007-10-09 16:35:22 | [diff] [blame] | 442 | if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) && |
| 443 | opt->verbose_header && |
| Junio C Hamano | 3969cf7 | 2006-06-27 22:08:19 | [diff] [blame] | 444 | opt->commit_format != CMIT_FMT_ONELINE) { |
| 445 | int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH; |
| 446 | if ((pch & opt->diffopt.output_format) == pch) |
| Linus Torvalds | abd4e22 | 2007-02-07 19:49:56 | [diff] [blame] | 447 | printf("---"); |
| 448 | putchar('\n'); |
| Junio C Hamano | 3969cf7 | 2006-06-27 22:08:19 | [diff] [blame] | 449 | } |
| 450 | } |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 451 | diff_flush(&opt->diffopt); |
| 452 | return 1; |
| 453 | } |
| 454 | |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 455 | static int do_diff_combined(struct rev_info *opt, struct commit *commit) |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 456 | { |
| 457 | unsigned const char *sha1 = commit->object.sha1; |
| 458 | |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 459 | diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt); |
| 460 | return !opt->loginfo; |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 461 | } |
| 462 | |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 463 | /* |
| 464 | * Show the diff of a commit. |
| 465 | * |
| 466 | * Return true if we printed any log info messages |
| 467 | */ |
| 468 | static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log) |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 469 | { |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 470 | int showed_log; |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 471 | struct commit_list *parents; |
| 472 | unsigned const char *sha1 = commit->object.sha1; |
| 473 | |
| Peter Valdemar Mørch | 84102a3 | 2008-08-11 06:46:25 | [diff] [blame] | 474 | if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS)) |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 475 | return 0; |
| 476 | |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 477 | /* Root commit? */ |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 478 | parents = commit->parents; |
| 479 | if (!parents) { |
| Rene Scharfe | 2b60356 | 2006-10-26 16:52:39 | [diff] [blame] | 480 | if (opt->show_root_diff) { |
| 481 | diff_root_tree_sha1(sha1, "", &opt->diffopt); |
| 482 | log_tree_diff_flush(opt); |
| 483 | } |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 484 | return !opt->loginfo; |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /* More than one parent? */ |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 488 | if (parents && parents->next) { |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 489 | if (opt->ignore_merges) |
| 490 | return 0; |
| 491 | else if (opt->combine_merges) |
| 492 | return do_diff_combined(opt, commit); |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 493 | |
| 494 | /* If we show individual diffs, show the parent info */ |
| 495 | log->parent = parents->item; |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 496 | } |
| 497 | |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 498 | showed_log = 0; |
| 499 | for (;;) { |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 500 | struct commit *parent = parents->item; |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 501 | |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 502 | diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt); |
| 503 | log_tree_diff_flush(opt); |
| 504 | |
| 505 | showed_log |= !opt->loginfo; |
| 506 | |
| 507 | /* Set up the log info for the next parent, if any.. */ |
| 508 | parents = parents->next; |
| 509 | if (!parents) |
| 510 | break; |
| 511 | log->parent = parents->item; |
| 512 | opt->loginfo = log; |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 513 | } |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 514 | return showed_log; |
| 515 | } |
| 516 | |
| 517 | int log_tree_commit(struct rev_info *opt, struct commit *commit) |
| 518 | { |
| 519 | struct log_info log; |
| Junio C Hamano | 3eefc18 | 2006-04-18 23:45:27 | [diff] [blame] | 520 | int shown; |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 521 | |
| 522 | log.commit = commit; |
| 523 | log.parent = NULL; |
| 524 | opt->loginfo = &log; |
| 525 | |
| Junio C Hamano | 3eefc18 | 2006-04-18 23:45:27 | [diff] [blame] | 526 | shown = log_tree_diff(opt, commit, &log); |
| 527 | if (!shown && opt->loginfo && opt->always_show_header) { |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 528 | log.parent = NULL; |
| Adam Simpkins | 0286565 | 2008-04-29 08:32:59 | [diff] [blame] | 529 | show_log(opt); |
| Junio C Hamano | 3eefc18 | 2006-04-18 23:45:27 | [diff] [blame] | 530 | shown = 1; |
| Linus Torvalds | 9153983 | 2006-04-17 18:59:32 | [diff] [blame] | 531 | } |
| 532 | opt->loginfo = NULL; |
| Theodore Ts'o | 06f59e9 | 2007-06-29 17:40:46 | [diff] [blame] | 533 | maybe_flush_or_die(stdout, "stdout"); |
| Junio C Hamano | 3eefc18 | 2006-04-18 23:45:27 | [diff] [blame] | 534 | return shown; |
| Junio C Hamano | 5f1c3f0 | 2006-04-09 08:11:11 | [diff] [blame] | 535 | } |