| 4100 | } |
| 4101 | |
| 4102 | static int do_merge(struct repository *r, |
| 4103 | struct commit *commit, |
| 4104 | const char *arg, int arg_len, |
| 4105 | int flags, int *check_todo, struct replay_opts *opts) |
| 4106 | { |
| 4107 | struct replay_ctx *ctx = opts->ctx; |
| 4108 | int run_commit_flags = 0; |
| 4109 | struct strbuf ref_name = STRBUF_INIT; |
| 4110 | struct commit *head_commit, *merge_commit, *i; |
| 4111 | struct commit_list *bases = NULL, *j; |
| 4112 | struct commit_list *to_merge = NULL, **tail = &to_merge; |
| 4113 | const char *strategy = !opts->xopts.nr && |
| 4114 | (!opts->strategy || |
| 4115 | !strcmp(opts->strategy, "recursive") || |
| 4116 | !strcmp(opts->strategy, "ort")) ? |
| 4117 | NULL : opts->strategy; |
| 4118 | struct merge_options o; |
| 4119 | int merge_arg_len, oneline_offset, can_fast_forward, ret, k; |
| 4120 | static struct lock_file lock; |
| 4121 | const char *p; |
| 4122 | const char *reflog_action = reflog_message(opts, "merge", NULL); |
| 4123 | |
| 4124 | if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { |
| 4125 | ret = -1; |
| 4126 | goto leave_merge; |
| 4127 | } |
| 4128 | |
| 4129 | head_commit = lookup_commit_reference_by_name("HEAD"); |
| 4130 | if (!head_commit) { |
| 4131 | ret = error(_("cannot merge without a current revision")); |
| 4132 | goto leave_merge; |
| 4133 | } |
| 4134 | |
| 4135 | /* |
| 4136 | * For octopus merges, the arg starts with the list of revisions to be |
| 4137 | * merged. The list is optionally followed by '#' and the oneline. |
| 4138 | */ |
| 4139 | merge_arg_len = oneline_offset = arg_len; |
| 4140 | for (p = arg; p - arg < arg_len; p += strspn(p, " \t\n")) { |
| 4141 | if (!*p) |
| 4142 | break; |
| 4143 | if (*p == '#' && (!p[1] || isspace(p[1]))) { |
| 4144 | p += 1 + strspn(p + 1, " \t\n"); |
| 4145 | oneline_offset = p - arg; |
| 4146 | break; |
| 4147 | } |
| 4148 | k = strcspn(p, " \t\n"); |
| 4149 | if (!k) |
| 4150 | continue; |
| 4151 | merge_commit = lookup_label(r, p, k, &ref_name); |
| 4152 | if (!merge_commit) { |
| 4153 | ret = error(_("unable to parse '%.*s'"), k, p); |
| 4154 | goto leave_merge; |
| 4155 | } |
| 4156 | tail = &commit_list_insert(merge_commit, tail)->next; |
| 4157 | p += k; |
| 4158 | merge_arg_len = p - arg; |
| 4159 | } |
no test coverage detected