Skip to content

Commit 2d5c238

Browse files
committed
Auto merge of #8573 - alexcrichton:hash-same, r=ehuss
Use the same index location on nightly as beta Closes #8572
2 parents c4e93dc + 6f29fb7 commit 2d5c238

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/cargo/core/source/source_id.rs

+20-11
Original file line numberDiff line numberDiff line change
@@ -506,33 +506,42 @@ impl fmt::Display for SourceId {
506506
// The hash of SourceId is used in the name of some Cargo folders, so shouldn't
507507
// vary. `as_str` gives the serialisation of a url (which has a spec) and so
508508
// 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).
509514
impl Hash for SourceId {
510515
fn hash<S: hash::Hasher>(&self, into: &mut S) {
511516
match &self.inner.kind {
512517
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);
518520
a.hash(into);
519521
}
520522
SourceKind::Git(GitReference::Branch(a)) => {
521-
2u8.hash(into);
523+
0usize.hash(into);
524+
1usize.hash(into);
522525
a.hash(into);
523526
}
524527
// For now hash `DefaultBranch` the same way as `Branch("master")`,
525528
// and for more details see module comments in
526529
// src/cargo/sources/git/utils.rs for why `DefaultBranch`
527530
SourceKind::Git(GitReference::DefaultBranch) => {
528-
2u8.hash(into);
531+
0usize.hash(into);
532+
1usize.hash(into);
529533
"master".hash(into);
530534
}
535+
SourceKind::Git(GitReference::Rev(a)) => {
536+
0usize.hash(into);
537+
2usize.hash(into);
538+
a.hash(into);
539+
}
531540

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),
536545
}
537546
match self.inner.kind {
538547
SourceKind::Git(_) => self.inner.canonical_url.hash(into),

0 commit comments

Comments
 (0)