Skip to content

Commit e7751e0

Browse files
committed
Merge branch 'ua/some-builtins-wo-the-repository' into jch
* 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 6a6bd24 + b6e37a7 commit e7751e0

16 files changed

+112
-62
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 repository *repo, 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(repo->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 < repo->index->cache_nr) {
84+
struct cache_entry *ce =repo->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 repository *repo, 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 < repo->index->cache_nr ; i++) {
145+
struct cache_entry *ce = repo->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(repo->index);
159+
ce = repo->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, 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, 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, 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: 18 additions & 17 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"
@@ -234,7 +233,8 @@ static void show_submodule(struct repository *superproject,
234233
{
235234
struct repository subrepo;
236235

237-
if (repo_submodule_init(&subrepo, superproject, path, null_oid(the_hash_algo)))
236+
if (repo_submodule_init(&subrepo, superproject, path,
237+
null_oid(superproject->hash_algo)))
238238
return;
239239

240240
if (repo_read_index(&subrepo) < 0)
@@ -245,12 +245,13 @@ static void show_submodule(struct repository *superproject,
245245
repo_clear(&subrepo);
246246
}
247247

248-
static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
248+
static void expand_objectsize(struct repository *repo, struct strbuf *line,
249+
const struct object_id *oid,
249250
const enum object_type type, unsigned int padded)
250251
{
251252
if (type == OBJ_BLOB) {
252253
unsigned long size;
253-
if (oid_object_info(the_repository, oid, &size) < 0)
254+
if (oid_object_info(repo, oid, &size) < 0)
254255
die(_("could not get object info about '%s'"),
255256
oid_to_hex(oid));
256257
if (padded)
@@ -283,10 +284,10 @@ static void show_ce_fmt(struct repository *repo, const struct cache_entry *ce,
283284
else if (skip_prefix(format, "(objecttype)", &format))
284285
strbuf_addstr(&sb, type_name(object_type(ce->ce_mode)));
285286
else if (skip_prefix(format, "(objectsize:padded)", &format))
286-
expand_objectsize(&sb, &ce->oid,
287+
expand_objectsize(repo, &sb, &ce->oid,
287288
object_type(ce->ce_mode), 1);
288289
else if (skip_prefix(format, "(objectsize)", &format))
289-
expand_objectsize(&sb, &ce->oid,
290+
expand_objectsize(repo, &sb, &ce->oid,
290291
object_type(ce->ce_mode), 0);
291292
else if (skip_prefix(format, "(stage)", &format))
292293
strbuf_addf(&sb, "%d", ce_stage(ce));
@@ -348,7 +349,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
348349
}
349350
}
350351

351-
static void show_ru_info(struct index_state *istate)
352+
static void show_ru_info(struct repository *repo, struct index_state *istate)
352353
{
353354
struct string_list_item *item;
354355

@@ -370,7 +371,7 @@ static void show_ru_info(struct index_state *istate)
370371
if (!ui->mode[i])
371372
continue;
372373
printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
373-
repo_find_unique_abbrev(the_repository, &ui->oid[i], abbrev),
374+
repo_find_unique_abbrev(repo, &ui->oid[i], abbrev),
374375
i + 1);
375376
write_name(path);
376377
}
@@ -567,7 +568,7 @@ static int option_parse_exclude_standard(const struct option *opt,
567568
int cmd_ls_files(int argc,
568569
const char **argv,
569570
const char *cmd_prefix,
570-
struct repository *repo UNUSED)
571+
struct repository *repo)
571572
{
572573
int require_work_tree = 0, show_tag = 0, i;
573574
char *max_prefix;
@@ -647,15 +648,15 @@ int cmd_ls_files(int argc,
647648
show_usage_with_options_if_asked(argc, argv,
648649
ls_files_usage, builtin_ls_files_options);
649650

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

653654
prefix = cmd_prefix;
654655
if (prefix)
655656
prefix_len = strlen(prefix);
656-
git_config(git_default_config, NULL);
657+
repo_config(repo, git_default_config, NULL);
657658

658-
if (repo_read_index(the_repository) < 0)
659+
if (repo_read_index(repo) < 0)
659660
die("index file corrupt");
660661

661662
argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
@@ -724,7 +725,7 @@ int cmd_ls_files(int argc,
724725
max_prefix = common_prefix(&pathspec);
725726
max_prefix_len = get_common_prefix_len(max_prefix);
726727

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

729730
/* Treat unmatching pathspec elements as errors */
730731
if (pathspec.nr && error_unmatch)
@@ -748,13 +749,13 @@ int cmd_ls_files(int argc,
748749
*/
749750
if (show_stage || show_unmerged)
750751
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);
752+
overlay_tree_on_index(repo->index, with_tree, max_prefix);
752753
}
753754

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

756757
if (show_resolve_undo)
757-
show_ru_info(the_repository->index);
758+
show_ru_info(repo, repo->index);
758759

759760
if (ps_matched && report_path_error(ps_matched, &pathspec)) {
760761
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);

0 commit comments

Comments
 (0)