Skip to content

Commit 56eed34

Browse files
chooglengitster
authored andcommitted
remote: remove the_repository->remote_state from static methods
Replace all remaining references of the_repository->remote_state in static functions with a struct remote_state parameter. To do so, move read_config() calls to non-static functions and create a family of static functions, "remotes_*", that behave like "repo_*", but accept struct remote_state instead of struct repository. In the case where a static function calls a non-static function, replace the non-static function with its "remotes_*" equivalent. Signed-off-by: Glen Choo <[email protected]> Reviewed-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 085b98f commit 56eed34

File tree

1 file changed

+71
-25
lines changed

1 file changed

+71
-25
lines changed

remote.c

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,9 @@ static int valid_remote_nick(const char *name)
483483
return 1;
484484
}
485485

486-
const char *remote_for_branch(struct branch *branch, int *explicit)
486+
static const char *remotes_remote_for_branch(struct remote_state *remote_state,
487+
struct branch *branch,
488+
int *explicit)
487489
{
488490
if (branch && branch->remote_name) {
489491
if (explicit)
@@ -495,32 +497,55 @@ const char *remote_for_branch(struct branch *branch, int *explicit)
495497
return "origin";
496498
}
497499

498-
const char *pushremote_for_branch(struct branch *branch, int *explicit)
500+
const char *remote_for_branch(struct branch *branch, int *explicit)
501+
{
502+
read_config(the_repository);
503+
return remotes_remote_for_branch(the_repository->remote_state, branch,
504+
explicit);
505+
}
506+
507+
static const char *
508+
remotes_pushremote_for_branch(struct remote_state *remote_state,
509+
struct branch *branch, int *explicit)
499510
{
500511
if (branch && branch->pushremote_name) {
501512
if (explicit)
502513
*explicit = 1;
503514
return branch->pushremote_name;
504515
}
505-
if (the_repository->remote_state->pushremote_name) {
516+
if (remote_state->pushremote_name) {
506517
if (explicit)
507518
*explicit = 1;
508-
return the_repository->remote_state->pushremote_name;
519+
return remote_state->pushremote_name;
509520
}
510-
return remote_for_branch(branch, explicit);
521+
return remotes_remote_for_branch(remote_state, branch, explicit);
511522
}
512523

524+
const char *pushremote_for_branch(struct branch *branch, int *explicit)
525+
{
526+
read_config(the_repository);
527+
return remotes_pushremote_for_branch(the_repository->remote_state,
528+
branch, explicit);
529+
}
530+
531+
static struct remote *remotes_remote_get(struct remote_state *remote_state,
532+
const char *name);
533+
513534
const char *remote_ref_for_branch(struct branch *branch, int for_push)
514535
{
536+
read_config(the_repository);
515537
if (branch) {
516538
if (!for_push) {
517539
if (branch->merge_nr) {
518540
return branch->merge_name[0];
519541
}
520542
} else {
521-
const char *dst, *remote_name =
522-
pushremote_for_branch(branch, NULL);
523-
struct remote *remote = remote_get(remote_name);
543+
const char *dst,
544+
*remote_name = remotes_pushremote_for_branch(
545+
the_repository->remote_state, branch,
546+
NULL);
547+
struct remote *remote = remotes_remote_get(
548+
the_repository->remote_state, remote_name);
524549

525550
if (remote && remote->push.nr &&
526551
(dst = apply_refspecs(&remote->push,
@@ -532,42 +557,58 @@ const char *remote_ref_for_branch(struct branch *branch, int for_push)
532557
return NULL;
533558
}
534559

535-
static struct remote *remote_get_1(const char *name,
536-
const char *(*get_default)(struct branch *, int *))
560+
static struct remote *
561+
remotes_remote_get_1(struct remote_state *remote_state, const char *name,
562+
const char *(*get_default)(struct remote_state *,
563+
struct branch *, int *))
537564
{
538565
struct remote *ret;
539566
int name_given = 0;
540567

541-
read_config(the_repository);
542-
543568
if (name)
544569
name_given = 1;
545570
else
546-
name = get_default(the_repository->remote_state->current_branch,
571+
name = get_default(remote_state, remote_state->current_branch,
547572
&name_given);
548573

549-
ret = make_remote(the_repository->remote_state, name, 0);
574+
ret = make_remote(remote_state, name, 0);
550575
if (valid_remote_nick(name) && have_git_dir()) {
551576
if (!valid_remote(ret))
552-
read_remotes_file(the_repository->remote_state, ret);
577+
read_remotes_file(remote_state, ret);
553578
if (!valid_remote(ret))
554-
read_branches_file(the_repository->remote_state, ret);
579+
read_branches_file(remote_state, ret);
555580
}
556581
if (name_given && !valid_remote(ret))
557-
add_url_alias(the_repository->remote_state, ret, name);
582+
add_url_alias(remote_state, ret, name);
558583
if (!valid_remote(ret))
559584
return NULL;
560585
return ret;
561586
}
562587

588+
static inline struct remote *
589+
remotes_remote_get(struct remote_state *remote_state, const char *name)
590+
{
591+
return remotes_remote_get_1(remote_state, name,
592+
remotes_remote_for_branch);
593+
}
594+
563595
struct remote *remote_get(const char *name)
564596
{
565-
return remote_get_1(name, remote_for_branch);
597+
read_config(the_repository);
598+
return remotes_remote_get(the_repository->remote_state, name);
599+
}
600+
601+
static inline struct remote *
602+
remotes_pushremote_get(struct remote_state *remote_state, const char *name)
603+
{
604+
return remotes_remote_get_1(remote_state, name,
605+
remotes_pushremote_for_branch);
566606
}
567607

568608
struct remote *pushremote_get(const char *name)
569609
{
570-
return remote_get_1(name, pushremote_for_branch);
610+
read_config(the_repository);
611+
return remotes_pushremote_get(the_repository->remote_state, name);
571612
}
572613

573614
int remote_is_configured(struct remote *remote, int in_repo)
@@ -1654,7 +1695,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
16541695
}
16551696
}
16561697

1657-
static void set_merge(struct branch *ret)
1698+
static void set_merge(struct remote_state *remote_state, struct branch *ret)
16581699
{
16591700
struct remote *remote;
16601701
char *ref;
@@ -1674,7 +1715,7 @@ static void set_merge(struct branch *ret)
16741715
return;
16751716
}
16761717

1677-
remote = remote_get(ret->remote_name);
1718+
remote = remotes_remote_get(remote_state, ret->remote_name);
16781719

16791720
CALLOC_ARRAY(ret->merge, ret->merge_nr);
16801721
for (i = 0; i < ret->merge_nr; i++) {
@@ -1701,7 +1742,7 @@ struct branch *branch_get(const char *name)
17011742
else
17021743
ret = make_branch(the_repository->remote_state, name,
17031744
strlen(name));
1704-
set_merge(ret);
1745+
set_merge(the_repository->remote_state, ret);
17051746
return ret;
17061747
}
17071748

@@ -1772,11 +1813,14 @@ static const char *tracking_for_push_dest(struct remote *remote,
17721813
return ret;
17731814
}
17741815

1775-
static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
1816+
static const char *branch_get_push_1(struct remote_state *remote_state,
1817+
struct branch *branch, struct strbuf *err)
17761818
{
17771819
struct remote *remote;
17781820

1779-
remote = remote_get(pushremote_for_branch(branch, NULL));
1821+
remote = remotes_remote_get(
1822+
remote_state,
1823+
remotes_pushremote_for_branch(remote_state, branch, NULL));
17801824
if (!remote)
17811825
return error_buf(err,
17821826
_("branch '%s' has no remote for pushing"),
@@ -1834,11 +1878,13 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
18341878

18351879
const char *branch_get_push(struct branch *branch, struct strbuf *err)
18361880
{
1881+
read_config(the_repository);
18371882
if (!branch)
18381883
return error_buf(err, _("HEAD does not point to a branch"));
18391884

18401885
if (!branch->push_tracking_ref)
1841-
branch->push_tracking_ref = branch_get_push_1(branch, err);
1886+
branch->push_tracking_ref = branch_get_push_1(
1887+
the_repository->remote_state, branch, err);
18421888
return branch->push_tracking_ref;
18431889
}
18441890

0 commit comments

Comments
 (0)