@@ -42,32 +42,30 @@ impl Default for Remote {
42
42
let handle = std:: thread:: spawn ( move || -> Result < ( ) , Error > {
43
43
let mut follow = None ;
44
44
let mut redirected_base_url = None :: < String > ;
45
-
46
- // This initial value is just a place holder, it will get modified
47
- // before `client.execute` is called.
48
- let current_follow_policy = Arc :: new ( atomic:: AtomicBool :: new ( false ) ) ;
49
-
50
- let follow_policy = Arc :: clone ( & current_follow_policy) ;
45
+ let allow_redirects = Arc :: new ( atomic:: AtomicBool :: new ( false ) ) ;
51
46
52
47
// We may error while configuring, which is expected as part of the internal protocol. The error will be
53
48
// received and the sender of the request might restart us.
54
49
let client = reqwest:: blocking:: ClientBuilder :: new ( )
55
50
. connect_timeout ( std:: time:: Duration :: from_secs ( 20 ) )
56
51
. http1_title_case_headers ( )
57
- . redirect ( reqwest:: redirect:: Policy :: custom ( move |attempt| {
58
- if follow_policy. load ( atomic:: Ordering :: Relaxed ) {
59
- let curr_url = attempt. url ( ) ;
60
- let prev_urls = attempt. previous ( ) ;
52
+ . redirect ( reqwest:: redirect:: Policy :: custom ( {
53
+ let allow_redirects = allow_redirects. clone ( ) ;
54
+ move |attempt| {
55
+ if allow_redirects. load ( atomic:: Ordering :: Relaxed ) {
56
+ let curr_url = attempt. url ( ) ;
57
+ let prev_urls = attempt. previous ( ) ;
61
58
62
- match prev_urls. first ( ) {
63
- Some ( prev_url) if prev_url. host_str ( ) != curr_url. host_str ( ) => {
64
- // gix does not want to be redirected to a different host.
65
- attempt. stop ( )
59
+ match prev_urls. first ( ) {
60
+ Some ( prev_url) if prev_url. host_str ( ) != curr_url. host_str ( ) => {
61
+ // git does not want to be redirected to a different host.
62
+ attempt. stop ( )
63
+ }
64
+ _ => attempt. follow ( ) ,
66
65
}
67
- _ => attempt. follow ( ) ,
66
+ } else {
67
+ attempt. stop ( )
68
68
}
69
- } else {
70
- attempt. stop ( )
71
69
}
72
70
} ) )
73
71
. build ( ) ?;
@@ -121,12 +119,8 @@ impl Default for Remote {
121
119
}
122
120
123
121
let follow = follow. get_or_insert ( config. follow_redirects ) ;
124
-
125
- current_follow_policy. store (
126
- match * follow {
127
- FollowRedirects :: None => false ,
128
- FollowRedirects :: Initial | FollowRedirects :: All => true ,
129
- } ,
122
+ allow_redirects. store (
123
+ matches ! ( follow, FollowRedirects :: Initial | FollowRedirects :: All ) ,
130
124
atomic:: Ordering :: Relaxed ,
131
125
) ;
132
126
0 commit comments