@@ -483,7 +483,9 @@ static int valid_remote_nick(const char *name)
483
483
return 1 ;
484
484
}
485
485
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 )
487
489
{
488
490
if (branch && branch -> remote_name ) {
489
491
if (explicit )
@@ -495,32 +497,55 @@ const char *remote_for_branch(struct branch *branch, int *explicit)
495
497
return "origin" ;
496
498
}
497
499
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 )
499
510
{
500
511
if (branch && branch -> pushremote_name ) {
501
512
if (explicit )
502
513
* explicit = 1 ;
503
514
return branch -> pushremote_name ;
504
515
}
505
- if (the_repository -> remote_state -> pushremote_name ) {
516
+ if (remote_state -> pushremote_name ) {
506
517
if (explicit )
507
518
* explicit = 1 ;
508
- return the_repository -> remote_state -> pushremote_name ;
519
+ return remote_state -> pushremote_name ;
509
520
}
510
- return remote_for_branch ( branch , explicit );
521
+ return remotes_remote_for_branch ( remote_state , branch , explicit );
511
522
}
512
523
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
+
513
534
const char * remote_ref_for_branch (struct branch * branch , int for_push )
514
535
{
536
+ read_config (the_repository );
515
537
if (branch ) {
516
538
if (!for_push ) {
517
539
if (branch -> merge_nr ) {
518
540
return branch -> merge_name [0 ];
519
541
}
520
542
} 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 );
524
549
525
550
if (remote && remote -> push .nr &&
526
551
(dst = apply_refspecs (& remote -> push ,
@@ -532,42 +557,58 @@ const char *remote_ref_for_branch(struct branch *branch, int for_push)
532
557
return NULL ;
533
558
}
534
559
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 * ))
537
564
{
538
565
struct remote * ret ;
539
566
int name_given = 0 ;
540
567
541
- read_config (the_repository );
542
-
543
568
if (name )
544
569
name_given = 1 ;
545
570
else
546
- name = get_default (the_repository -> remote_state -> current_branch ,
571
+ name = get_default (remote_state , remote_state -> current_branch ,
547
572
& name_given );
548
573
549
- ret = make_remote (the_repository -> remote_state , name , 0 );
574
+ ret = make_remote (remote_state , name , 0 );
550
575
if (valid_remote_nick (name ) && have_git_dir ()) {
551
576
if (!valid_remote (ret ))
552
- read_remotes_file (the_repository -> remote_state , ret );
577
+ read_remotes_file (remote_state , ret );
553
578
if (!valid_remote (ret ))
554
- read_branches_file (the_repository -> remote_state , ret );
579
+ read_branches_file (remote_state , ret );
555
580
}
556
581
if (name_given && !valid_remote (ret ))
557
- add_url_alias (the_repository -> remote_state , ret , name );
582
+ add_url_alias (remote_state , ret , name );
558
583
if (!valid_remote (ret ))
559
584
return NULL ;
560
585
return ret ;
561
586
}
562
587
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
+
563
595
struct remote * remote_get (const char * name )
564
596
{
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 );
566
606
}
567
607
568
608
struct remote * pushremote_get (const char * name )
569
609
{
570
- return remote_get_1 (name , pushremote_for_branch );
610
+ read_config (the_repository );
611
+ return remotes_pushremote_get (the_repository -> remote_state , name );
571
612
}
572
613
573
614
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,
1654
1695
}
1655
1696
}
1656
1697
1657
- static void set_merge (struct branch * ret )
1698
+ static void set_merge (struct remote_state * remote_state , struct branch * ret )
1658
1699
{
1659
1700
struct remote * remote ;
1660
1701
char * ref ;
@@ -1674,7 +1715,7 @@ static void set_merge(struct branch *ret)
1674
1715
return ;
1675
1716
}
1676
1717
1677
- remote = remote_get ( ret -> remote_name );
1718
+ remote = remotes_remote_get ( remote_state , ret -> remote_name );
1678
1719
1679
1720
CALLOC_ARRAY (ret -> merge , ret -> merge_nr );
1680
1721
for (i = 0 ; i < ret -> merge_nr ; i ++ ) {
@@ -1701,7 +1742,7 @@ struct branch *branch_get(const char *name)
1701
1742
else
1702
1743
ret = make_branch (the_repository -> remote_state , name ,
1703
1744
strlen (name ));
1704
- set_merge (ret );
1745
+ set_merge (the_repository -> remote_state , ret );
1705
1746
return ret ;
1706
1747
}
1707
1748
@@ -1772,11 +1813,14 @@ static const char *tracking_for_push_dest(struct remote *remote,
1772
1813
return ret ;
1773
1814
}
1774
1815
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 )
1776
1818
{
1777
1819
struct remote * remote ;
1778
1820
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 ));
1780
1824
if (!remote )
1781
1825
return error_buf (err ,
1782
1826
_ ("branch '%s' has no remote for pushing" ),
@@ -1834,11 +1878,13 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
1834
1878
1835
1879
const char * branch_get_push (struct branch * branch , struct strbuf * err )
1836
1880
{
1881
+ read_config (the_repository );
1837
1882
if (!branch )
1838
1883
return error_buf (err , _ ("HEAD does not point to a branch" ));
1839
1884
1840
1885
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 );
1842
1888
return branch -> push_tracking_ref ;
1843
1889
}
1844
1890
0 commit comments