MCPcopy Create free account
hub / github.com/git/git / do_merge

Function do_merge

sequencer.c:4102–4412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4100}
4101
4102static 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 }

Callers 1

pick_commitsFunction · 0.85

Calls 15

reflog_messageFunction · 0.85
repo_hold_locked_indexFunction · 0.85
errorFunction · 0.85
lookup_labelFunction · 0.85
commit_list_insertFunction · 0.85
oideqFunction · 0.85
rollback_lock_fileFunction · 0.85
repo_logmsg_reencodeFunction · 0.85
oid_to_hexFunction · 0.85
find_commit_subjectFunction · 0.85

Tested by

no test coverage detected