Matthias Kestenholz | 25f38f0 | 2006-08-02 23:52:00 +0200 | [diff] [blame] | 1 | #include "builtin.h" |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 2 | #include "cache.h" |
| 3 | #include "commit.h" |
| 4 | #include "diff.h" |
| 5 | #include "revision.h" |
| 6 | #include "tag.h" |
| 7 | |
Pierre Habouzit | c8ef038 | 2008-10-02 14:59:18 +0200 | [diff] [blame] | 8 | static const char * const fmt_merge_msg_usage[] = { |
| 9 | "git fmt-merge-msg [--log|--no-log] [--file <file>]", |
| 10 | NULL |
| 11 | }; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 12 | |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 13 | static int merge_summary; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 14 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 15 | static int fmt_merge_msg_config(const char *key, const char *value, void *cb) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 16 | { |
SZEDER Gábor | 6cd9cfe | 2008-04-06 03:23:45 +0200 | [diff] [blame] | 17 | static int found_merge_log = 0; |
| 18 | if (!strcmp("merge.log", key)) { |
| 19 | found_merge_log = 1; |
| 20 | merge_summary = git_config_bool(key, value); |
| 21 | } |
| 22 | if (!found_merge_log && !strcmp("merge.summary", key)) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 23 | merge_summary = git_config_bool(key, value); |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | struct list { |
| 28 | char **list; |
| 29 | void **payload; |
| 30 | unsigned nr, alloc; |
| 31 | }; |
| 32 | |
| 33 | static void append_to_list(struct list *list, char *value, void *payload) |
| 34 | { |
| 35 | if (list->nr == list->alloc) { |
| 36 | list->alloc += 32; |
Jonas Fonseca | 83572c1 | 2006-08-26 16:16:18 +0200 | [diff] [blame] | 37 | list->list = xrealloc(list->list, sizeof(char *) * list->alloc); |
| 38 | list->payload = xrealloc(list->payload, |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 39 | sizeof(char *) * list->alloc); |
| 40 | } |
| 41 | list->payload[list->nr] = payload; |
| 42 | list->list[list->nr++] = value; |
| 43 | } |
| 44 | |
| 45 | static int find_in_list(struct list *list, char *value) |
| 46 | { |
| 47 | int i; |
| 48 | |
| 49 | for (i = 0; i < list->nr; i++) |
| 50 | if (!strcmp(list->list[i], value)) |
| 51 | return i; |
| 52 | |
| 53 | return -1; |
| 54 | } |
| 55 | |
| 56 | static void free_list(struct list *list) |
| 57 | { |
| 58 | int i; |
| 59 | |
| 60 | if (list->alloc == 0) |
| 61 | return; |
| 62 | |
| 63 | for (i = 0; i < list->nr; i++) { |
| 64 | free(list->list[i]); |
Junio C Hamano | 4cac42b | 2006-08-27 21:19:39 -0700 | [diff] [blame] | 65 | free(list->payload[i]); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 66 | } |
| 67 | free(list->list); |
| 68 | free(list->payload); |
| 69 | list->nr = list->alloc = 0; |
| 70 | } |
| 71 | |
| 72 | struct src_data { |
| 73 | struct list branch, tag, r_branch, generic; |
| 74 | int head_status; |
| 75 | }; |
| 76 | |
| 77 | static struct list srcs = { NULL, NULL, 0, 0}; |
| 78 | static struct list origins = { NULL, NULL, 0, 0}; |
| 79 | |
| 80 | static int handle_line(char *line) |
| 81 | { |
| 82 | int i, len = strlen(line); |
| 83 | unsigned char *sha1; |
| 84 | char *src, *origin; |
| 85 | struct src_data *src_data; |
Junio C Hamano | e918c6a | 2006-07-12 22:21:05 -0700 | [diff] [blame] | 86 | int pulling_head = 0; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 87 | |
| 88 | if (len < 43 || line[40] != '\t') |
| 89 | return 1; |
| 90 | |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 91 | if (!prefixcmp(line + 41, "not-for-merge")) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 92 | return 0; |
| 93 | |
| 94 | if (line[41] != '\t') |
| 95 | return 2; |
| 96 | |
| 97 | line[40] = 0; |
| 98 | sha1 = xmalloc(20); |
| 99 | i = get_sha1(line, sha1); |
| 100 | line[40] = '\t'; |
| 101 | if (i) |
| 102 | return 3; |
| 103 | |
| 104 | if (line[len - 1] == '\n') |
| 105 | line[len - 1] = 0; |
| 106 | line += 42; |
| 107 | |
| 108 | src = strstr(line, " of "); |
| 109 | if (src) { |
| 110 | *src = 0; |
| 111 | src += 4; |
Junio C Hamano | e918c6a | 2006-07-12 22:21:05 -0700 | [diff] [blame] | 112 | pulling_head = 0; |
| 113 | } else { |
| 114 | src = line; |
| 115 | pulling_head = 1; |
| 116 | } |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 117 | |
| 118 | i = find_in_list(&srcs, src); |
| 119 | if (i < 0) { |
| 120 | i = srcs.nr; |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 121 | append_to_list(&srcs, xstrdup(src), |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 122 | xcalloc(1, sizeof(struct src_data))); |
| 123 | } |
| 124 | src_data = srcs.payload[i]; |
| 125 | |
Junio C Hamano | e918c6a | 2006-07-12 22:21:05 -0700 | [diff] [blame] | 126 | if (pulling_head) { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 127 | origin = xstrdup(src); |
Junio C Hamano | e918c6a | 2006-07-12 22:21:05 -0700 | [diff] [blame] | 128 | src_data->head_status |= 1; |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 129 | } else if (!prefixcmp(line, "branch ")) { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 130 | origin = xstrdup(line + 7); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 131 | append_to_list(&src_data->branch, origin, NULL); |
| 132 | src_data->head_status |= 2; |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 133 | } else if (!prefixcmp(line, "tag ")) { |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 134 | origin = line; |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 135 | append_to_list(&src_data->tag, xstrdup(origin + 4), NULL); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 136 | src_data->head_status |= 2; |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 137 | } else if (!prefixcmp(line, "remote branch ")) { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 138 | origin = xstrdup(line + 14); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 139 | append_to_list(&src_data->r_branch, origin, NULL); |
| 140 | src_data->head_status |= 2; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 141 | } else { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 142 | origin = xstrdup(src); |
| 143 | append_to_list(&src_data->generic, xstrdup(line), NULL); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 144 | src_data->head_status |= 2; |
| 145 | } |
| 146 | |
| 147 | if (!strcmp(".", src) || !strcmp(src, origin)) { |
| 148 | int len = strlen(origin); |
| 149 | if (origin[0] == '\'' && origin[len - 1] == '\'') { |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 150 | origin = xmemdupz(origin + 1, len - 2); |
| 151 | } else { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 152 | origin = xstrdup(origin); |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 153 | } |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 154 | } else { |
Jonas Fonseca | 2d7320d | 2006-09-01 00:32:39 +0200 | [diff] [blame] | 155 | char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 156 | sprintf(new_origin, "%s of %s", origin, src); |
| 157 | origin = new_origin; |
| 158 | } |
| 159 | append_to_list(&origins, origin, sha1); |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static void print_joined(const char *singular, const char *plural, |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 164 | struct list *list, struct strbuf *out) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 165 | { |
| 166 | if (list->nr == 0) |
| 167 | return; |
| 168 | if (list->nr == 1) { |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 169 | strbuf_addf(out, "%s%s", singular, list->list[0]); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 170 | } else { |
| 171 | int i; |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 172 | strbuf_addstr(out, plural); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 173 | for (i = 0; i < list->nr - 1; i++) |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 174 | strbuf_addf(out, "%s%s", i > 0 ? ", " : "", list->list[i]); |
| 175 | strbuf_addf(out, " and %s", list->list[list->nr - 1]); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | static void shortlog(const char *name, unsigned char *sha1, |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 180 | struct commit *head, struct rev_info *rev, int limit, |
| 181 | struct strbuf *out) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 182 | { |
| 183 | int i, count = 0; |
| 184 | struct commit *commit; |
| 185 | struct object *branch; |
| 186 | struct list subjects = { NULL, NULL, 0, 0 }; |
Linus Torvalds | 7dc0fe3 | 2007-11-12 23:16:08 -0800 | [diff] [blame] | 187 | int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 188 | |
| 189 | branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40); |
Linus Torvalds | 1974632 | 2006-07-11 20:45:31 -0700 | [diff] [blame] | 190 | if (!branch || branch->type != OBJ_COMMIT) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 191 | return; |
| 192 | |
| 193 | setup_revisions(0, NULL, rev, NULL); |
| 194 | rev->ignore_merges = 1; |
| 195 | add_pending_object(rev, branch, name); |
| 196 | add_pending_object(rev, &head->object, "^HEAD"); |
| 197 | head->object.flags |= UNINTERESTING; |
Martin Koegler | 3d51e1b | 2008-02-18 08:31:56 +0100 | [diff] [blame] | 198 | if (prepare_revision_walk(rev)) |
| 199 | die("revision walk setup failed"); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 200 | while ((commit = get_revision(rev)) != NULL) { |
| 201 | char *oneline, *bol, *eol; |
| 202 | |
| 203 | /* ignore merges */ |
| 204 | if (commit->parents && commit->parents->next) |
| 205 | continue; |
| 206 | |
| 207 | count++; |
| 208 | if (subjects.nr > limit) |
| 209 | continue; |
| 210 | |
| 211 | bol = strstr(commit->buffer, "\n\n"); |
Linus Torvalds | 6a28518 | 2008-04-15 11:01:36 -0700 | [diff] [blame] | 212 | if (bol) { |
| 213 | unsigned char c; |
| 214 | do { |
| 215 | c = *++bol; |
| 216 | } while (isspace(c)); |
| 217 | if (!c) |
| 218 | bol = NULL; |
| 219 | } |
| 220 | |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 221 | if (!bol) { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 222 | append_to_list(&subjects, xstrdup(sha1_to_hex( |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 223 | commit->object.sha1)), |
| 224 | NULL); |
| 225 | continue; |
| 226 | } |
| 227 | |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 228 | eol = strchr(bol, '\n'); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 229 | if (eol) { |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 230 | oneline = xmemdupz(bol, eol - bol); |
| 231 | } else { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 232 | oneline = xstrdup(bol); |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 233 | } |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 234 | append_to_list(&subjects, oneline, NULL); |
| 235 | } |
| 236 | |
| 237 | if (count > limit) |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 238 | strbuf_addf(out, "\n* %s: (%d commits)\n", name, count); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 239 | else |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 240 | strbuf_addf(out, "\n* %s:\n", name); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 241 | |
| 242 | for (i = 0; i < subjects.nr; i++) |
| 243 | if (i >= limit) |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 244 | strbuf_addf(out, " ...\n"); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 245 | else |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 246 | strbuf_addf(out, " %s\n", subjects.list[i]); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 247 | |
| 248 | clear_commit_marks((struct commit *)branch, flags); |
| 249 | clear_commit_marks(head, flags); |
| 250 | free_commit_list(rev->commits); |
| 251 | rev->commits = NULL; |
| 252 | rev->pending.nr = 0; |
| 253 | |
| 254 | free_list(&subjects); |
| 255 | } |
| 256 | |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 257 | int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) { |
| 258 | int limit = 20, i = 0, pos = 0; |
Benjamin Kramer | fd13b21 | 2009-03-07 21:02:26 +0100 | [diff] [blame] | 259 | char *sep = ""; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 260 | unsigned char head_sha1[20]; |
Linus Torvalds | ed378ec | 2006-09-11 20:17:35 -0700 | [diff] [blame] | 261 | const char *current_branch; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 262 | |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 263 | /* get current branch */ |
| 264 | current_branch = resolve_ref("HEAD", head_sha1, 1, NULL); |
| 265 | if (!current_branch) |
| 266 | die("No current branch"); |
| 267 | if (!prefixcmp(current_branch, "refs/heads/")) |
| 268 | current_branch += 11; |
| 269 | |
| 270 | /* get a line */ |
| 271 | while (pos < in->len) { |
| 272 | int len; |
Benjamin Kramer | fd13b21 | 2009-03-07 21:02:26 +0100 | [diff] [blame] | 273 | char *newline, *p = in->buf + pos; |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 274 | |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 275 | newline = strchr(p, '\n'); |
| 276 | len = newline ? newline - p : strlen(p); |
| 277 | pos += len + !!newline; |
| 278 | i++; |
| 279 | p[len] = 0; |
| 280 | if (handle_line(p)) |
| 281 | die ("Error in line %d: %.*s", i, len, p); |
| 282 | } |
| 283 | |
| 284 | strbuf_addstr(out, "Merge "); |
| 285 | for (i = 0; i < srcs.nr; i++) { |
| 286 | struct src_data *src_data = srcs.payload[i]; |
| 287 | const char *subsep = ""; |
| 288 | |
| 289 | strbuf_addstr(out, sep); |
| 290 | sep = "; "; |
| 291 | |
| 292 | if (src_data->head_status == 1) { |
| 293 | strbuf_addstr(out, srcs.list[i]); |
| 294 | continue; |
| 295 | } |
| 296 | if (src_data->head_status == 3) { |
| 297 | subsep = ", "; |
| 298 | strbuf_addstr(out, "HEAD"); |
| 299 | } |
| 300 | if (src_data->branch.nr) { |
| 301 | strbuf_addstr(out, subsep); |
| 302 | subsep = ", "; |
| 303 | print_joined("branch ", "branches ", &src_data->branch, |
| 304 | out); |
| 305 | } |
| 306 | if (src_data->r_branch.nr) { |
| 307 | strbuf_addstr(out, subsep); |
| 308 | subsep = ", "; |
| 309 | print_joined("remote branch ", "remote branches ", |
| 310 | &src_data->r_branch, out); |
| 311 | } |
| 312 | if (src_data->tag.nr) { |
| 313 | strbuf_addstr(out, subsep); |
| 314 | subsep = ", "; |
| 315 | print_joined("tag ", "tags ", &src_data->tag, out); |
| 316 | } |
| 317 | if (src_data->generic.nr) { |
| 318 | strbuf_addstr(out, subsep); |
| 319 | print_joined("commit ", "commits ", &src_data->generic, |
| 320 | out); |
| 321 | } |
| 322 | if (strcmp(".", srcs.list[i])) |
| 323 | strbuf_addf(out, " of %s", srcs.list[i]); |
| 324 | } |
| 325 | |
| 326 | if (!strcmp("master", current_branch)) |
| 327 | strbuf_addch(out, '\n'); |
| 328 | else |
| 329 | strbuf_addf(out, " into %s\n", current_branch); |
| 330 | |
| 331 | if (merge_summary) { |
| 332 | struct commit *head; |
| 333 | struct rev_info rev; |
| 334 | |
| 335 | head = lookup_commit(head_sha1); |
| 336 | init_revisions(&rev, NULL); |
| 337 | rev.commit_format = CMIT_FMT_ONELINE; |
| 338 | rev.ignore_merges = 1; |
| 339 | rev.limited = 1; |
| 340 | |
| 341 | for (i = 0; i < origins.nr; i++) |
| 342 | shortlog(origins.list[i], origins.payload[i], |
| 343 | head, &rev, limit, out); |
| 344 | } |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) |
| 349 | { |
Pierre Habouzit | c8ef038 | 2008-10-02 14:59:18 +0200 | [diff] [blame] | 350 | const char *inpath = NULL; |
| 351 | struct option options[] = { |
| 352 | OPT_BOOLEAN(0, "log", &merge_summary, "populate log with the shortlog"), |
| 353 | OPT_BOOLEAN(0, "summary", &merge_summary, "alias for --log"), |
Stephen Boyd | df217ed | 2009-05-23 11:53:13 -0700 | [diff] [blame] | 354 | OPT_FILENAME('F', "file", &inpath, "file to read from"), |
Pierre Habouzit | c8ef038 | 2008-10-02 14:59:18 +0200 | [diff] [blame] | 355 | OPT_END() |
| 356 | }; |
| 357 | |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 358 | FILE *in = stdin; |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 359 | struct strbuf input = STRBUF_INIT, output = STRBUF_INIT; |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 360 | int ret; |
| 361 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 362 | git_config(fmt_merge_msg_config, NULL); |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 363 | argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage, |
| 364 | 0); |
Pierre Habouzit | c8ef038 | 2008-10-02 14:59:18 +0200 | [diff] [blame] | 365 | if (argc > 0) |
| 366 | usage_with_options(fmt_merge_msg_usage, options); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 367 | |
Pierre Habouzit | c8ef038 | 2008-10-02 14:59:18 +0200 | [diff] [blame] | 368 | if (inpath && strcmp(inpath, "-")) { |
| 369 | in = fopen(inpath, "r"); |
| 370 | if (!in) |
Thomas Rast | 0721c31 | 2009-06-27 17:58:47 +0200 | [diff] [blame] | 371 | die_errno("cannot open '%s'", inpath); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 372 | } |
| 373 | |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 374 | if (strbuf_read(&input, fileno(in), 0) < 0) |
Thomas Rast | d824cbb | 2009-06-27 17:58:46 +0200 | [diff] [blame] | 375 | die_errno("could not read input file"); |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 376 | ret = fmt_merge_msg(merge_summary, &input, &output); |
| 377 | if (ret) |
| 378 | return ret; |
Pierre Habouzit | c8ef038 | 2008-10-02 14:59:18 +0200 | [diff] [blame] | 379 | write_in_full(STDOUT_FILENO, output.buf, output.len); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 380 | return 0; |
| 381 | } |