Skip to content

Commit 1a764cd

Browse files
committed
Merge branch 'ua/some-builtins-wo-the-repository'
A handful of built-in command implementations have been rewritten to use the repository instance supplied by git.c:run_builtin(), its caller. * ua/some-builtins-wo-the-repository: builtin/checkout-index: stop using `the_repository` builtin/for-each-ref: stop using `the_repository` builtin/ls-files: stop using `the_repository` builtin/pack-refs: stop using `the_repository` builtin/send-pack: stop using `the_repository` builtin/verify-commit: stop using `the_repository` builtin/verify-tag: stop using `the_repository` config: teach repo_config to allow `repo` to be NULL
2 parents def5e32 + 09cbf15 commit 1a764cd

16 files changed

+116
-61
lines changed

builtin/checkout-index.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*
66
*/
77

8-
#define USE_THE_REPOSITORY_VARIABLE
98
#define DISABLE_SIGN_COMPARE_WARNINGS
109

1110
#include "builtin.h"
@@ -68,10 +67,10 @@ static void write_tempfile_record(const char *name, const char *prefix)
6867
}
6968
}
7069

71-
static int checkout_file(const char *name, const char *prefix)
70+
static int checkout_file(struct index_state *index, const char *name, const char *prefix)
7271
{
7372
int namelen = strlen(name);
74-
int pos = index_name_pos(the_repository->index, name, namelen);
73+
int pos = index_name_pos(index, name, namelen);
7574
int has_same_name = 0;
7675
int is_file = 0;
7776
int is_skipped = 1;
@@ -81,8 +80,8 @@ static int checkout_file(const char *name, const char *prefix)
8180
if (pos < 0)
8281
pos = -pos - 1;
8382

84-
while (pos <the_repository->index->cache_nr) {
85-
struct cache_entry *ce =the_repository->index->cache[pos];
83+
while (pos < index->cache_nr) {
84+
struct cache_entry *ce = index->cache[pos];
8685
if (ce_namelen(ce) != namelen ||
8786
memcmp(ce->name, name, namelen))
8887
break;
@@ -137,13 +136,13 @@ static int checkout_file(const char *name, const char *prefix)
137136
return -1;
138137
}
139138

140-
static int checkout_all(const char *prefix, int prefix_length)
139+
static int checkout_all(struct index_state *index, const char *prefix, int prefix_length)
141140
{
142141
int i, errs = 0;
143142
struct cache_entry *last_ce = NULL;
144143

145-
for (i = 0; i < the_repository->index->cache_nr ; i++) {
146-
struct cache_entry *ce = the_repository->index->cache[i];
144+
for (i = 0; i < index->cache_nr ; i++) {
145+
struct cache_entry *ce = index->cache[i];
147146

148147
if (S_ISSPARSEDIR(ce->ce_mode)) {
149148
if (!ce_skip_worktree(ce))
@@ -156,8 +155,8 @@ static int checkout_all(const char *prefix, int prefix_length)
156155
* first entry inside the expanded sparse directory).
157156
*/
158157
if (ignore_skip_worktree) {
159-
ensure_full_index(the_repository->index);
160-
ce = the_repository->index->cache[i];
158+
ensure_full_index(index);
159+
ce = index->cache[i];
161160
}
162161
}
163162

@@ -213,7 +212,7 @@ static int option_parse_stage(const struct option *opt,
213212
int cmd_checkout_index(int argc,
214213
const char **argv,
215214
const char *prefix,
216-
struct repository *repo UNUSED)
215+
struct repository *repo)
217216
{
218217
int i;
219218
struct lock_file lock_file = LOCK_INIT;
@@ -253,19 +252,19 @@ int cmd_checkout_index(int argc,
253252
show_usage_with_options_if_asked(argc, argv,
254253
builtin_checkout_index_usage,
255254
builtin_checkout_index_options);
256-
git_config(git_default_config, NULL);
255+
repo_config(repo, git_default_config, NULL);
257256
prefix_length = prefix ? strlen(prefix) : 0;
258257

259-
prepare_repo_settings(the_repository);
260-
the_repository->settings.command_requires_full_index = 0;
258+
prepare_repo_settings(repo);
259+
repo->settings.command_requires_full_index = 0;
261260

262-
if (repo_read_index(the_repository) < 0) {
261+
if (repo_read_index(repo) < 0) {
263262
die("invalid cache");
264263
}
265264

266265
argc = parse_options(argc, argv, prefix, builtin_checkout_index_options,
267266
builtin_checkout_index_usage, 0);
268-
state.istate = the_repository->index;
267+
state.istate = repo->index;
269268
state.force = force;
270269
state.quiet = quiet;
271270
state.not_new = not_new;
@@ -285,8 +284,8 @@ int cmd_checkout_index(int argc,
285284
*/
286285
if (index_opt && !state.base_dir_len && !to_tempfile) {
287286
state.refresh_cache = 1;
288-
state.istate = the_repository->index;
289-
repo_hold_locked_index(the_repository, &lock_file,
287+
state.istate = repo->index;
288+
repo_hold_locked_index(repo, &lock_file,
290289
LOCK_DIE_ON_ERROR);
291290
}
292291

@@ -304,7 +303,7 @@ int cmd_checkout_index(int argc,
304303
if (read_from_stdin)
305304
die("git checkout-index: don't mix '--stdin' and explicit filenames");
306305
p = prefix_path(prefix, prefix_length, arg);
307-
err |= checkout_file(p, prefix);
306+
err |= checkout_file(repo->index, p, prefix);
308307
free(p);
309308
}
310309

@@ -326,15 +325,15 @@ int cmd_checkout_index(int argc,
326325
strbuf_swap(&buf, &unquoted);
327326
}
328327
p = prefix_path(prefix, prefix_length, buf.buf);
329-
err |= checkout_file(p, prefix);
328+
err |= checkout_file(repo->index, p, prefix);
330329
free(p);
331330
}
332331
strbuf_release(&unquoted);
333332
strbuf_release(&buf);
334333
}
335334

336335
if (all)
337-
err |= checkout_all(prefix, prefix_length);
336+
err |= checkout_all(repo->index, prefix, prefix_length);
338337

339338
if (pc_workers > 1)
340339
err |= run_parallel_checkout(&state, pc_workers, pc_threshold,
@@ -344,7 +343,7 @@ int cmd_checkout_index(int argc,
344343
return 1;
345344

346345
if (is_lock_file_locked(&lock_file) &&
347-
write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
346+
write_locked_index(repo->index, &lock_file, COMMIT_LOCK))
348347
die("Unable to write new index file");
349348
return 0;
350349
}

builtin/for-each-ref.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#include "builtin.h"
32
#include "commit.h"
43
#include "config.h"
@@ -20,7 +19,7 @@ static char const * const for_each_ref_usage[] = {
2019
int cmd_for_each_ref(int argc,
2120
const char **argv,
2221
const char *prefix,
23-
struct repository *repo UNUSED)
22+
struct repository *repo)
2423
{
2524
struct ref_sorting *sorting;
2625
struct string_list sorting_options = STRING_LIST_INIT_DUP;
@@ -63,7 +62,7 @@ int cmd_for_each_ref(int argc,
6362

6463
format.format = "%(objectname) %(objecttype)\t%(refname)";
6564

66-
git_config(git_default_config, NULL);
65+
repo_config(repo, git_default_config, NULL);
6766

6867
/* Set default (refname) sorting */
6968
string_list_append(&sorting_options, "refname");

builtin/ls-files.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* Copyright (C) Linus Torvalds, 2005
77
*/
88

9-
#define USE_THE_REPOSITORY_VARIABLE
109
#define DISABLE_SIGN_COMPARE_WARNINGS
1110

1211
#include "builtin.h"
@@ -245,12 +244,13 @@ static void show_submodule(struct repository *superproject,
245244
repo_clear(&subrepo);
246245
}
247246

248-
static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
247+
static void expand_objectsize(struct repository *repo, struct strbuf *line,
248+
const struct object_id *oid,
249249
const enum object_type type, unsigned int padded)
250250
{
251251
if (type == OBJ_BLOB) {
252252
unsigned long size;
253-
if (oid_object_info(the_repository, oid, &size) < 0)
253+
if (oid_object_info(repo, oid, &size) < 0)
254254
die(_("could not get object info about '%s'"),
255255
oid_to_hex(oid));
256256
if (padded)
@@ -283,10 +283,10 @@ static void show_ce_fmt(struct repository *repo, const struct cache_entry *ce,
283283
else if (skip_prefix(format, "(objecttype)", &format))
284284
strbuf_addstr(&sb, type_name(object_type(ce->ce_mode)));
285285
else if (skip_prefix(format, "(objectsize:padded)", &format))
286-
expand_objectsize(&sb, &ce->oid,
286+
expand_objectsize(repo, &sb, &ce->oid,
287287
object_type(ce->ce_mode), 1);
288288
else if (skip_prefix(format, "(objectsize)", &format))
289-
expand_objectsize(&sb, &ce->oid,
289+
expand_objectsize(repo, &sb, &ce->oid,
290290
object_type(ce->ce_mode), 0);
291291
else if (skip_prefix(format, "(stage)", &format))
292292
strbuf_addf(&sb, "%d", ce_stage(ce));
@@ -348,7 +348,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
348348
}
349349
}
350350

351-
static void show_ru_info(struct index_state *istate)
351+
static void show_ru_info(struct repository *repo, struct index_state *istate)
352352
{
353353
struct string_list_item *item;
354354

@@ -370,7 +370,7 @@ static void show_ru_info(struct index_state *istate)
370370
if (!ui->mode[i])
371371
continue;
372372
printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
373-
repo_find_unique_abbrev(the_repository, &ui->oid[i], abbrev),
373+
repo_find_unique_abbrev(repo, &ui->oid[i], abbrev),
374374
i + 1);
375375
write_name(path);
376376
}
@@ -567,7 +567,7 @@ static int option_parse_exclude_standard(const struct option *opt,
567567
int cmd_ls_files(int argc,
568568
const char **argv,
569569
const char *cmd_prefix,
570-
struct repository *repo UNUSED)
570+
struct repository *repo)
571571
{
572572
int require_work_tree = 0, show_tag = 0, i;
573573
char *max_prefix;
@@ -647,15 +647,15 @@ int cmd_ls_files(int argc,
647647
show_usage_with_options_if_asked(argc, argv,
648648
ls_files_usage, builtin_ls_files_options);
649649

650-
prepare_repo_settings(the_repository);
651-
the_repository->settings.command_requires_full_index = 0;
650+
prepare_repo_settings(repo);
651+
repo->settings.command_requires_full_index = 0;
652652

653653
prefix = cmd_prefix;
654654
if (prefix)
655655
prefix_len = strlen(prefix);
656-
git_config(git_default_config, NULL);
656+
repo_config(repo, git_default_config, NULL);
657657

658-
if (repo_read_index(the_repository) < 0)
658+
if (repo_read_index(repo) < 0)
659659
die("index file corrupt");
660660

661661
argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
@@ -724,7 +724,7 @@ int cmd_ls_files(int argc,
724724
max_prefix = common_prefix(&pathspec);
725725
max_prefix_len = get_common_prefix_len(max_prefix);
726726

727-
prune_index(the_repository->index, max_prefix, max_prefix_len);
727+
prune_index(repo->index, max_prefix, max_prefix_len);
728728

729729
/* Treat unmatching pathspec elements as errors */
730730
if (pathspec.nr && error_unmatch)
@@ -748,13 +748,13 @@ int cmd_ls_files(int argc,
748748
*/
749749
if (show_stage || show_unmerged)
750750
die(_("options '%s' and '%s' cannot be used together"), "ls-files --with-tree", "-s/-u");
751-
overlay_tree_on_index(the_repository->index, with_tree, max_prefix);
751+
overlay_tree_on_index(repo->index, with_tree, max_prefix);
752752
}
753753

754-
show_files(the_repository, &dir);
754+
show_files(repo, &dir);
755755

756756
if (show_resolve_undo)
757-
show_ru_info(the_repository->index);
757+
show_ru_info(repo, repo->index);
758758

759759
if (ps_matched && report_path_error(ps_matched, &pathspec)) {
760760
fprintf(stderr, "Did you forget to 'git add'?\n");

builtin/pack-refs.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "builtin.h"
42
#include "config.h"
53
#include "gettext.h"
@@ -15,7 +13,7 @@ static char const * const pack_refs_usage[] = {
1513
int cmd_pack_refs(int argc,
1614
const char **argv,
1715
const char *prefix,
18-
struct repository *repo UNUSED)
16+
struct repository *repo)
1917
{
2018
struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
2119
struct string_list included_refs = STRING_LIST_INIT_NODUP;
@@ -39,7 +37,7 @@ int cmd_pack_refs(int argc,
3937
N_("references to exclude")),
4038
OPT_END(),
4139
};
42-
git_config(git_default_config, NULL);
40+
repo_config(repo, git_default_config, NULL);
4341
if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
4442
usage_with_options(pack_refs_usage, opts);
4543

@@ -52,7 +50,7 @@ int cmd_pack_refs(int argc,
5250
if (!pack_refs_opts.includes->nr)
5351
string_list_append(pack_refs_opts.includes, "refs/tags/*");
5452

55-
ret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);
53+
ret = refs_pack_refs(get_main_ref_store(repo), &pack_refs_opts);
5654

5755
clear_ref_exclusions(&excludes);
5856
string_list_clear(&included_refs, 0);

builtin/send-pack.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#include "builtin.h"
32
#include "config.h"
43
#include "hex.h"
@@ -151,7 +150,7 @@ static int send_pack_config(const char *k, const char *v,
151150
int cmd_send_pack(int argc,
152151
const char **argv,
153152
const char *prefix,
154-
struct repository *repo UNUSED)
153+
struct repository *repo)
155154
{
156155
struct refspec rs = REFSPEC_INIT_PUSH;
157156
const char *remote_name = NULL;
@@ -212,7 +211,7 @@ int cmd_send_pack(int argc,
212211
OPT_END()
213212
};
214213

215-
git_config(send_pack_config, NULL);
214+
repo_config(repo, send_pack_config, NULL);
216215
argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);
217216
if (argc > 0) {
218217
dest = argv[0];
@@ -317,7 +316,7 @@ int cmd_send_pack(int argc,
317316
set_ref_status_for_push(remote_refs, args.send_mirror,
318317
args.force_update);
319318

320-
ret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have);
319+
ret = send_pack(repo, &args, fd, conn, remote_refs, &extra_have);
321320

322321
if (helper_status)
323322
print_helper_status(remote_refs);

builtin/verify-commit.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*
66
* Based on git-verify-tag
77
*/
8-
#define USE_THE_REPOSITORY_VARIABLE
98
#include "builtin.h"
109
#include "config.h"
1110
#include "gettext.h"
@@ -33,15 +32,15 @@ static int run_gpg_verify(struct commit *commit, unsigned flags)
3332
return ret;
3433
}
3534

36-
static int verify_commit(const char *name, unsigned flags)
35+
static int verify_commit(struct repository *repo, const char *name, unsigned flags)
3736
{
3837
struct object_id oid;
3938
struct object *obj;
4039

41-
if (repo_get_oid(the_repository, name, &oid))
40+
if (repo_get_oid(repo, name, &oid))
4241
return error("commit '%s' not found.", name);
4342

44-
obj = parse_object(the_repository, &oid);
43+
obj = parse_object(repo, &oid);
4544
if (!obj)
4645
return error("%s: unable to read file.", name);
4746
if (obj->type != OBJ_COMMIT)
@@ -54,7 +53,7 @@ static int verify_commit(const char *name, unsigned flags)
5453
int cmd_verify_commit(int argc,
5554
const char **argv,
5655
const char *prefix,
57-
struct repository *repo UNUSED)
56+
struct repository *repo)
5857
{
5958
int i = 1, verbose = 0, had_error = 0;
6059
unsigned flags = 0;
@@ -64,7 +63,7 @@ int cmd_verify_commit(int argc,
6463
OPT_END()
6564
};
6665

67-
git_config(git_default_config, NULL);
66+
repo_config(repo, git_default_config, NULL);
6867

6968
argc = parse_options(argc, argv, prefix, verify_commit_options,
7069
verify_commit_usage, PARSE_OPT_KEEP_ARGV0);
@@ -78,7 +77,7 @@ int cmd_verify_commit(int argc,
7877
* was received in the process of writing the gpg input: */
7978
signal(SIGPIPE, SIG_IGN);
8079
while (i < argc)
81-
if (verify_commit(argv[i++], flags))
80+
if (verify_commit(repo, argv[i++], flags))
8281
had_error = 1;
8382
return had_error;
8483
}

0 commit comments

Comments
 (0)