@@ -20,7 +20,6 @@ pub struct GitSource<'cfg> {
2020 path_source : Option < PathSource < ' cfg > > ,
2121 ident : String ,
2222 config : & ' cfg Config ,
23- updated : bool ,
2423}
2524
2625impl < ' cfg > GitSource < ' cfg > {
@@ -43,7 +42,6 @@ impl<'cfg> GitSource<'cfg> {
4342 path_source : None ,
4443 ident,
4544 config,
46- updated : false ,
4745 } ;
4846
4947 Ok ( source)
@@ -55,13 +53,72 @@ impl<'cfg> GitSource<'cfg> {
5553
5654 pub fn read_packages ( & mut self ) -> CargoResult < Vec < Package > > {
5755 if self . path_source . is_none ( ) {
58- self . update ( ) ?;
56+ self . invalidate_cache ( ) ;
57+ self . block_until_ready ( ) ?;
5958 }
6059 self . path_source . as_mut ( ) . unwrap ( ) . read_packages ( )
6160 }
61+ }
62+
63+ fn ident ( id : & SourceId ) -> String {
64+ let ident = id
65+ . canonical_url ( )
66+ . raw_canonicalized_url ( )
67+ . path_segments ( )
68+ . and_then ( |s| s. rev ( ) . next ( ) )
69+ . unwrap_or ( "" ) ;
70+
71+ let ident = if ident. is_empty ( ) { "_empty" } else { ident } ;
72+
73+ format ! ( "{}-{}" , ident, short_hash( id. canonical_url( ) ) )
74+ }
6275
63- fn update ( & mut self ) -> CargoResult < ( ) > {
64- if self . updated {
76+ impl < ' cfg > Debug for GitSource < ' cfg > {
77+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
78+ write ! ( f, "git repo at {}" , self . remote. url( ) ) ?;
79+
80+ match self . manifest_reference . pretty_ref ( ) {
81+ Some ( s) => write ! ( f, " ({})" , s) ,
82+ None => Ok ( ( ) ) ,
83+ }
84+ }
85+ }
86+
87+ impl < ' cfg > Source for GitSource < ' cfg > {
88+ fn query ( & mut self , dep : & Dependency , f : & mut dyn FnMut ( Summary ) ) -> Poll < CargoResult < ( ) > > {
89+ if let Some ( src) = self . path_source . as_mut ( ) {
90+ src. query ( dep, f)
91+ } else {
92+ Poll :: Pending
93+ }
94+ }
95+
96+ fn fuzzy_query (
97+ & mut self ,
98+ dep : & Dependency ,
99+ f : & mut dyn FnMut ( Summary ) ,
100+ ) -> Poll < CargoResult < ( ) > > {
101+ if let Some ( src) = self . path_source . as_mut ( ) {
102+ src. fuzzy_query ( dep, f)
103+ } else {
104+ Poll :: Pending
105+ }
106+ }
107+
108+ fn supports_checksums ( & self ) -> bool {
109+ false
110+ }
111+
112+ fn requires_precise ( & self ) -> bool {
113+ true
114+ }
115+
116+ fn source_id ( & self ) -> SourceId {
117+ self . source_id
118+ }
119+
120+ fn block_until_ready ( & mut self ) -> CargoResult < ( ) > {
121+ if self . path_source . is_some ( ) {
65122 return Ok ( ( ) ) ;
66123 }
67124
@@ -92,10 +149,10 @@ impl<'cfg> GitSource<'cfg> {
92149 // doesn't have it.
93150 ( locked_rev, db) => {
94151 if self . config . offline ( ) {
95- return Err ( anyhow:: anyhow !(
152+ anyhow:: bail !(
96153 "can't checkout from '{}': you are in the offline mode (--offline)" ,
97154 self . remote. url( )
98- ) ) ;
155+ ) ;
99156 }
100157 self . config . shell ( ) . status (
101158 "Updating" ,
@@ -133,67 +190,7 @@ impl<'cfg> GitSource<'cfg> {
133190
134191 self . path_source = Some ( path_source) ;
135192 self . locked_rev = Some ( actual_rev) ;
136- self . path_source . as_mut ( ) . unwrap ( ) . update ( ) ?;
137- self . updated = true ;
138- Ok ( ( ) )
139- }
140- }
141-
142- fn ident ( id : & SourceId ) -> String {
143- let ident = id
144- . canonical_url ( )
145- . raw_canonicalized_url ( )
146- . path_segments ( )
147- . and_then ( |s| s. rev ( ) . next ( ) )
148- . unwrap_or ( "" ) ;
149-
150- let ident = if ident. is_empty ( ) { "_empty" } else { ident } ;
151-
152- format ! ( "{}-{}" , ident, short_hash( id. canonical_url( ) ) )
153- }
154-
155- impl < ' cfg > Debug for GitSource < ' cfg > {
156- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
157- write ! ( f, "git repo at {}" , self . remote. url( ) ) ?;
158-
159- match self . manifest_reference . pretty_ref ( ) {
160- Some ( s) => write ! ( f, " ({})" , s) ,
161- None => Ok ( ( ) ) ,
162- }
163- }
164- }
165-
166- impl < ' cfg > Source for GitSource < ' cfg > {
167- fn query ( & mut self , dep : & Dependency , f : & mut dyn FnMut ( Summary ) ) -> Poll < CargoResult < ( ) > > {
168- if let Some ( src) = self . path_source . as_mut ( ) {
169- src. query ( dep, f)
170- } else {
171- Poll :: Pending
172- }
173- }
174-
175- fn fuzzy_query (
176- & mut self ,
177- dep : & Dependency ,
178- f : & mut dyn FnMut ( Summary ) ,
179- ) -> Poll < CargoResult < ( ) > > {
180- if let Some ( src) = self . path_source . as_mut ( ) {
181- src. fuzzy_query ( dep, f)
182- } else {
183- Poll :: Pending
184- }
185- }
186-
187- fn supports_checksums ( & self ) -> bool {
188- false
189- }
190-
191- fn requires_precise ( & self ) -> bool {
192- true
193- }
194-
195- fn source_id ( & self ) -> SourceId {
196- self . source_id
193+ self . path_source . as_mut ( ) . unwrap ( ) . update ( )
197194 }
198195
199196 fn download ( & mut self , id : PackageId ) -> CargoResult < MaybePackage > {
@@ -226,13 +223,7 @@ impl<'cfg> Source for GitSource<'cfg> {
226223 Ok ( false )
227224 }
228225
229- fn block_until_ready ( & mut self ) -> CargoResult < ( ) > {
230- self . update ( )
231- }
232-
233- fn invalidate_cache ( & mut self ) {
234- self . updated = false ;
235- }
226+ fn invalidate_cache ( & mut self ) { }
236227}
237228
238229#[ cfg( test) ]
0 commit comments