From 858c012d10429b2e91b12d299b2f18752c70b4bb Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 15 Sep 2023 15:40:55 +0800 Subject: [PATCH] refactor: rename `SourceId:for_alt_registry` to `for_named_registry` --- src/cargo/core/source_id.rs | 10 +++++----- src/cargo/sources/config.rs | 4 ++-- src/cargo/util/credential/paseto.rs | 2 +- src/cargo/util/credential/token.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cargo/core/source_id.rs b/src/cargo/core/source_id.rs index 76b60dac8a52..e62ee21c57d2 100644 --- a/src/cargo/core/source_id.rs +++ b/src/cargo/core/source_id.rs @@ -218,7 +218,7 @@ 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 { let kind = Self::remote_source_kind(url); @@ -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 { + pub fn for_named_registry(url: &Url, name: &str) -> CargoResult { let kind = Self::remote_source_kind(url); SourceId::new(kind, url.to_owned(), Some(name)) } @@ -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. @@ -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"); @@ -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"); diff --git a/src/cargo/sources/config.rs b/src/cargo/sources/config.rs index f0c214e16d6f..1e9e39157122 100644 --- a/src/cargo/sources/config.rs +++ b/src/cargo/sources/config.rs @@ -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, }, )?; @@ -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(®istry, &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); diff --git a/src/cargo/util/credential/paseto.rs b/src/cargo/util/credential/paseto.rs index bd49af98acdc..8f7bdd8673f3 100644 --- a/src/cargo/util/credential/paseto.rs +++ b/src/cargo/util/credential/paseto.rs @@ -65,7 +65,7 @@ impl<'a> Credential for PasetoCredential<'a> { ) -> Result { 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) }?; diff --git a/src/cargo/util/credential/token.rs b/src/cargo/util/credential/token.rs index 7a29e6360d9f..3b012610d586 100644 --- a/src/cargo/util/credential/token.rs +++ b/src/cargo/util/credential/token.rs @@ -30,7 +30,7 @@ impl<'a> Credential for TokenCredential<'a> { ) -> Result { 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) }?;