All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>, Elijah Newren <newren@gmail.com>
Subject: [PATCH] replay: replace the_repository with repo parameter passed to cmd_replay()
Date: Wed, 14 May 2025 20:33:25 +0000	[thread overview]
Message-ID: <pull.1921.git.1747254806067.gitgitgadget@gmail.com> (raw)

From: Elijah Newren <newren@gmail.com>

Replace the_repository everywhere with repo, feed repo from cmd_replay()
to all the other functions in the file that need it, and remove the
UNUSED annotation on repo.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
    replay: replace the_repository with repo parameter passed to cmd_replay
    
    The point of this patch is not to remove USE_THE_REPOSITORY_VARIABLE; I
    can't yet because DEFAULT_ABBREV and get_commit_output_encoding() both
    require it and have no current alternatives. However, I still think it's
    worthwhile to stop using the_repository everywhere while ignoring the
    repo parameter explicitly passed in. That looks kinda ugly, and since
    I'm poking around in replay right now, I don't want to push
    the_repository in even more places when we have the appropriate value
    available -- especially since that might make my local work conflict
    should someone else come along and try to clean this up.
    
    --color-words is handy when viewing this patch; it may make it easier to
    see the changes.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1921%2Fnewren%2Freplay-repo-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1921/newren/replay-repo-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1921

 builtin/replay.c | 65 ++++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 30 deletions(-)

diff --git a/builtin/replay.c b/builtin/replay.c
index 032c172b65e..225cef08807 100644
--- a/builtin/replay.c
+++ b/builtin/replay.c
@@ -20,21 +20,22 @@
 #include <oidset.h>
 #include <tree.h>
 
-static const char *short_commit_name(struct commit *commit)
+static const char *short_commit_name(struct repository *repo,
+				     struct commit *commit)
 {
-	return repo_find_unique_abbrev(the_repository, &commit->object.oid,
+	return repo_find_unique_abbrev(repo, &commit->object.oid,
 				       DEFAULT_ABBREV);
 }
 
-static struct commit *peel_committish(const char *name)
+static struct commit *peel_committish(struct repository *repo, const char *name)
 {
 	struct object *obj;
 	struct object_id oid;
 
-	if (repo_get_oid(the_repository, name, &oid))
+	if (repo_get_oid(repo, name, &oid))
 		return NULL;
-	obj = parse_object(the_repository, &oid);
-	return (struct commit *)repo_peel_to_type(the_repository, name, 0, obj,
+	obj = parse_object(repo, &oid);
+	return (struct commit *)repo_peel_to_type(repo, name, 0, obj,
 						  OBJ_COMMIT);
 }
 
@@ -50,7 +51,8 @@ static char *get_author(const char *message)
 	return NULL;
 }
 
-static struct commit *create_commit(struct tree *tree,
+static struct commit *create_commit(struct repository *repo,
+				    struct tree *tree,
 				    struct commit *based_on,
 				    struct commit *parent)
 {
@@ -62,7 +64,7 @@ static struct commit *create_commit(struct tree *tree,
 	struct commit_extra_header *extra = NULL;
 	struct strbuf msg = STRBUF_INIT;
 	const char *out_enc = get_commit_output_encoding();
-	const char *message = repo_logmsg_reencode(the_repository, based_on,
+	const char *message = repo_logmsg_reencode(repo, based_on,
 						   NULL, out_enc);
 	const char *orig_message = NULL;
 	const char *exclude_gpgsig[] = { "gpgsig", NULL };
@@ -79,7 +81,7 @@ static struct commit *create_commit(struct tree *tree,
 		goto out;
 	}
 
-	obj = parse_object(the_repository, &ret);
+	obj = parse_object(repo, &ret);
 
 out:
 	free_commit_extra_headers(extra);
@@ -97,7 +99,8 @@ struct ref_info {
 	int negative_refexprs;
 };
 
-static void get_ref_information(struct rev_cmdline_info *cmd_info,
+static void get_ref_information(struct repository *repo,
+				struct rev_cmdline_info *cmd_info,
 				struct ref_info *ref_info)
 {
 	int i;
@@ -132,14 +135,14 @@ static void get_ref_information(struct rev_cmdline_info *cmd_info,
 
 		if (*refexpr == '^')
 			refexpr++;
-		if (repo_dwim_ref(the_repository, refexpr, strlen(refexpr), &oid, &fullname, 0) != 1)
+		if (repo_dwim_ref(repo, refexpr, strlen(refexpr), &oid, &fullname, 0) != 1)
 			can_uniquely_dwim = 0;
 
 		if (e->flags & BOTTOM) {
 			if (can_uniquely_dwim)
 				strset_add(&ref_info->negative_refs, fullname);
 			if (!ref_info->negative_refexprs)
-				ref_info->onto = lookup_commit_reference_gently(the_repository,
+				ref_info->onto = lookup_commit_reference_gently(repo,
 										&e->item->oid, 1);
 			ref_info->negative_refexprs++;
 		} else {
@@ -152,7 +155,8 @@ static void get_ref_information(struct rev_cmdline_info *cmd_info,
 	}
 }
 
-static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
+static void determine_replay_mode(struct repository *repo,
+				  struct rev_cmdline_info *cmd_info,
 				  const char *onto_name,
 				  char **advance_name,
 				  struct commit **onto,
@@ -160,14 +164,14 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
 {
 	struct ref_info rinfo;
 
-	get_ref_information(cmd_info, &rinfo);
+	get_ref_information(repo, cmd_info, &rinfo);
 	if (!rinfo.positive_refexprs)
 		die(_("need some commits to replay"));
 
 	die_for_incompatible_opt2(!!onto_name, "--onto",
 				  !!*advance_name, "--advance");
 	if (onto_name) {
-		*onto = peel_committish(onto_name);
+		*onto = peel_committish(repo, onto_name);
 		if (rinfo.positive_refexprs <
 		    strset_get_size(&rinfo.positive_refs))
 			die(_("all positive revisions given must be references"));
@@ -175,8 +179,8 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
 		struct object_id oid;
 		char *fullname = NULL;
 
-		*onto = peel_committish(*advance_name);
-		if (repo_dwim_ref(the_repository, *advance_name, strlen(*advance_name),
+		*onto = peel_committish(repo, *advance_name);
+		if (repo_dwim_ref(repo, *advance_name, strlen(*advance_name),
 			     &oid, &fullname, 0) == 1) {
 			free(*advance_name);
 			*advance_name = fullname;
@@ -245,7 +249,8 @@ static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
 	return kh_value(replayed_commits, pos);
 }
 
-static struct commit *pick_regular_commit(struct commit *pickme,
+static struct commit *pick_regular_commit(struct repository *repo,
+					  struct commit *pickme,
 					  kh_oid_map_t *replayed_commits,
 					  struct commit *onto,
 					  struct merge_options *merge_opt,
@@ -257,12 +262,12 @@ static struct commit *pick_regular_commit(struct commit *pickme,
 	base = pickme->parents->item;
 	replayed_base = mapped_commit(replayed_commits, base, onto);
 
-	result->tree = repo_get_commit_tree(the_repository, replayed_base);
-	pickme_tree = repo_get_commit_tree(the_repository, pickme);
-	base_tree = repo_get_commit_tree(the_repository, base);
+	result->tree = repo_get_commit_tree(repo, replayed_base);
+	pickme_tree = repo_get_commit_tree(repo, pickme);
+	base_tree = repo_get_commit_tree(repo, base);
 
-	merge_opt->branch1 = short_commit_name(replayed_base);
-	merge_opt->branch2 = short_commit_name(pickme);
+	merge_opt->branch1 = short_commit_name(repo, replayed_base);
+	merge_opt->branch2 = short_commit_name(repo, pickme);
 	merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2);
 
 	merge_incore_nonrecursive(merge_opt,
@@ -275,13 +280,13 @@ static struct commit *pick_regular_commit(struct commit *pickme,
 	merge_opt->ancestor = NULL;
 	if (!result->clean)
 		return NULL;
-	return create_commit(result->tree, pickme, replayed_base);
+	return create_commit(repo, result->tree, pickme, replayed_base);
 }
 
 int cmd_replay(int argc,
 	       const char **argv,
 	       const char *prefix,
-	       struct repository *repo UNUSED)
+	       struct repository *repo)
 {
 	const char *advance_name_opt = NULL;
 	char *advance_name = NULL;
@@ -329,7 +334,7 @@ int cmd_replay(int argc,
 		    "--advance", "--contained");
 	advance_name = xstrdup_or_null(advance_name_opt);
 
-	repo_init_revisions(the_repository, &revs, prefix);
+	repo_init_revisions(repo, &revs, prefix);
 
 	/*
 	 * Set desired values for rev walking options here. If they
@@ -380,7 +385,7 @@ int cmd_replay(int argc,
 		revs.simplify_history = 0;
 	}
 
-	determine_replay_mode(&revs.cmdline, onto_name, &advance_name,
+	determine_replay_mode(repo, &revs.cmdline, onto_name, &advance_name,
 			      &onto, &update_refs);
 
 	if (!onto) /* FIXME: Should handle replaying down to root commit */
@@ -391,7 +396,7 @@ int cmd_replay(int argc,
 		goto cleanup;
 	}
 
-	init_basic_merge_options(&merge_opt, the_repository);
+	init_basic_merge_options(&merge_opt, repo);
 	memset(&result, 0, sizeof(result));
 	merge_opt.show_rename_progress = 0;
 	last_commit = onto;
@@ -406,8 +411,8 @@ int cmd_replay(int argc,
 		if (commit->parents->next)
 			die(_("replaying merge commits is not supported yet!"));
 
-		last_commit = pick_regular_commit(commit, replayed_commits, onto,
-						  &merge_opt, &result);
+		last_commit = pick_regular_commit(repo, commit, replayed_commits,
+						  onto, &merge_opt, &result);
 		if (!last_commit)
 			break;
 

base-commit: 1a8a4971cc6c179c4dd711f4a7f5d7178f4b3ab7
-- 
gitgitgadget

             reply	other threads:[~2025-05-14 20:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-14 20:33 Elijah Newren via GitGitGadget [this message]
2025-05-14 22:10 ` [PATCH] replay: replace the_repository with repo parameter passed to cmd_replay() Junio C Hamano
2025-05-15 13:24 ` Patrick Steinhardt

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

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

  git send-email \
    --in-reply-to=pull.1921.git.1747254806067.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=newren@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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.