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 | |
| 8 | static const char *fmt_merge_msg_usage = |
Stephan Beyer | 1b1dd23 | 2008-07-13 15:36:15 +0200 | [diff] [blame] | 9 | "git fmt-merge-msg [--log] [--no-log] [--file <file>]"; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 10 | |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 11 | static int merge_summary; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 12 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 13 | 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] | 14 | { |
SZEDER Gábor | 6cd9cfe | 2008-04-06 03:23:45 +0200 | [diff] [blame] | 15 | static int found_merge_log = 0; |
| 16 | if (!strcmp("merge.log", key)) { |
| 17 | found_merge_log = 1; |
| 18 | merge_summary = git_config_bool(key, value); |
| 19 | } |
| 20 | if (!found_merge_log && !strcmp("merge.summary", key)) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 21 | merge_summary = git_config_bool(key, value); |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | struct list { |
| 26 | char **list; |
| 27 | void **payload; |
| 28 | unsigned nr, alloc; |
| 29 | }; |
| 30 | |
| 31 | static void append_to_list(struct list *list, char *value, void *payload) |
| 32 | { |
| 33 | if (list->nr == list->alloc) { |
| 34 | list->alloc += 32; |
Jonas Fonseca | 83572c1 | 2006-08-26 16:16:18 +0200 | [diff] [blame] | 35 | list->list = xrealloc(list->list, sizeof(char *) * list->alloc); |
| 36 | list->payload = xrealloc(list->payload, |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 37 | sizeof(char *) * list->alloc); |
| 38 | } |
| 39 | list->payload[list->nr] = payload; |
| 40 | list->list[list->nr++] = value; |
| 41 | } |
| 42 | |
| 43 | static int find_in_list(struct list *list, char *value) |
| 44 | { |
| 45 | int i; |
| 46 | |
| 47 | for (i = 0; i < list->nr; i++) |
| 48 | if (!strcmp(list->list[i], value)) |
| 49 | return i; |
| 50 | |
| 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | static void free_list(struct list *list) |
| 55 | { |
| 56 | int i; |
| 57 | |
| 58 | if (list->alloc == 0) |
| 59 | return; |
| 60 | |
| 61 | for (i = 0; i < list->nr; i++) { |
| 62 | free(list->list[i]); |
Junio C Hamano | 4cac42b | 2006-08-27 21:19:39 -0700 | [diff] [blame] | 63 | free(list->payload[i]); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 64 | } |
| 65 | free(list->list); |
| 66 | free(list->payload); |
| 67 | list->nr = list->alloc = 0; |
| 68 | } |
| 69 | |
| 70 | struct src_data { |
| 71 | struct list branch, tag, r_branch, generic; |
| 72 | int head_status; |
| 73 | }; |
| 74 | |
| 75 | static struct list srcs = { NULL, NULL, 0, 0}; |
| 76 | static struct list origins = { NULL, NULL, 0, 0}; |
| 77 | |
| 78 | static int handle_line(char *line) |
| 79 | { |
| 80 | int i, len = strlen(line); |
| 81 | unsigned char *sha1; |
| 82 | char *src, *origin; |
| 83 | struct src_data *src_data; |
Junio C Hamano | e918c6a | 2006-07-12 22:21:05 -0700 | [diff] [blame] | 84 | int pulling_head = 0; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 85 | |
| 86 | if (len < 43 || line[40] != '\t') |
| 87 | return 1; |
| 88 | |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 89 | if (!prefixcmp(line + 41, "not-for-merge")) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 90 | return 0; |
| 91 | |
| 92 | if (line[41] != '\t') |
| 93 | return 2; |
| 94 | |
| 95 | line[40] = 0; |
| 96 | sha1 = xmalloc(20); |
| 97 | i = get_sha1(line, sha1); |
| 98 | line[40] = '\t'; |
| 99 | if (i) |
| 100 | return 3; |
| 101 | |
| 102 | if (line[len - 1] == '\n') |
| 103 | line[len - 1] = 0; |
| 104 | line += 42; |
| 105 | |
| 106 | src = strstr(line, " of "); |
| 107 | if (src) { |
| 108 | *src = 0; |
| 109 | src += 4; |
Junio C Hamano | e918c6a | 2006-07-12 22:21:05 -0700 | [diff] [blame] | 110 | pulling_head = 0; |
| 111 | } else { |
| 112 | src = line; |
| 113 | pulling_head = 1; |
| 114 | } |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 115 | |
| 116 | i = find_in_list(&srcs, src); |
| 117 | if (i < 0) { |
| 118 | i = srcs.nr; |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 119 | append_to_list(&srcs, xstrdup(src), |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 120 | xcalloc(1, sizeof(struct src_data))); |
| 121 | } |
| 122 | src_data = srcs.payload[i]; |
| 123 | |
Junio C Hamano | e918c6a | 2006-07-12 22:21:05 -0700 | [diff] [blame] | 124 | if (pulling_head) { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 125 | origin = xstrdup(src); |
Junio C Hamano | e918c6a | 2006-07-12 22:21:05 -0700 | [diff] [blame] | 126 | src_data->head_status |= 1; |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 127 | } else if (!prefixcmp(line, "branch ")) { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 128 | origin = xstrdup(line + 7); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 129 | append_to_list(&src_data->branch, origin, NULL); |
| 130 | src_data->head_status |= 2; |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 131 | } else if (!prefixcmp(line, "tag ")) { |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 132 | origin = line; |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 133 | append_to_list(&src_data->tag, xstrdup(origin + 4), NULL); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 134 | src_data->head_status |= 2; |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 135 | } else if (!prefixcmp(line, "remote branch ")) { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 136 | origin = xstrdup(line + 14); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 137 | append_to_list(&src_data->r_branch, origin, NULL); |
| 138 | src_data->head_status |= 2; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 139 | } else { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 140 | origin = xstrdup(src); |
| 141 | append_to_list(&src_data->generic, xstrdup(line), NULL); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 142 | src_data->head_status |= 2; |
| 143 | } |
| 144 | |
| 145 | if (!strcmp(".", src) || !strcmp(src, origin)) { |
| 146 | int len = strlen(origin); |
| 147 | if (origin[0] == '\'' && origin[len - 1] == '\'') { |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 148 | origin = xmemdupz(origin + 1, len - 2); |
| 149 | } else { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 150 | origin = xstrdup(origin); |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 151 | } |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 152 | } else { |
Jonas Fonseca | 2d7320d | 2006-09-01 00:32:39 +0200 | [diff] [blame] | 153 | char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 154 | sprintf(new_origin, "%s of %s", origin, src); |
| 155 | origin = new_origin; |
| 156 | } |
| 157 | append_to_list(&origins, origin, sha1); |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | static void print_joined(const char *singular, const char *plural, |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 162 | struct list *list, struct strbuf *out) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 163 | { |
| 164 | if (list->nr == 0) |
| 165 | return; |
| 166 | if (list->nr == 1) { |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 167 | strbuf_addf(out, "%s%s", singular, list->list[0]); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 168 | } else { |
| 169 | int i; |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 170 | strbuf_addstr(out, plural); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 171 | for (i = 0; i < list->nr - 1; i++) |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 172 | strbuf_addf(out, "%s%s", i > 0 ? ", " : "", list->list[i]); |
| 173 | strbuf_addf(out, " and %s", list->list[list->nr - 1]); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
| 177 | static void shortlog(const char *name, unsigned char *sha1, |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 178 | struct commit *head, struct rev_info *rev, int limit, |
| 179 | struct strbuf *out) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 180 | { |
| 181 | int i, count = 0; |
| 182 | struct commit *commit; |
| 183 | struct object *branch; |
| 184 | struct list subjects = { NULL, NULL, 0, 0 }; |
Linus Torvalds | 7dc0fe3 | 2007-11-12 23:16:08 -0800 | [diff] [blame] | 185 | int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 186 | |
| 187 | branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40); |
Linus Torvalds | 1974632 | 2006-07-11 20:45:31 -0700 | [diff] [blame] | 188 | if (!branch || branch->type != OBJ_COMMIT) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 189 | return; |
| 190 | |
| 191 | setup_revisions(0, NULL, rev, NULL); |
| 192 | rev->ignore_merges = 1; |
| 193 | add_pending_object(rev, branch, name); |
| 194 | add_pending_object(rev, &head->object, "^HEAD"); |
| 195 | head->object.flags |= UNINTERESTING; |
Martin Koegler | 3d51e1b | 2008-02-18 08:31:56 +0100 | [diff] [blame] | 196 | if (prepare_revision_walk(rev)) |
| 197 | die("revision walk setup failed"); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 198 | while ((commit = get_revision(rev)) != NULL) { |
| 199 | char *oneline, *bol, *eol; |
| 200 | |
| 201 | /* ignore merges */ |
| 202 | if (commit->parents && commit->parents->next) |
| 203 | continue; |
| 204 | |
| 205 | count++; |
| 206 | if (subjects.nr > limit) |
| 207 | continue; |
| 208 | |
| 209 | bol = strstr(commit->buffer, "\n\n"); |
Linus Torvalds | 6a28518 | 2008-04-15 11:01:36 -0700 | [diff] [blame] | 210 | if (bol) { |
| 211 | unsigned char c; |
| 212 | do { |
| 213 | c = *++bol; |
| 214 | } while (isspace(c)); |
| 215 | if (!c) |
| 216 | bol = NULL; |
| 217 | } |
| 218 | |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 219 | if (!bol) { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 220 | append_to_list(&subjects, xstrdup(sha1_to_hex( |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 221 | commit->object.sha1)), |
| 222 | NULL); |
| 223 | continue; |
| 224 | } |
| 225 | |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 226 | eol = strchr(bol, '\n'); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 227 | if (eol) { |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 228 | oneline = xmemdupz(bol, eol - bol); |
| 229 | } else { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 230 | oneline = xstrdup(bol); |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 231 | } |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 232 | append_to_list(&subjects, oneline, NULL); |
| 233 | } |
| 234 | |
| 235 | if (count > limit) |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 236 | strbuf_addf(out, "\n* %s: (%d commits)\n", name, count); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 237 | else |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 238 | strbuf_addf(out, "\n* %s:\n", name); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 239 | |
| 240 | for (i = 0; i < subjects.nr; i++) |
| 241 | if (i >= limit) |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 242 | strbuf_addf(out, " ...\n"); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 243 | else |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 244 | strbuf_addf(out, " %s\n", subjects.list[i]); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 245 | |
| 246 | clear_commit_marks((struct commit *)branch, flags); |
| 247 | clear_commit_marks(head, flags); |
| 248 | free_commit_list(rev->commits); |
| 249 | rev->commits = NULL; |
| 250 | rev->pending.nr = 0; |
| 251 | |
| 252 | free_list(&subjects); |
| 253 | } |
| 254 | |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 255 | int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) { |
| 256 | int limit = 20, i = 0, pos = 0; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 257 | char line[1024]; |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 258 | char *p = line, *sep = ""; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 259 | unsigned char head_sha1[20]; |
Linus Torvalds | ed378ec | 2006-09-11 20:17:35 -0700 | [diff] [blame] | 260 | const char *current_branch; |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 261 | |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 262 | /* get current branch */ |
| 263 | current_branch = resolve_ref("HEAD", head_sha1, 1, NULL); |
| 264 | if (!current_branch) |
| 265 | die("No current branch"); |
| 266 | if (!prefixcmp(current_branch, "refs/heads/")) |
| 267 | current_branch += 11; |
| 268 | |
| 269 | /* get a line */ |
| 270 | while (pos < in->len) { |
| 271 | int len; |
| 272 | char *newline; |
| 273 | |
| 274 | p = in->buf + pos; |
| 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 | { |
| 350 | FILE *in = stdin; |
| 351 | struct strbuf input, output; |
| 352 | int ret; |
| 353 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 354 | git_config(fmt_merge_msg_config, NULL); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 355 | |
| 356 | while (argc > 1) { |
SZEDER Gábor | 6cd9cfe | 2008-04-06 03:23:45 +0200 | [diff] [blame] | 357 | if (!strcmp(argv[1], "--log") || !strcmp(argv[1], "--summary")) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 358 | merge_summary = 1; |
SZEDER Gábor | 6cd9cfe | 2008-04-06 03:23:45 +0200 | [diff] [blame] | 359 | else if (!strcmp(argv[1], "--no-log") |
| 360 | || !strcmp(argv[1], "--no-summary")) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 361 | merge_summary = 0; |
| 362 | else if (!strcmp(argv[1], "-F") || !strcmp(argv[1], "--file")) { |
Michael Coleman | 163d7b9 | 2007-02-27 23:44:42 -0600 | [diff] [blame] | 363 | if (argc < 3) |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 364 | die ("Which file?"); |
| 365 | if (!strcmp(argv[2], "-")) |
| 366 | in = stdin; |
| 367 | else { |
| 368 | fclose(in); |
| 369 | in = fopen(argv[2], "r"); |
Michael Coleman | 163d7b9 | 2007-02-27 23:44:42 -0600 | [diff] [blame] | 370 | if (!in) |
| 371 | die("cannot open %s", argv[2]); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 372 | } |
| 373 | argc--; argv++; |
| 374 | } else |
| 375 | break; |
| 376 | argc--; argv++; |
| 377 | } |
| 378 | |
| 379 | if (argc > 1) |
| 380 | usage(fmt_merge_msg_usage); |
| 381 | |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 382 | strbuf_init(&input, 0); |
| 383 | if (strbuf_read(&input, fileno(in), 0) < 0) |
| 384 | die("could not read input file %s", strerror(errno)); |
| 385 | strbuf_init(&output, 0); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 386 | |
Miklos Vajna | 0b9a969 | 2008-06-27 18:21:59 +0200 | [diff] [blame] | 387 | ret = fmt_merge_msg(merge_summary, &input, &output); |
| 388 | if (ret) |
| 389 | return ret; |
| 390 | printf("%s", output.buf); |
Johannes Schindelin | 00449f9 | 2006-07-03 17:18:43 +0200 | [diff] [blame] | 391 | return 0; |
| 392 | } |