int fmt_merge_msg(struct strbuf *in, struct strbuf *out, struct fmt_merge_msg_opts *opts) { int i = 0, pos = 0; unsigned char head_sha1[20]; const char *current_branch; void *current_branch_to_free; /* get current branch */ current_branch = current_branch_to_free = resolve_refdup("HEAD", head_sha1, 1, NULL); if (!current_branch) die("No current branch"); if (!prefixcmp(current_branch, "refs/heads/")) current_branch += 11; /* get a line */ while (pos < in->len) { int len; char *newline, *p = in->buf + pos; newline = strchr(p, '\n'); len = newline ? newline - p : strlen(p); pos += len + !!newline; i++; p[len] = 0; if (handle_line(p)) die ("Error in line %d: %.*s", i, len, p); } if (opts->add_title && srcs.nr) fmt_merge_msg_title(out, current_branch); if (origins.nr) fmt_merge_msg_sigs(out); if (opts->shortlog_len) { struct commit *head; struct rev_info rev; head = lookup_commit_or_die(head_sha1, "HEAD"); init_revisions(&rev, NULL); rev.commit_format = CMIT_FMT_ONELINE; rev.ignore_merges = 1; rev.limited = 1; if (suffixcmp(out->buf, "\n")) strbuf_addch(out, '\n'); for (i = 0; i < origins.nr; i++) shortlog(origins.items[i].string, origins.items[i].util, head, &rev, opts->shortlog_len, out); } strbuf_complete_line(out); free(current_branch_to_free); return 0; }
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) { int limit = 20, i = 0; char line[1024]; FILE *in = stdin; const char *sep = ""; unsigned char head_sha1[20]; const char *current_branch; git_config(fmt_merge_msg_config); while (argc > 1) { if (!strcmp(argv[1], "--log") || !strcmp(argv[1], "--summary")) merge_summary = 1; else if (!strcmp(argv[1], "--no-log") || !strcmp(argv[1], "--no-summary")) merge_summary = 0; else if (!strcmp(argv[1], "-F") || !strcmp(argv[1], "--file")) { if (argc < 3) die ("Which file?"); if (!strcmp(argv[2], "-")) in = stdin; else { fclose(in); in = fopen(argv[2], "r"); if (!in) die("cannot open %s", argv[2]); } argc--; argv++; } else break; argc--; argv++; } if (argc > 1) usage(fmt_merge_msg_usage); /* get current branch */ current_branch = resolve_ref("HEAD", head_sha1, 1, NULL); if (!current_branch) die("No current branch"); if (!prefixcmp(current_branch, "refs/heads/")) current_branch += 11; while (fgets(line, sizeof(line), in)) { i++; if (line[0] == 0) continue; if (handle_line(line)) die ("Error in line %d: %s", i, line); } printf("Merge "); for (i = 0; i < srcs.nr; i++) { struct src_data *src_data = srcs.payload[i]; const char *subsep = ""; printf(sep); sep = "; "; if (src_data->head_status == 1) { printf(srcs.list[i]); continue; } if (src_data->head_status == 3) { subsep = ", "; printf("HEAD"); } if (src_data->branch.nr) { printf(subsep); subsep = ", "; print_joined("branch ", "branches ", &src_data->branch); } if (src_data->r_branch.nr) { printf(subsep); subsep = ", "; print_joined("remote branch ", "remote branches ", &src_data->r_branch); } if (src_data->tag.nr) { printf(subsep); subsep = ", "; print_joined("tag ", "tags ", &src_data->tag); } if (src_data->generic.nr) { printf(subsep); print_joined("commit ", "commits ", &src_data->generic); } if (strcmp(".", srcs.list[i])) printf(" of %s", srcs.list[i]); } if (!strcmp("master", current_branch)) putchar('\n'); else printf(" into %s\n", current_branch); if (merge_summary) { struct commit *head; struct rev_info rev; head = lookup_commit(head_sha1); init_revisions(&rev, prefix); rev.commit_format = CMIT_FMT_ONELINE; rev.ignore_merges = 1; rev.limited = 1; for (i = 0; i < origins.nr; i++) shortlog(origins.list[i], origins.payload[i], head, &rev, limit); } /* No cleanup yet; is standalone anyway */ return 0; }
int fmt_merge_msg(struct strbuf *in, struct strbuf *out, struct fmt_merge_msg_opts *opts) { int i = 0, pos = 0; unsigned char head_sha1[20]; const char *current_branch; void *current_branch_to_free; struct merge_parents merge_parents; memset(&merge_parents, 0, sizeof(merge_parents)); /* get current branch */ current_branch = current_branch_to_free = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL); if (!current_branch) die("No current branch"); if (starts_with(current_branch, "refs/heads/")) current_branch += 11; find_merge_parents(&merge_parents, in, head_sha1); /* get a line */ while (pos < in->len) { int len; char *newline, *p = in->buf + pos; newline = strchr(p, '\n'); len = newline ? newline - p : strlen(p); pos += len + !!newline; i++; p[len] = 0; if (handle_line(p, &merge_parents)) die ("Error in line %d: %.*s", i, len, p); } if (opts->add_title && srcs.nr) fmt_merge_msg_title(out, current_branch); if (origins.nr) fmt_merge_msg_sigs(out); if (opts->shortlog_len) { struct commit *head; struct rev_info rev; head = lookup_commit_or_die(head_sha1, "HEAD"); init_revisions(&rev, NULL); rev.commit_format = CMIT_FMT_ONELINE; rev.merge_diff_mode = MERGE_DIFF_IGNORE; rev.limited = 1; strbuf_complete_line(out); for (i = 0; i < origins.nr; i++) shortlog(origins.items[i].string, origins.items[i].util, head, &rev, opts, out); } strbuf_complete_line(out); free(current_branch_to_free); free(merge_parents.item); return 0; }