git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Martin Ågren" <martin.agren@gmail.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 09/11] merge-recursive.c: remove implicit dependency on the_repository
Date: Sat, 12 Jan 2019 09:13:30 +0700	[thread overview]
Message-ID: <20190112021332.11066-10-pclouds@gmail.com> (raw)
In-Reply-To: <20190112021332.11066-1-pclouds@gmail.com>

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 merge-recursive.c | 45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index 28f44c73ec..a596d95739 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -146,7 +146,8 @@ static int err(struct merge_options *o, const char *err, ...)
 	return -1;
 }
 
-static struct tree *shift_tree_object(struct tree *one, struct tree *two,
+static struct tree *shift_tree_object(struct repository *repo,
+				      struct tree *one, struct tree *two,
 				      const char *subtree_shift)
 {
 	struct object_id shifted;
@@ -159,12 +160,14 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
 	}
 	if (oideq(&two->object.oid, &shifted))
 		return two;
-	return lookup_tree(the_repository, &shifted);
+	return lookup_tree(repo, &shifted);
 }
 
-static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
+static struct commit *make_virtual_commit(struct repository *repo,
+					  struct tree *tree,
+					  const char *comment)
 {
-	struct commit *commit = alloc_commit_node(the_repository);
+	struct commit *commit = alloc_commit_node(repo);
 
 	set_merge_remote_desc(commit, comment, (struct object *)commit);
 	commit->maybe_tree = tree;
@@ -445,7 +448,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
 		return NULL;
 	}
 
-	result = lookup_tree(the_repository, &istate->cache_tree->oid);
+	result = lookup_tree(o->repo, &istate->cache_tree->oid);
 
 	return result;
 }
@@ -1208,9 +1211,9 @@ static int merge_submodule(struct merge_options *o,
 		return 0;
 	}
 
-	if (!(commit_base = lookup_commit_reference(the_repository, base)) ||
-	    !(commit_a = lookup_commit_reference(the_repository, a)) ||
-	    !(commit_b = lookup_commit_reference(the_repository, b))) {
+	if (!(commit_base = lookup_commit_reference(o->repo, base)) ||
+	    !(commit_a = lookup_commit_reference(o->repo, a)) ||
+	    !(commit_b = lookup_commit_reference(o->repo, b))) {
 		output(o, 1, _("Failed to merge submodule %s (commits not present)"), path);
 		return 0;
 	}
@@ -3416,8 +3419,8 @@ int merge_trees(struct merge_options *o,
 	}
 
 	if (o->subtree_shift) {
-		merge = shift_tree_object(head, merge, o->subtree_shift);
-		common = shift_tree_object(head, common, o->subtree_shift);
+		merge = shift_tree_object(o->repo, head, merge, o->subtree_shift);
+		common = shift_tree_object(o->repo, head, common, o->subtree_shift);
 	}
 
 	if (oid_eq(&common->object.oid, &merge->object.oid)) {
@@ -3553,8 +3556,8 @@ int merge_recursive(struct merge_options *o,
 		/* if there is no common ancestor, use an empty tree */
 		struct tree *tree;
 
-		tree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
-		merged_common_ancestors = make_virtual_commit(tree, "ancestor");
+		tree = lookup_tree(o->repo, o->repo->hash_algo->empty_tree);
+		merged_common_ancestors = make_virtual_commit(o->repo, tree, "ancestor");
 	}
 
 	for (iter = ca; iter; iter = iter->next) {
@@ -3598,7 +3601,7 @@ int merge_recursive(struct merge_options *o,
 	}
 
 	if (o->call_depth) {
-		*result = make_virtual_commit(mrtree, "merged tree");
+		*result = make_virtual_commit(o->repo, mrtree, "merged tree");
 		commit_list_insert(h1, &(*result)->parents);
 		commit_list_insert(h2, &(*result)->parents->next);
 	}
@@ -3611,17 +3614,17 @@ int merge_recursive(struct merge_options *o,
 	return clean;
 }
 
-static struct commit *get_ref(const struct object_id *oid, const char *name)
+static struct commit *get_ref(struct repository *repo, const struct object_id *oid,
+			      const char *name)
 {
 	struct object *object;
 
-	object = deref_tag(the_repository, parse_object(the_repository, oid),
-			   name,
-			   strlen(name));
+	object = deref_tag(repo, parse_object(repo, oid),
+			   name, strlen(name));
 	if (!object)
 		return NULL;
 	if (object->type == OBJ_TREE)
-		return make_virtual_commit((struct tree*)object, name);
+		return make_virtual_commit(repo, (struct tree*)object, name);
 	if (object->type != OBJ_COMMIT)
 		return NULL;
 	if (parse_commit((struct commit *)object))
@@ -3638,15 +3641,15 @@ int merge_recursive_generic(struct merge_options *o,
 {
 	int clean;
 	struct lock_file lock = LOCK_INIT;
-	struct commit *head_commit = get_ref(head, o->branch1);
-	struct commit *next_commit = get_ref(merge, o->branch2);
+	struct commit *head_commit = get_ref(o->repo, head, o->branch1);
+	struct commit *next_commit = get_ref(o->repo, merge, o->branch2);
 	struct commit_list *ca = NULL;
 
 	if (base_list) {
 		int i;
 		for (i = 0; i < num_base_list; ++i) {
 			struct commit *base;
-			if (!(base = get_ref(base_list[i], oid_to_hex(base_list[i]))))
+			if (!(base = get_ref(o->repo, base_list[i], oid_to_hex(base_list[i]))))
 				return err(o, _("Could not parse object '%s'"),
 					   oid_to_hex(base_list[i]));
 			commit_list_insert(base, &ca);
-- 
2.20.0.482.g66447595a7


  parent reply	other threads:[~2019-01-12  2:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-05  5:51 [PATCH 00/10] Remove the_index, the final part Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 01/10] notes-utils.c: remove the_repository references Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 02/10] repository.c: replace hold_locked_index() with repo_hold_locked_index() Nguyễn Thái Ngọc Duy
2019-01-05 14:33   ` Martin Ågren
2019-01-07 12:55     ` Duy Nguyen
2019-01-05  5:51 ` [PATCH 03/10] checkout: avoid the_index when possible Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 04/10] read-cache.c: kill read_index() Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 05/10] read-cache.c: replace update_index_if_able with repo_& Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 06/10] sha1-name.c: remove implicit dependency on the_index Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 07/10] merge-recursive.c: " Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 08/10] merge-recursive.c: remove implicit dependency on the_repository Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 09/10] read-cache.c: remove the_* from index_has_changes() Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 10/10] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch Nguyễn Thái Ngọc Duy
2019-01-12  2:13 ` [PATCH v2 00/11] Remove the_index, the final part Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 01/11] grep: use grep_opt->repo instead of explict repo argument Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 02/11] notes-utils.c: remove the_repository references Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 03/11] repository.c: replace hold_locked_index() with repo_hold_locked_index() Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 04/11] checkout: avoid the_index when possible Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 05/11] read-cache.c: kill read_index() Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 06/11] read-cache.c: replace update_index_if_able with repo_& Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 07/11] sha1-name.c: remove implicit dependency on the_index Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 08/11] merge-recursive.c: " Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` Nguyễn Thái Ngọc Duy [this message]
2019-01-12  2:13   ` [PATCH v2 10/11] read-cache.c: remove the_* from index_has_changes() Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 11/11] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190112021332.11066-10-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=martin.agren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).