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