merge-recursive.c: remove implicit dependency on the_repository

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jan 12, 2019 at 09:13 UTC d7cf3a96e9a02a4fba870e5cce7bf1a51abf5e54
1 file changed +24 -21
merge-recursive.c
+24 -21
@@ -146,7 +146,8 @@ static int err(struct merge_options *o, const char *err, ...)
146 return -1;
147 }
148
149 -static struct tree *shift_tree_object(struct tree *one, struct tree *two,
149 +static struct tree *shift_tree_object(struct repository *repo,
150 + struct tree *one, struct tree *two,
151 const char *subtree_shift)
152 {
153 struct object_id shifted;
@@ -159,12 +160,14 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
160 }
161 if (oideq(&two->object.oid, &shifted))
162 return two;
162 - return lookup_tree(the_repository, &shifted);
163 + return lookup_tree(repo, &shifted);
164 }
165
165 -static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
166 +static struct commit *make_virtual_commit(struct repository *repo,
167 + struct tree *tree,
168 + const char *comment)
169 {
167 - struct commit *commit = alloc_commit_node(the_repository);
170 + struct commit *commit = alloc_commit_node(repo);
171
172 set_merge_remote_desc(commit, comment, (struct object *)commit);
173 commit->maybe_tree = tree;
@@ -445,7 +448,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
448 return NULL;
449 }
450
448 - result = lookup_tree(the_repository, &istate->cache_tree->oid);
451 + result = lookup_tree(o->repo, &istate->cache_tree->oid);
452
453 return result;
454 }
@@ -1208,9 +1211,9 @@ static int merge_submodule(struct merge_options *o,
1211 return 0;
1212 }
1213
1211 - if (!(commit_base = lookup_commit_reference(the_repository, base)) ||
1212 - !(commit_a = lookup_commit_reference(the_repository, a)) ||
1213 - !(commit_b = lookup_commit_reference(the_repository, b))) {
1214 + if (!(commit_base = lookup_commit_reference(o->repo, base)) ||
1215 + !(commit_a = lookup_commit_reference(o->repo, a)) ||
1216 + !(commit_b = lookup_commit_reference(o->repo, b))) {
1217 output(o, 1, _("Failed to merge submodule %s (commits not present)"), path);
1218 return 0;
1219 }
@@ -3416,8 +3419,8 @@ int merge_trees(struct merge_options *o,
3419 }
3420
3421 if (o->subtree_shift) {
3419 - merge = shift_tree_object(head, merge, o->subtree_shift);
3420 - common = shift_tree_object(head, common, o->subtree_shift);
3422 + merge = shift_tree_object(o->repo, head, merge, o->subtree_shift);
3423 + common = shift_tree_object(o->repo, head, common, o->subtree_shift);
3424 }
3425
3426 if (oid_eq(&common->object.oid, &merge->object.oid)) {
@@ -3553,8 +3556,8 @@ int merge_recursive(struct merge_options *o,
3556 /* if there is no common ancestor, use an empty tree */
3557 struct tree *tree;
3558
3556 - tree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
3557 - merged_common_ancestors = make_virtual_commit(tree, "ancestor");
3559 + tree = lookup_tree(o->repo, o->repo->hash_algo->empty_tree);
3560 + merged_common_ancestors = make_virtual_commit(o->repo, tree, "ancestor");
3561 }
3562
3563 for (iter = ca; iter; iter = iter->next) {
@@ -3598,7 +3601,7 @@ int merge_recursive(struct merge_options *o,
3601 }
3602
3603 if (o->call_depth) {
3601 - *result = make_virtual_commit(mrtree, "merged tree");
3604 + *result = make_virtual_commit(o->repo, mrtree, "merged tree");
3605 commit_list_insert(h1, &(*result)->parents);
3606 commit_list_insert(h2, &(*result)->parents->next);
3607 }
@@ -3611,17 +3614,17 @@ int merge_recursive(struct merge_options *o,
3614 return clean;
3615 }
3616
3614 -static struct commit *get_ref(const struct object_id *oid, const char *name)
3617 +static struct commit *get_ref(struct repository *repo, const struct object_id *oid,
3618 + const char *name)
3619 {
3620 struct object *object;
3621
3618 - object = deref_tag(the_repository, parse_object(the_repository, oid),
3619 - name,
3620 - strlen(name));
3622 + object = deref_tag(repo, parse_object(repo, oid),
3623 + name, strlen(name));
3624 if (!object)
3625 return NULL;
3626 if (object->type == OBJ_TREE)
3624 - return make_virtual_commit((struct tree*)object, name);
3627 + return make_virtual_commit(repo, (struct tree*)object, name);
3628 if (object->type != OBJ_COMMIT)
3629 return NULL;
3630 if (parse_commit((struct commit *)object))
@@ -3638,15 +3641,15 @@ int merge_recursive_generic(struct merge_options *o,
3641 {
3642 int clean;
3643 struct lock_file lock = LOCK_INIT;
3641 - struct commit *head_commit = get_ref(head, o->branch1);
3642 - struct commit *next_commit = get_ref(merge, o->branch2);
3644 + struct commit *head_commit = get_ref(o->repo, head, o->branch1);
3645 + struct commit *next_commit = get_ref(o->repo, merge, o->branch2);
3646 struct commit_list *ca = NULL;
3647
3648 if (base_list) {
3649 int i;
3650 for (i = 0; i < num_base_list; ++i) {
3651 struct commit *base;
3649 - if (!(base = get_ref(base_list[i], oid_to_hex(base_list[i]))))
3652 + if (!(base = get_ref(o->repo, base_list[i], oid_to_hex(base_list[i]))))
3653 return err(o, _("Could not parse object '%s'"),
3654 oid_to_hex(base_list[i]));
3655 commit_list_insert(base, &ca);