Skip to content

Commit

Permalink
refactor: rename SourceId:for_alt_registry to for_named_registry
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Sep 15, 2023
1 parent 69e6fea commit 6c3933f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl SourceId {
}

/// Creates a `SourceId` from a remote registry URL with given name.
pub fn for_alt_registry(url: &Url, name: &str) -> CargoResult<SourceId> {
pub fn for_named_registry(url: &Url, name: &str) -> CargoResult<SourceId> {
let kind = Self::remote_source_kind(url);
SourceId::new(kind, url.to_owned(), Some(name))
}
Expand Down Expand Up @@ -284,7 +284,7 @@ impl SourceId {
return Self::crates_io(config);
}
let url = config.get_registry_index(key)?;
Self::for_alt_registry(&url, key)
Self::for_named_registry(&url, key)
}

/// Gets this source URL.
Expand Down Expand Up @@ -922,7 +922,7 @@ mod tests {
assert_eq!(crate::util::hex::short_hash(&source_id), "fb60813d6cb8df79");

let url = "https://your-crates.io".into_url().unwrap();
let source_id = SourceId::for_alt_registry(&url, "alt").unwrap();
let source_id = SourceId::for_named_registry(&url, "alt").unwrap();
assert_eq!(gen_hash(source_id), 12862859764592646184);
assert_eq!(crate::util::hex::short_hash(&source_id), "09c10fd0cbd74bce");

Expand All @@ -932,7 +932,7 @@ mod tests {
assert_eq!(crate::util::hex::short_hash(&source_id), "d1ea0d96f6f759b5");

let url = "sparse+https://your-crates.io".into_url().unwrap();
let source_id = SourceId::for_alt_registry(&url, "alt").unwrap();
let source_id = SourceId::for_named_registry(&url, "alt").unwrap();
assert_eq!(gen_hash(source_id), 5159702466575482972);
assert_eq!(crate::util::hex::short_hash(&source_id), "135d23074253cb78");

Expand Down
4 changes: 2 additions & 2 deletions src/cargo/sources/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
base.add(
CRATES_IO_REGISTRY,
SourceConfig {
id: SourceId::for_alt_registry(&url.parse()?, CRATES_IO_REGISTRY)?,
id: SourceId::for_named_registry(&url.parse()?, CRATES_IO_REGISTRY)?,
replace_with: None,
},
)?;
Expand Down Expand Up @@ -239,7 +239,7 @@ restore the source replacement configuration to continue the build
let mut srcs = Vec::new();
if let Some(registry) = def.registry {
let url = url(&registry, &format!("source.{}.registry", name))?;
srcs.push(SourceId::for_alt_registry(&url, &name)?);
srcs.push(SourceId::for_named_registry(&url, &name)?);
}
if let Some(local_registry) = def.local_registry {
let path = local_registry.resolve_path(self.config);
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,7 @@ impl Config {
let source_id = self.crates_io_source_id.try_borrow_with(|| {
self.check_registry_index_not_set()?;
let url = CRATES_IO_INDEX.into_url().unwrap();
SourceId::for_alt_registry(&url, CRATES_IO_REGISTRY)
SourceId::for_named_registry(&url, CRATES_IO_REGISTRY)
})?;
Ok(*source_id)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/credential/paseto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'a> Credential for PasetoCredential<'a> {
) -> Result<CredentialResponse, Error> {
let index_url = Url::parse(registry.index_url).context("parsing index url")?;
let sid = if let Some(name) = registry.name {
SourceId::for_alt_registry(&index_url, name)
SourceId::for_named_registry(&index_url, name)
} else {
SourceId::for_registry(&index_url)
}?;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/credential/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> Credential for TokenCredential<'a> {
) -> Result<CredentialResponse, Error> {
let index_url = Url::parse(registry.index_url).context("parsing index url")?;
let sid = if let Some(name) = registry.name {
SourceId::for_alt_registry(&index_url, name)
SourceId::for_named_registry(&index_url, name)
} else {
SourceId::for_registry(&index_url)
}?;
Expand Down

0 comments on commit 6c3933f

Please sign in to comment.