replay: replace the_repository with repo parameter passed to cmd_replay ()
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
May 14, 2025 at 20:33 UTC
d2c3e94a0aa1755677c18b16d05b71e94c700029
1 file changed
+35
-30
builtin/replay.c
+35
-30
@@ -20,21 +20,22 @@
20
#include <oidset.h>
21
#include <tree.h>
22
23
-static const char *short_commit_name(struct commit *commit)
23
+static const char *short_commit_name(struct repository *repo,
24
+ struct commit *commit)
25
{
25
- return repo_find_unique_abbrev(the_repository, &commit->object.oid,
26
+ return repo_find_unique_abbrev(repo, &commit->object.oid,
27
DEFAULT_ABBREV);
28
}
29
29
-static struct commit *peel_committish(const char *name)
30
+static struct commit *peel_committish(struct repository *repo, const char *name)
31
{
32
struct object *obj;
33
struct object_id oid;
34
34
- if (repo_get_oid(the_repository, name, &oid))
35
+ if (repo_get_oid(repo, name, &oid))
36
return NULL;
36
- obj = parse_object(the_repository, &oid);
37
- return (struct commit *)repo_peel_to_type(the_repository, name, 0, obj,
37
+ obj = parse_object(repo, &oid);
38
+ return (struct commit *)repo_peel_to_type(repo, name, 0, obj,
39
OBJ_COMMIT);
40
}
41
@@ -50,7 +51,8 @@ static char *get_author(const char *message)
51
return NULL;
52
}
53
53
-static struct commit *create_commit(struct tree *tree,
54
+static struct commit *create_commit(struct repository *repo,
55
+ struct tree *tree,
56
struct commit *based_on,
57
struct commit *parent)
58
{
@@ -62,7 +64,7 @@ static struct commit *create_commit(struct tree *tree,
64
struct commit_extra_header *extra = NULL;
65
struct strbuf msg = STRBUF_INIT;
66
const char *out_enc = get_commit_output_encoding();
65
- const char *message = repo_logmsg_reencode(the_repository, based_on,
67
+ const char *message = repo_logmsg_reencode(repo, based_on,
68
NULL, out_enc);
69
const char *orig_message = NULL;
70
const char *exclude_gpgsig[] = { "gpgsig", NULL };
@@ -79,7 +81,7 @@ static struct commit *create_commit(struct tree *tree,
81
goto out;
82
}
83
82
- obj = parse_object(the_repository, &ret);
84
+ obj = parse_object(repo, &ret);
85
86
out:
87
free_commit_extra_headers(extra);
@@ -97,7 +99,8 @@ struct ref_info {
99
int negative_refexprs;
100
};
101
100
-static void get_ref_information(struct rev_cmdline_info *cmd_info,
102
+static void get_ref_information(struct repository *repo,
103
+ struct rev_cmdline_info *cmd_info,
104
struct ref_info *ref_info)
105
{
106
int i;
@@ -132,14 +135,14 @@ static void get_ref_information(struct rev_cmdline_info *cmd_info,
135
136
if (*refexpr == '^')
137
refexpr++;
135
- if (repo_dwim_ref(the_repository, refexpr, strlen(refexpr), &oid, &fullname, 0) != 1)
138
+ if (repo_dwim_ref(repo, refexpr, strlen(refexpr), &oid, &fullname, 0) != 1)
139
can_uniquely_dwim = 0;
140
141
if (e->flags & BOTTOM) {
142
if (can_uniquely_dwim)
143
strset_add(&ref_info->negative_refs, fullname);
144
if (!ref_info->negative_refexprs)
142
- ref_info->onto = lookup_commit_reference_gently(the_repository,
145
+ ref_info->onto = lookup_commit_reference_gently(repo,
146
&e->item->oid, 1);
147
ref_info->negative_refexprs++;
148
} else {
@@ -152,7 +155,8 @@ static void get_ref_information(struct rev_cmdline_info *cmd_info,
155
}
156
}
157
155
-static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
158
+static void determine_replay_mode(struct repository *repo,
159
+ struct rev_cmdline_info *cmd_info,
160
const char *onto_name,
161
char **advance_name,
162
struct commit **onto,
@@ -160,14 +164,14 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
164
{
165
struct ref_info rinfo;
166
163
- get_ref_information(cmd_info, &rinfo);
167
+ get_ref_information(repo, cmd_info, &rinfo);
168
if (!rinfo.positive_refexprs)
169
die(_("need some commits to replay"));
170
171
die_for_incompatible_opt2(!!onto_name, "--onto",
172
!!*advance_name, "--advance");
173
if (onto_name) {
170
- *onto = peel_committish(onto_name);
174
+ *onto = peel_committish(repo, onto_name);
175
if (rinfo.positive_refexprs <
176
strset_get_size(&rinfo.positive_refs))
177
die(_("all positive revisions given must be references"));
@@ -175,8 +179,8 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
179
struct object_id oid;
180
char *fullname = NULL;
181
178
- *onto = peel_committish(*advance_name);
179
- if (repo_dwim_ref(the_repository, *advance_name, strlen(*advance_name),
182
+ *onto = peel_committish(repo, *advance_name);
183
+ if (repo_dwim_ref(repo, *advance_name, strlen(*advance_name),
184
&oid, &fullname, 0) == 1) {
185
free(*advance_name);
186
*advance_name = fullname;
@@ -245,7 +249,8 @@ static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
249
return kh_value(replayed_commits, pos);
250
}
251
248
-static struct commit *pick_regular_commit(struct commit *pickme,
252
+static struct commit *pick_regular_commit(struct repository *repo,
253
+ struct commit *pickme,
254
kh_oid_map_t *replayed_commits,
255
struct commit *onto,
256
struct merge_options *merge_opt,
@@ -257,12 +262,12 @@ static struct commit *pick_regular_commit(struct commit *pickme,
262
base = pickme->parents->item;
263
replayed_base = mapped_commit(replayed_commits, base, onto);
264
260
- result->tree = repo_get_commit_tree(the_repository, replayed_base);
261
- pickme_tree = repo_get_commit_tree(the_repository, pickme);
262
- base_tree = repo_get_commit_tree(the_repository, base);
265
+ result->tree = repo_get_commit_tree(repo, replayed_base);
266
+ pickme_tree = repo_get_commit_tree(repo, pickme);
267
+ base_tree = repo_get_commit_tree(repo, base);
268
264
- merge_opt->branch1 = short_commit_name(replayed_base);
265
- merge_opt->branch2 = short_commit_name(pickme);
269
+ merge_opt->branch1 = short_commit_name(repo, replayed_base);
270
+ merge_opt->branch2 = short_commit_name(repo, pickme);
271
merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2);
272
273
merge_incore_nonrecursive(merge_opt,
@@ -275,13 +280,13 @@ static struct commit *pick_regular_commit(struct commit *pickme,
280
merge_opt->ancestor = NULL;
281
if (!result->clean)
282
return NULL;
278
- return create_commit(result->tree, pickme, replayed_base);
283
+ return create_commit(repo, result->tree, pickme, replayed_base);
284
}
285
286
int cmd_replay(int argc,
287
const char **argv,
288
const char *prefix,
284
- struct repository *repo UNUSED)
289
+ struct repository *repo)
290
{
291
const char *advance_name_opt = NULL;
292
char *advance_name = NULL;
@@ -329,7 +334,7 @@ int cmd_replay(int argc,
334
"--advance", "--contained");
335
advance_name = xstrdup_or_null(advance_name_opt);
336
332
- repo_init_revisions(the_repository, &revs, prefix);
337
+ repo_init_revisions(repo, &revs, prefix);
338
339
/*
340
* Set desired values for rev walking options here. If they
@@ -380,7 +385,7 @@ int cmd_replay(int argc,
385
revs.simplify_history = 0;
386
}
387
383
- determine_replay_mode(&revs.cmdline, onto_name, &advance_name,
388
+ determine_replay_mode(repo, &revs.cmdline, onto_name, &advance_name,
389
&onto, &update_refs);
390
391
if (!onto) /* FIXME: Should handle replaying down to root commit */
@@ -391,7 +396,7 @@ int cmd_replay(int argc,
396
goto cleanup;
397
}
398
394
- init_basic_merge_options(&merge_opt, the_repository);
399
+ init_basic_merge_options(&merge_opt, repo);
400
memset(&result, 0, sizeof(result));
401
merge_opt.show_rename_progress = 0;
402
last_commit = onto;
@@ -406,8 +411,8 @@ int cmd_replay(int argc,
411
if (commit->parents->next)
412
die(_("replaying merge commits is not supported yet!"));
413
409
- last_commit = pick_regular_commit(commit, replayed_commits, onto,
410
- &merge_opt, &result);
414
+ last_commit = pick_regular_commit(repo, commit, replayed_commits,
415
+ onto, &merge_opt, &result);
416
if (!last_commit)
417
break;
418