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