@@ -506,33 +506,42 @@ impl fmt::Display for SourceId {
506
506
// The hash of SourceId is used in the name of some Cargo folders, so shouldn't
507
507
// vary. `as_str` gives the serialisation of a url (which has a spec) and so
508
508
// insulates against possible changes in how the url crate does hashing.
509
+ //
510
+ // Note that the semi-funky hashing here is done to handle `DefaultBranch`
511
+ // hashing the same as `"master"`, and also to hash the same as previous
512
+ // versions of Cargo while it's somewhat convenient to do so (that way all
513
+ // versions of Cargo use the same checkout).
509
514
impl Hash for SourceId {
510
515
fn hash < S : hash:: Hasher > ( & self , into : & mut S ) {
511
516
match & self . inner . kind {
512
517
SourceKind :: Git ( GitReference :: Tag ( a) ) => {
513
- 0u8 . hash ( into) ;
514
- a. hash ( into) ;
515
- }
516
- SourceKind :: Git ( GitReference :: Rev ( a) ) => {
517
- 1u8 . hash ( into) ;
518
+ 0usize . hash ( into) ;
519
+ 0usize . hash ( into) ;
518
520
a. hash ( into) ;
519
521
}
520
522
SourceKind :: Git ( GitReference :: Branch ( a) ) => {
521
- 2u8 . hash ( into) ;
523
+ 0usize . hash ( into) ;
524
+ 1usize . hash ( into) ;
522
525
a. hash ( into) ;
523
526
}
524
527
// For now hash `DefaultBranch` the same way as `Branch("master")`,
525
528
// and for more details see module comments in
526
529
// src/cargo/sources/git/utils.rs for why `DefaultBranch`
527
530
SourceKind :: Git ( GitReference :: DefaultBranch ) => {
528
- 2u8 . hash ( into) ;
531
+ 0usize . hash ( into) ;
532
+ 1usize . hash ( into) ;
529
533
"master" . hash ( into) ;
530
534
}
535
+ SourceKind :: Git ( GitReference :: Rev ( a) ) => {
536
+ 0usize . hash ( into) ;
537
+ 2usize . hash ( into) ;
538
+ a. hash ( into) ;
539
+ }
531
540
532
- SourceKind :: Path => 4u8 . hash ( into) ,
533
- SourceKind :: Registry => 5u8 . hash ( into) ,
534
- SourceKind :: LocalRegistry => 6u8 . hash ( into) ,
535
- SourceKind :: Directory => 7u8 . hash ( into) ,
541
+ SourceKind :: Path => 1usize . hash ( into) ,
542
+ SourceKind :: Registry => 2usize . hash ( into) ,
543
+ SourceKind :: LocalRegistry => 3usize . hash ( into) ,
544
+ SourceKind :: Directory => 4usize . hash ( into) ,
536
545
}
537
546
match self . inner . kind {
538
547
SourceKind :: Git ( _) => self . inner . canonical_url . hash ( into) ,
0 commit comments