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 d6c7b20 commit 858c012
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ impl SourceId {
/// Creates a SourceId from a remote registry URL when the registry name
/// cannot be determined, e.g. a user passes `--index` directly from CLI.
///
/// Use [`SourceId::for_alt_registry`] if a name can provided, which
/// Use [`SourceId::for_named_registry`] if a name can provided, which
/// generates better messages for cargo.
pub fn for_registry(url: &Url) -> CargoResult<SourceId> {
let kind = Self::remote_source_kind(url);
SourceId::new(kind, url.to_owned(), None)
}

/// 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 @@ -288,7 +288,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 @@ -926,7 +926,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 @@ -936,7 +936,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/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 858c012

Please sign in to comment.