@@ -163,9 +163,9 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
163
163
// Older versions of Cargo used the single value of the hash of the HEAD commit as a `index_version`.
164
164
// This is technically correct but a little too conservative. If a new commit is fetched all cached
165
165
// files need to be regenerated even if a particular file was not changed.
166
- // Cargo now checks the `index_version` in two parts the cache file is considered valid if `index_version`
167
- // ends with the hash of the HEAD commit OR if it starts with the hash of the file's contents.
168
- // Cargo writes the cached files with `index_version` = `git_file_hash` + ":" + `git_commit_hash` .
166
+ // However if an old cargo has written such a file we still know how to read it, as long as we check for that hash value.
167
+ //
168
+ // Cargo now uses a hash of the file's contents as provided by git .
169
169
fn load (
170
170
& mut self ,
171
171
_root : & Path ,
@@ -177,10 +177,9 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
177
177
}
178
178
// Check if the cache is valid.
179
179
let git_commit_hash = self . current_version ( ) ;
180
- if let ( Some ( i) , Some ( c) ) = ( index_version, git_commit_hash) {
181
- if i. ends_with ( c. as_str ( ) ) {
182
- return Poll :: Ready ( Ok ( LoadResponse :: CacheValid ) ) ;
183
- }
180
+ if index_version. is_some ( ) && index_version == git_commit_hash. as_deref ( ) {
181
+ // This file was written by an old version of cargo, but it is still up-to-date.
182
+ return Poll :: Ready ( Ok ( LoadResponse :: CacheValid ) ) ;
184
183
}
185
184
// Note that the index calls this method and the filesystem is locked
186
185
// in the index, so we don't need to worry about an `update_index`
@@ -189,18 +188,16 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
189
188
registry : & RemoteRegistry < ' _ > ,
190
189
path : & Path ,
191
190
index_version : Option < & str > ,
192
- git_commit_hash : Option < & str > ,
193
191
) -> CargoResult < LoadResponse > {
194
192
let repo = registry. repo ( ) ?;
195
193
let tree = registry. tree ( ) ?;
196
194
let entry = tree. get_path ( path) ;
197
195
let entry = entry?;
198
- let git_file_hash = entry. id ( ) . to_string ( ) ;
196
+ let git_file_hash = Some ( entry. id ( ) . to_string ( ) ) ;
199
197
200
- if let Some ( i) = index_version {
201
- if i. starts_with ( git_file_hash. as_str ( ) ) {
202
- return Ok ( LoadResponse :: CacheValid ) ;
203
- }
198
+ // Check if the cache is valid.
199
+ if index_version. is_some ( ) && index_version == git_file_hash. as_deref ( ) {
200
+ return Ok ( LoadResponse :: CacheValid ) ;
204
201
}
205
202
206
203
let object = entry. to_object ( repo) ?;
@@ -211,11 +208,11 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
211
208
212
209
Ok ( LoadResponse :: Data {
213
210
raw_data : blob. content ( ) . to_vec ( ) ,
214
- index_version : git_commit_hash . map ( |c| git_file_hash + c ) ,
211
+ index_version : git_file_hash,
215
212
} )
216
213
}
217
214
218
- match load_helper ( & self , path, index_version, git_commit_hash . as_deref ( ) ) {
215
+ match load_helper ( & self , path, index_version) {
219
216
Ok ( result) => Poll :: Ready ( Ok ( result) ) ,
220
217
Err ( _) if !self . updated => {
221
218
// If git returns an error and we haven't updated the repo, return
0 commit comments