mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #7048 - jeremystucki:into_url, r=Eh2406
Rename to_url → into_url I think it should be `into_url` as it consumes itself. [Relevant clippy lint](https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention)
This commit is contained in:
commit
eebd1da3a8
@ -9,7 +9,7 @@ use cargo::core::resolver::{self, Method};
|
|||||||
use cargo::core::source::{GitReference, SourceId};
|
use cargo::core::source::{GitReference, SourceId};
|
||||||
use cargo::core::Resolve;
|
use cargo::core::Resolve;
|
||||||
use cargo::core::{Dependency, PackageId, Registry, Summary};
|
use cargo::core::{Dependency, PackageId, Registry, Summary};
|
||||||
use cargo::util::{CargoResult, Config, Graph, ToUrl};
|
use cargo::util::{CargoResult, Config, Graph, IntoUrl};
|
||||||
|
|
||||||
use proptest::collection::{btree_map, vec};
|
use proptest::collection::{btree_map, vec};
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
@ -504,7 +504,7 @@ macro_rules! pkg {
|
|||||||
fn registry_loc() -> SourceId {
|
fn registry_loc() -> SourceId {
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref EXAMPLE_DOT_COM: SourceId =
|
static ref EXAMPLE_DOT_COM: SourceId =
|
||||||
SourceId::for_registry(&"https://example.com".to_url().unwrap()).unwrap();
|
SourceId::for_registry(&"https://example.com".into_url().unwrap()).unwrap();
|
||||||
}
|
}
|
||||||
*EXAMPLE_DOT_COM
|
*EXAMPLE_DOT_COM
|
||||||
}
|
}
|
||||||
@ -535,7 +535,7 @@ pub fn pkg_id(name: &str) -> PackageId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn pkg_id_loc(name: &str, loc: &str) -> PackageId {
|
fn pkg_id_loc(name: &str, loc: &str) -> PackageId {
|
||||||
let remote = loc.to_url();
|
let remote = loc.into_url();
|
||||||
let master = GitReference::Branch("master".to_string());
|
let master = GitReference::Branch("master".to_string());
|
||||||
let source_id = SourceId::for_git(&remote.unwrap(), master).unwrap();
|
let source_id = SourceId::for_git(&remote.unwrap(), master).unwrap();
|
||||||
|
|
||||||
@ -586,7 +586,7 @@ pub fn dep_req_kind(name: &str, req: &str, kind: Kind, public: bool) -> Dependen
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn dep_loc(name: &str, location: &str) -> Dependency {
|
pub fn dep_loc(name: &str, location: &str) -> Dependency {
|
||||||
let url = location.to_url().unwrap();
|
let url = location.into_url().unwrap();
|
||||||
let master = GitReference::Branch("master".to_string());
|
let master = GitReference::Branch("master".to_string());
|
||||||
let source_id = SourceId::for_git(&url, master).unwrap();
|
let source_id = SourceId::for_git(&url, master).unwrap();
|
||||||
Dependency::parse_no_deprecated(name, Some("1.0.0"), source_id).unwrap()
|
Dependency::parse_no_deprecated(name, Some("1.0.0"), source_id).unwrap()
|
||||||
|
@ -2,7 +2,7 @@ use crate::command_prelude::*;
|
|||||||
|
|
||||||
use cargo::core::{GitReference, Source, SourceId};
|
use cargo::core::{GitReference, Source, SourceId};
|
||||||
use cargo::sources::GitSource;
|
use cargo::sources::GitSource;
|
||||||
use cargo::util::ToUrl;
|
use cargo::util::IntoUrl;
|
||||||
|
|
||||||
pub fn cli() -> App {
|
pub fn cli() -> App {
|
||||||
subcommand("git-checkout")
|
subcommand("git-checkout")
|
||||||
@ -23,7 +23,7 @@ pub fn cli() -> App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
|
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
|
||||||
let url = args.value_of("url").unwrap().to_url()?;
|
let url = args.value_of("url").unwrap().into_url()?;
|
||||||
let reference = args.value_of("reference").unwrap();
|
let reference = args.value_of("reference").unwrap();
|
||||||
|
|
||||||
let reference = GitReference::Branch(reference.to_string());
|
let reference = GitReference::Branch(reference.to_string());
|
||||||
|
@ -2,7 +2,7 @@ use crate::command_prelude::*;
|
|||||||
|
|
||||||
use cargo::core::{GitReference, SourceId};
|
use cargo::core::{GitReference, SourceId};
|
||||||
use cargo::ops;
|
use cargo::ops;
|
||||||
use cargo::util::ToUrl;
|
use cargo::util::IntoUrl;
|
||||||
|
|
||||||
pub fn cli() -> App {
|
pub fn cli() -> App {
|
||||||
subcommand("install")
|
subcommand("install")
|
||||||
@ -127,7 +127,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
|
|||||||
let mut from_cwd = false;
|
let mut from_cwd = false;
|
||||||
|
|
||||||
let source = if let Some(url) = args.value_of("git") {
|
let source = if let Some(url) = args.value_of("git") {
|
||||||
let url = url.to_url()?;
|
let url = url.into_url()?;
|
||||||
let gitref = if let Some(branch) = args.value_of("branch") {
|
let gitref = if let Some(branch) = args.value_of("branch") {
|
||||||
GitReference::Branch(branch.to_string())
|
GitReference::Branch(branch.to_string())
|
||||||
} else if let Some(tag) = args.value_of("tag") {
|
} else if let Some(tag) = args.value_of("tag") {
|
||||||
|
@ -59,7 +59,7 @@ impl ser::Serialize for PackageId {
|
|||||||
"{} {} ({})",
|
"{} {} ({})",
|
||||||
self.inner.name,
|
self.inner.name,
|
||||||
self.inner.version,
|
self.inner.version,
|
||||||
self.inner.source_id.to_url()
|
self.inner.source_id.into_url()
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,11 +205,11 @@ mod tests {
|
|||||||
use super::PackageId;
|
use super::PackageId;
|
||||||
use crate::core::source::SourceId;
|
use crate::core::source::SourceId;
|
||||||
use crate::sources::CRATES_IO_INDEX;
|
use crate::sources::CRATES_IO_INDEX;
|
||||||
use crate::util::ToUrl;
|
use crate::util::IntoUrl;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_version_handled_nicely() {
|
fn invalid_version_handled_nicely() {
|
||||||
let loc = CRATES_IO_INDEX.to_url().unwrap();
|
let loc = CRATES_IO_INDEX.into_url().unwrap();
|
||||||
let repo = SourceId::for_registry(&loc).unwrap();
|
let repo = SourceId::for_registry(&loc).unwrap();
|
||||||
|
|
||||||
assert!(PackageId::new("foo", "1.0", repo).is_err());
|
assert!(PackageId::new("foo", "1.0", repo).is_err());
|
||||||
@ -220,7 +220,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn debug() {
|
fn debug() {
|
||||||
let loc = CRATES_IO_INDEX.to_url().unwrap();
|
let loc = CRATES_IO_INDEX.into_url().unwrap();
|
||||||
let pkg_id = PackageId::new("foo", "1.0.0", SourceId::for_registry(&loc).unwrap()).unwrap();
|
let pkg_id = PackageId::new("foo", "1.0.0", SourceId::for_registry(&loc).unwrap()).unwrap();
|
||||||
assert_eq!(r#"PackageId { name: "foo", version: "1.0.0", source: "registry `https://github.com/rust-lang/crates.io-index`" }"#, format!("{:?}", pkg_id));
|
assert_eq!(r#"PackageId { name: "foo", version: "1.0.0", source: "registry `https://github.com/rust-lang/crates.io-index`" }"#, format!("{:?}", pkg_id));
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ PackageId {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display() {
|
fn display() {
|
||||||
let loc = CRATES_IO_INDEX.to_url().unwrap();
|
let loc = CRATES_IO_INDEX.into_url().unwrap();
|
||||||
let pkg_id = PackageId::new("foo", "1.0.0", SourceId::for_registry(&loc).unwrap()).unwrap();
|
let pkg_id = PackageId::new("foo", "1.0.0", SourceId::for_registry(&loc).unwrap()).unwrap();
|
||||||
assert_eq!("foo v1.0.0", pkg_id.to_string());
|
assert_eq!("foo v1.0.0", pkg_id.to_string());
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use url::Url;
|
|||||||
use crate::core::interning::InternedString;
|
use crate::core::interning::InternedString;
|
||||||
use crate::core::PackageId;
|
use crate::core::PackageId;
|
||||||
use crate::util::errors::{CargoResult, CargoResultExt};
|
use crate::util::errors::{CargoResult, CargoResultExt};
|
||||||
use crate::util::{validate_package_name, ToSemver, ToUrl};
|
use crate::util::{validate_package_name, IntoUrl, ToSemver};
|
||||||
|
|
||||||
/// Some or all of the data required to identify a package:
|
/// Some or all of the data required to identify a package:
|
||||||
///
|
///
|
||||||
@ -50,7 +50,7 @@ impl PackageIdSpec {
|
|||||||
/// }
|
/// }
|
||||||
pub fn parse(spec: &str) -> CargoResult<PackageIdSpec> {
|
pub fn parse(spec: &str) -> CargoResult<PackageIdSpec> {
|
||||||
if spec.contains('/') {
|
if spec.contains('/') {
|
||||||
if let Ok(url) = spec.to_url() {
|
if let Ok(url) = spec.into_url() {
|
||||||
return PackageIdSpec::from_url(url);
|
return PackageIdSpec::from_url(url);
|
||||||
}
|
}
|
||||||
if !spec.contains("://") {
|
if !spec.contains("://") {
|
||||||
|
@ -269,7 +269,7 @@ impl fmt::Display for EncodablePackageId {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{} {}", self.name, self.version)?;
|
write!(f, "{} {}", self.name, self.version)?;
|
||||||
if let Some(ref s) = self.source {
|
if let Some(ref s) = self.source {
|
||||||
write!(f, " ({})", s.to_url())?;
|
write!(f, " ({})", s.into_url())?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ use crate::ops;
|
|||||||
use crate::sources::git;
|
use crate::sources::git;
|
||||||
use crate::sources::DirectorySource;
|
use crate::sources::DirectorySource;
|
||||||
use crate::sources::{GitSource, PathSource, RegistrySource, CRATES_IO_INDEX};
|
use crate::sources::{GitSource, PathSource, RegistrySource, CRATES_IO_INDEX};
|
||||||
use crate::util::{CargoResult, Config, ToUrl};
|
use crate::util::{CargoResult, Config, IntoUrl};
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref SOURCE_ID_CACHE: Mutex<HashSet<&'static SourceIdInner>> = Mutex::new(HashSet::new());
|
static ref SOURCE_ID_CACHE: Mutex<HashSet<&'static SourceIdInner>> = Mutex::new(HashSet::new());
|
||||||
@ -117,7 +117,7 @@ impl SourceId {
|
|||||||
|
|
||||||
match kind {
|
match kind {
|
||||||
"git" => {
|
"git" => {
|
||||||
let mut url = url.to_url()?;
|
let mut url = url.into_url()?;
|
||||||
let mut reference = GitReference::Branch("master".to_string());
|
let mut reference = GitReference::Branch("master".to_string());
|
||||||
for (k, v) in url.query_pairs() {
|
for (k, v) in url.query_pairs() {
|
||||||
match &k[..] {
|
match &k[..] {
|
||||||
@ -135,11 +135,11 @@ impl SourceId {
|
|||||||
Ok(SourceId::for_git(&url, reference)?.with_precise(precise))
|
Ok(SourceId::for_git(&url, reference)?.with_precise(precise))
|
||||||
}
|
}
|
||||||
"registry" => {
|
"registry" => {
|
||||||
let url = url.to_url()?;
|
let url = url.into_url()?;
|
||||||
Ok(SourceId::new(Kind::Registry, url)?.with_precise(Some("locked".to_string())))
|
Ok(SourceId::new(Kind::Registry, url)?.with_precise(Some("locked".to_string())))
|
||||||
}
|
}
|
||||||
"path" => {
|
"path" => {
|
||||||
let url = url.to_url()?;
|
let url = url.into_url()?;
|
||||||
SourceId::new(Kind::Path, url)
|
SourceId::new(Kind::Path, url)
|
||||||
}
|
}
|
||||||
kind => Err(failure::format_err!(
|
kind => Err(failure::format_err!(
|
||||||
@ -150,8 +150,8 @@ impl SourceId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A view of the `SourceId` that can be `Display`ed as a URL.
|
/// A view of the `SourceId` that can be `Display`ed as a URL.
|
||||||
pub fn to_url(&self) -> SourceIdToUrl<'_> {
|
pub fn into_url(&self) -> SourceIdIntoUrl<'_> {
|
||||||
SourceIdToUrl {
|
SourceIdIntoUrl {
|
||||||
inner: &*self.inner,
|
inner: &*self.inner,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ impl SourceId {
|
|||||||
///
|
///
|
||||||
/// `path`: an absolute path.
|
/// `path`: an absolute path.
|
||||||
pub fn for_path(path: &Path) -> CargoResult<SourceId> {
|
pub fn for_path(path: &Path) -> CargoResult<SourceId> {
|
||||||
let url = path.to_url()?;
|
let url = path.into_url()?;
|
||||||
SourceId::new(Kind::Path, url)
|
SourceId::new(Kind::Path, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,13 +176,13 @@ impl SourceId {
|
|||||||
|
|
||||||
/// Creates a SourceId from a local registry path.
|
/// Creates a SourceId from a local registry path.
|
||||||
pub fn for_local_registry(path: &Path) -> CargoResult<SourceId> {
|
pub fn for_local_registry(path: &Path) -> CargoResult<SourceId> {
|
||||||
let url = path.to_url()?;
|
let url = path.into_url()?;
|
||||||
SourceId::new(Kind::LocalRegistry, url)
|
SourceId::new(Kind::LocalRegistry, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `SourceId` from a directory path.
|
/// Creates a `SourceId` from a directory path.
|
||||||
pub fn for_directory(path: &Path) -> CargoResult<SourceId> {
|
pub fn for_directory(path: &Path) -> CargoResult<SourceId> {
|
||||||
let url = path.to_url()?;
|
let url = path.into_url()?;
|
||||||
SourceId::new(Kind::Directory, url)
|
SourceId::new(Kind::Directory, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ impl SourceId {
|
|||||||
} else {
|
} else {
|
||||||
CRATES_IO_INDEX
|
CRATES_IO_INDEX
|
||||||
};
|
};
|
||||||
let url = url.to_url()?;
|
let url = url.into_url()?;
|
||||||
SourceId::for_registry(&url)
|
SourceId::for_registry(&url)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -390,7 +390,7 @@ impl ser::Serialize for SourceId {
|
|||||||
if self.is_path() {
|
if self.is_path() {
|
||||||
None::<String>.serialize(s)
|
None::<String>.serialize(s)
|
||||||
} else {
|
} else {
|
||||||
s.collect_str(&self.to_url())
|
s.collect_str(&self.into_url())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -504,11 +504,11 @@ impl Hash for SourceId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A `Display`able view into a `SourceId` that will write it as a url
|
/// A `Display`able view into a `SourceId` that will write it as a url
|
||||||
pub struct SourceIdToUrl<'a> {
|
pub struct SourceIdIntoUrl<'a> {
|
||||||
inner: &'a SourceIdInner,
|
inner: &'a SourceIdInner,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> fmt::Display for SourceIdToUrl<'a> {
|
impl<'a> fmt::Display for SourceIdIntoUrl<'a> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self.inner {
|
match *self.inner {
|
||||||
SourceIdInner {
|
SourceIdInner {
|
||||||
@ -579,15 +579,15 @@ impl<'a> fmt::Display for PrettyRef<'a> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{GitReference, Kind, SourceId};
|
use super::{GitReference, Kind, SourceId};
|
||||||
use crate::util::ToUrl;
|
use crate::util::IntoUrl;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn github_sources_equal() {
|
fn github_sources_equal() {
|
||||||
let loc = "https://github.com/foo/bar".to_url().unwrap();
|
let loc = "https://github.com/foo/bar".into_url().unwrap();
|
||||||
let master = Kind::Git(GitReference::Branch("master".to_string()));
|
let master = Kind::Git(GitReference::Branch("master".to_string()));
|
||||||
let s1 = SourceId::new(master.clone(), loc).unwrap();
|
let s1 = SourceId::new(master.clone(), loc).unwrap();
|
||||||
|
|
||||||
let loc = "git://github.com/foo/bar".to_url().unwrap();
|
let loc = "git://github.com/foo/bar".into_url().unwrap();
|
||||||
let s2 = SourceId::new(master, loc.clone()).unwrap();
|
let s2 = SourceId::new(master, loc.clone()).unwrap();
|
||||||
|
|
||||||
assert_eq!(s1, s2);
|
assert_eq!(s1, s2);
|
||||||
|
@ -21,7 +21,7 @@ use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_REGISTRY};
|
|||||||
use crate::util::config::{self, Config};
|
use crate::util::config::{self, Config};
|
||||||
use crate::util::errors::{CargoResult, CargoResultExt};
|
use crate::util::errors::{CargoResult, CargoResultExt};
|
||||||
use crate::util::important_paths::find_root_manifest_for_wd;
|
use crate::util::important_paths::find_root_manifest_for_wd;
|
||||||
use crate::util::ToUrl;
|
use crate::util::IntoUrl;
|
||||||
use crate::util::{paths, validate_package_name};
|
use crate::util::{paths, validate_package_name};
|
||||||
use crate::version;
|
use crate::version;
|
||||||
|
|
||||||
@ -696,7 +696,7 @@ fn get_source_id(
|
|||||||
) -> CargoResult<SourceId> {
|
) -> CargoResult<SourceId> {
|
||||||
match (reg, index) {
|
match (reg, index) {
|
||||||
(Some(r), _) => SourceId::alt_registry(config, &r),
|
(Some(r), _) => SourceId::alt_registry(config, &r),
|
||||||
(_, Some(i)) => SourceId::for_registry(&i.to_url()?),
|
(_, Some(i)) => SourceId::for_registry(&i.into_url()?),
|
||||||
_ => {
|
_ => {
|
||||||
let map = SourceConfigMap::new(config)?;
|
let map = SourceConfigMap::new(config)?;
|
||||||
let src = map.load(SourceId::crates_io(config)?, &HashSet::new())?;
|
let src = map.load(SourceId::crates_io(config)?, &HashSet::new())?;
|
||||||
|
@ -14,7 +14,7 @@ use crate::core::{GitReference, PackageId, Source, SourceId};
|
|||||||
use crate::sources::{ReplacedSource, CRATES_IO_REGISTRY};
|
use crate::sources::{ReplacedSource, CRATES_IO_REGISTRY};
|
||||||
use crate::util::config::ConfigValue;
|
use crate::util::config::ConfigValue;
|
||||||
use crate::util::errors::{CargoResult, CargoResultExt};
|
use crate::util::errors::{CargoResult, CargoResultExt};
|
||||||
use crate::util::{Config, ToUrl};
|
use crate::util::{Config, IntoUrl};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SourceConfigMap<'cfg> {
|
pub struct SourceConfigMap<'cfg> {
|
||||||
@ -242,7 +242,7 @@ restore the source replacement configuration to continue the build
|
|||||||
|
|
||||||
fn url(cfg: &ConfigValue, key: &str) -> CargoResult<Url> {
|
fn url(cfg: &ConfigValue, key: &str) -> CargoResult<Url> {
|
||||||
let (url, path) = cfg.string(key)?;
|
let (url, path) = cfg.string(key)?;
|
||||||
let url = url.to_url().chain_err(|| {
|
let url = url.into_url().chain_err(|| {
|
||||||
format!(
|
format!(
|
||||||
"configuration key `{}` specified an invalid \
|
"configuration key `{}` specified an invalid \
|
||||||
URL (in {})",
|
URL (in {})",
|
||||||
|
@ -241,7 +241,7 @@ impl<'cfg> Source for GitSource<'cfg> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::ident;
|
use super::ident;
|
||||||
use crate::util::ToUrl;
|
use crate::util::IntoUrl;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -291,6 +291,6 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn url(s: &str) -> Url {
|
fn url(s: &str) -> Url {
|
||||||
s.to_url().unwrap()
|
s.into_url().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ use crate::core::GitReference;
|
|||||||
use crate::util::errors::{CargoResult, CargoResultExt};
|
use crate::util::errors::{CargoResult, CargoResultExt};
|
||||||
use crate::util::paths;
|
use crate::util::paths;
|
||||||
use crate::util::process_builder::process;
|
use crate::util::process_builder::process;
|
||||||
use crate::util::{internal, network, Config, Progress, ToUrl};
|
use crate::util::{internal, network, Config, IntoUrl, Progress};
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
pub struct GitRevision(git2::Oid);
|
pub struct GitRevision(git2::Oid);
|
||||||
@ -274,7 +274,7 @@ impl<'a> GitCheckout<'a> {
|
|||||||
//
|
//
|
||||||
// Note that we still use the same fetch options because while we don't
|
// Note that we still use the same fetch options because while we don't
|
||||||
// need authentication information we may want progress bars and such.
|
// need authentication information we may want progress bars and such.
|
||||||
let url = database.path.to_url()?;
|
let url = database.path.into_url()?;
|
||||||
let mut repo = None;
|
let mut repo = None;
|
||||||
with_fetch_options(&git_config, &url, config, &mut |fopts| {
|
with_fetch_options(&git_config, &url, config, &mut |fopts| {
|
||||||
let mut checkout = git2::build::CheckoutBuilder::new();
|
let mut checkout = git2::build::CheckoutBuilder::new();
|
||||||
@ -310,7 +310,7 @@ impl<'a> GitCheckout<'a> {
|
|||||||
|
|
||||||
fn fetch(&mut self, cargo_config: &Config) -> CargoResult<()> {
|
fn fetch(&mut self, cargo_config: &Config) -> CargoResult<()> {
|
||||||
info!("fetch {}", self.repo.path().display());
|
info!("fetch {}", self.repo.path().display());
|
||||||
let url = self.database.path.to_url()?;
|
let url = self.database.path.into_url()?;
|
||||||
let refspec = "refs/heads/*:refs/heads/*";
|
let refspec = "refs/heads/*:refs/heads/*";
|
||||||
fetch(&mut self.repo, &url, refspec, cargo_config)?;
|
fetch(&mut self.repo, &url, refspec, cargo_config)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -396,7 +396,7 @@ impl<'a> GitCheckout<'a> {
|
|||||||
|
|
||||||
// Fetch data from origin and reset to the head commit
|
// Fetch data from origin and reset to the head commit
|
||||||
let refspec = "refs/heads/*:refs/heads/*";
|
let refspec = "refs/heads/*:refs/heads/*";
|
||||||
let url = url.to_url()?;
|
let url = url.into_url()?;
|
||||||
fetch(&mut repo, &url, refspec, cargo_config).chain_err(|| {
|
fetch(&mut repo, &url, refspec, cargo_config).chain_err(|| {
|
||||||
internal(format!(
|
internal(format!(
|
||||||
"failed to fetch submodule `{}` from {}",
|
"failed to fetch submodule `{}` from {}",
|
||||||
|
@ -177,7 +177,7 @@ use crate::core::{InternedString, Package, PackageId, Source, SourceId, Summary}
|
|||||||
use crate::sources::PathSource;
|
use crate::sources::PathSource;
|
||||||
use crate::util::errors::CargoResultExt;
|
use crate::util::errors::CargoResultExt;
|
||||||
use crate::util::hex;
|
use crate::util::hex;
|
||||||
use crate::util::to_url::ToUrl;
|
use crate::util::into_url::IntoUrl;
|
||||||
use crate::util::{internal, CargoResult, Config, Filesystem};
|
use crate::util::{internal, CargoResult, Config, Filesystem};
|
||||||
|
|
||||||
const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok";
|
const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok";
|
||||||
@ -304,7 +304,7 @@ impl<'a> RegistryDependency<'a> {
|
|||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let id = if let Some(registry) = ®istry {
|
let id = if let Some(registry) = ®istry {
|
||||||
SourceId::for_registry(®istry.to_url()?)?
|
SourceId::for_registry(®istry.into_url()?)?
|
||||||
} else {
|
} else {
|
||||||
default
|
default
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,7 @@ use crate::util::toml as cargo_toml;
|
|||||||
use crate::util::Filesystem;
|
use crate::util::Filesystem;
|
||||||
use crate::util::Rustc;
|
use crate::util::Rustc;
|
||||||
use crate::util::{paths, validate_package_name, FileLock};
|
use crate::util::{paths, validate_package_name, FileLock};
|
||||||
use crate::util::{ToUrl, ToUrlWithBase};
|
use crate::util::{IntoUrl, IntoUrlWithBase};
|
||||||
|
|
||||||
/// Configuration information for cargo. This is not specific to a build, it is information
|
/// Configuration information for cargo. This is not specific to a build, it is information
|
||||||
/// relating to cargo itself.
|
/// relating to cargo itself.
|
||||||
@ -714,8 +714,8 @@ impl Config {
|
|||||||
.root(self)
|
.root(self)
|
||||||
.join("truncated-by-url_with_base");
|
.join("truncated-by-url_with_base");
|
||||||
// Parse val to check it is a URL, not a relative path without a protocol.
|
// Parse val to check it is a URL, not a relative path without a protocol.
|
||||||
let _parsed = index.val.to_url()?;
|
let _parsed = index.val.into_url()?;
|
||||||
let url = index.val.to_url_with_base(Some(&*base))?;
|
let url = index.val.into_url_with_base(Some(&*base))?;
|
||||||
if url.password().is_some() {
|
if url.password().is_some() {
|
||||||
failure::bail!("Registry URLs may not contain passwords");
|
failure::bail!("Registry URLs may not contain passwords");
|
||||||
}
|
}
|
||||||
|
@ -5,26 +5,26 @@ use url::Url;
|
|||||||
use crate::util::CargoResult;
|
use crate::util::CargoResult;
|
||||||
|
|
||||||
/// A type that can be converted to a Url
|
/// A type that can be converted to a Url
|
||||||
pub trait ToUrl {
|
pub trait IntoUrl {
|
||||||
/// Performs the conversion
|
/// Performs the conversion
|
||||||
fn to_url(self) -> CargoResult<Url>;
|
fn into_url(self) -> CargoResult<Url>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ToUrl for &'a str {
|
impl<'a> IntoUrl for &'a str {
|
||||||
fn to_url(self) -> CargoResult<Url> {
|
fn into_url(self) -> CargoResult<Url> {
|
||||||
Url::parse(self).map_err(|s| failure::format_err!("invalid url `{}`: {}", self, s))
|
Url::parse(self).map_err(|s| failure::format_err!("invalid url `{}`: {}", self, s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ToUrl for &'a Path {
|
impl<'a> IntoUrl for &'a Path {
|
||||||
fn to_url(self) -> CargoResult<Url> {
|
fn into_url(self) -> CargoResult<Url> {
|
||||||
Url::from_file_path(self)
|
Url::from_file_path(self)
|
||||||
.map_err(|()| failure::format_err!("invalid path url `{}`", self.display()))
|
.map_err(|()| failure::format_err!("invalid path url `{}`", self.display()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ToUrl for &'a PathBuf {
|
impl<'a> IntoUrl for &'a PathBuf {
|
||||||
fn to_url(self) -> CargoResult<Url> {
|
fn into_url(self) -> CargoResult<Url> {
|
||||||
self.as_path().to_url()
|
self.as_path().into_url()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,19 +1,19 @@
|
|||||||
use crate::util::{CargoResult, ToUrl};
|
use crate::util::{CargoResult, IntoUrl};
|
||||||
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
/// A type that can be interpreted as a relative Url and converted to
|
/// A type that can be interpreted as a relative Url and converted to
|
||||||
/// a Url.
|
/// a Url.
|
||||||
pub trait ToUrlWithBase {
|
pub trait IntoUrlWithBase {
|
||||||
/// Performs the conversion
|
/// Performs the conversion
|
||||||
fn to_url_with_base<U: ToUrl>(self, base: Option<U>) -> CargoResult<Url>;
|
fn into_url_with_base<U: IntoUrl>(self, base: Option<U>) -> CargoResult<Url>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ToUrlWithBase for &'a str {
|
impl<'a> IntoUrlWithBase for &'a str {
|
||||||
fn to_url_with_base<U: ToUrl>(self, base: Option<U>) -> CargoResult<Url> {
|
fn into_url_with_base<U: IntoUrl>(self, base: Option<U>) -> CargoResult<Url> {
|
||||||
let base_url = match base {
|
let base_url = match base {
|
||||||
Some(base) => Some(
|
Some(base) => Some(
|
||||||
base.to_url()
|
base.into_url()
|
||||||
.map_err(|s| failure::format_err!("invalid url `{}`: {}", self, s))?,
|
.map_err(|s| failure::format_err!("invalid url `{}`: {}", self, s))?,
|
||||||
),
|
),
|
||||||
None => None,
|
None => None,
|
||||||
@ -28,20 +28,20 @@ impl<'a> ToUrlWithBase for &'a str {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::util::ToUrlWithBase;
|
use crate::util::IntoUrlWithBase;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_url_with_base() {
|
fn into_url_with_base() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"rel/path"
|
"rel/path"
|
||||||
.to_url_with_base(Some("file:///abs/path/"))
|
.into_url_with_base(Some("file:///abs/path/"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"file:///abs/path/rel/path"
|
"file:///abs/path/rel/path"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"rel/path"
|
"rel/path"
|
||||||
.to_url_with_base(Some("file:///abs/path/popped-file"))
|
.into_url_with_base(Some("file:///abs/path/popped-file"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"file:///abs/path/rel/path"
|
"file:///abs/path/rel/path"
|
@ -10,6 +10,8 @@ pub use self::errors::{CargoTestError, CliError, ProcessError};
|
|||||||
pub use self::flock::{FileLock, Filesystem};
|
pub use self::flock::{FileLock, Filesystem};
|
||||||
pub use self::graph::Graph;
|
pub use self::graph::Graph;
|
||||||
pub use self::hex::{hash_u64, short_hash, to_hex};
|
pub use self::hex::{hash_u64, short_hash, to_hex};
|
||||||
|
pub use self::into_url::IntoUrl;
|
||||||
|
pub use self::into_url_with_base::IntoUrlWithBase;
|
||||||
pub use self::lev_distance::lev_distance;
|
pub use self::lev_distance::lev_distance;
|
||||||
pub use self::lockserver::{LockServer, LockServerClient, LockServerStarted};
|
pub use self::lockserver::{LockServer, LockServerClient, LockServerStarted};
|
||||||
pub use self::paths::{bytes2path, dylib_path, join_paths, path2bytes};
|
pub use self::paths::{bytes2path, dylib_path, join_paths, path2bytes};
|
||||||
@ -20,8 +22,6 @@ pub use self::read2::read2;
|
|||||||
pub use self::rustc::Rustc;
|
pub use self::rustc::Rustc;
|
||||||
pub use self::sha256::Sha256;
|
pub use self::sha256::Sha256;
|
||||||
pub use self::to_semver::ToSemver;
|
pub use self::to_semver::ToSemver;
|
||||||
pub use self::to_url::ToUrl;
|
|
||||||
pub use self::to_url_with_base::ToUrlWithBase;
|
|
||||||
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
|
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
|
||||||
pub use self::workspace::{
|
pub use self::workspace::{
|
||||||
print_available_benches, print_available_binaries, print_available_examples,
|
print_available_benches, print_available_binaries, print_available_examples,
|
||||||
@ -38,6 +38,8 @@ mod flock;
|
|||||||
pub mod graph;
|
pub mod graph;
|
||||||
pub mod hex;
|
pub mod hex;
|
||||||
pub mod important_paths;
|
pub mod important_paths;
|
||||||
|
pub mod into_url;
|
||||||
|
mod into_url_with_base;
|
||||||
pub mod job;
|
pub mod job;
|
||||||
pub mod lev_distance;
|
pub mod lev_distance;
|
||||||
mod lockserver;
|
mod lockserver;
|
||||||
@ -51,8 +53,6 @@ mod read2;
|
|||||||
pub mod rustc;
|
pub mod rustc;
|
||||||
mod sha256;
|
mod sha256;
|
||||||
pub mod to_semver;
|
pub mod to_semver;
|
||||||
pub mod to_url;
|
|
||||||
mod to_url_with_base;
|
|
||||||
pub mod toml;
|
pub mod toml;
|
||||||
mod vcs;
|
mod vcs;
|
||||||
mod workspace;
|
mod workspace;
|
||||||
|
@ -22,7 +22,7 @@ use crate::core::{GitReference, PackageIdSpec, SourceId, WorkspaceConfig, Worksp
|
|||||||
use crate::sources::{CRATES_IO_INDEX, CRATES_IO_REGISTRY};
|
use crate::sources::{CRATES_IO_INDEX, CRATES_IO_REGISTRY};
|
||||||
use crate::util::errors::{CargoResult, CargoResultExt, ManifestError};
|
use crate::util::errors::{CargoResult, CargoResultExt, ManifestError};
|
||||||
use crate::util::paths;
|
use crate::util::paths;
|
||||||
use crate::util::{self, validate_package_name, Config, ToUrl};
|
use crate::util::{self, validate_package_name, Config, IntoUrl};
|
||||||
|
|
||||||
mod targets;
|
mod targets;
|
||||||
use self::targets::targets;
|
use self::targets::targets;
|
||||||
@ -1231,7 +1231,7 @@ impl TomlManifest {
|
|||||||
_ => cx
|
_ => cx
|
||||||
.config
|
.config
|
||||||
.get_registry_index(url)
|
.get_registry_index(url)
|
||||||
.or_else(|_| url.to_url())
|
.or_else(|_| url.into_url())
|
||||||
.chain_err(|| {
|
.chain_err(|| {
|
||||||
format!("[patch] entry `{}` should be a URL or registry name", url)
|
format!("[patch] entry `{}` should be a URL or registry name", url)
|
||||||
})?,
|
})?,
|
||||||
@ -1403,7 +1403,7 @@ impl DetailedTomlDependency {
|
|||||||
.or_else(|| self.tag.clone().map(GitReference::Tag))
|
.or_else(|| self.tag.clone().map(GitReference::Tag))
|
||||||
.or_else(|| self.rev.clone().map(GitReference::Rev))
|
.or_else(|| self.rev.clone().map(GitReference::Rev))
|
||||||
.unwrap_or_else(|| GitReference::Branch("master".to_string()));
|
.unwrap_or_else(|| GitReference::Branch("master".to_string()));
|
||||||
let loc = git.to_url()?;
|
let loc = git.into_url()?;
|
||||||
SourceId::for_git(&loc, reference)?
|
SourceId::for_git(&loc, reference)?
|
||||||
}
|
}
|
||||||
(None, Some(path), _, _) => {
|
(None, Some(path), _, _) => {
|
||||||
@ -1426,7 +1426,7 @@ impl DetailedTomlDependency {
|
|||||||
}
|
}
|
||||||
(None, None, Some(registry), None) => SourceId::alt_registry(cx.config, registry)?,
|
(None, None, Some(registry), None) => SourceId::alt_registry(cx.config, registry)?,
|
||||||
(None, None, None, Some(registry_index)) => {
|
(None, None, None, Some(registry_index)) => {
|
||||||
let url = registry_index.to_url()?;
|
let url = registry_index.into_url()?;
|
||||||
SourceId::for_registry(&url)?
|
SourceId::for_registry(&url)?
|
||||||
}
|
}
|
||||||
(None, None, None, None) => SourceId::crates_io(cx.config)?,
|
(None, None, None, None) => SourceId::crates_io(cx.config)?,
|
||||||
@ -1455,7 +1455,7 @@ impl DetailedTomlDependency {
|
|||||||
dep.set_registry_id(registry_id);
|
dep.set_registry_id(registry_id);
|
||||||
}
|
}
|
||||||
if let Some(registry_index) = &self.registry_index {
|
if let Some(registry_index) = &self.registry_index {
|
||||||
let url = registry_index.to_url()?;
|
let url = registry_index.into_url()?;
|
||||||
let registry_id = SourceId::for_registry(&url)?;
|
let registry_id = SourceId::for_registry(&url)?;
|
||||||
dep.set_registry_id(registry_id);
|
dep.set_registry_id(registry_id);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::support::publish::validate_alt_upload;
|
use crate::support::publish::validate_alt_upload;
|
||||||
use crate::support::registry::{self, Package};
|
use crate::support::registry::{self, Package};
|
||||||
use crate::support::{basic_manifest, git, paths, project};
|
use crate::support::{basic_manifest, git, paths, project};
|
||||||
use cargo::util::ToUrl;
|
use cargo::util::IntoUrl;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ fn registry_incompatible_with_git() {
|
|||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn cannot_publish_to_crates_io_with_registry_dependency() {
|
fn cannot_publish_to_crates_io_with_registry_dependency() {
|
||||||
let fakeio_path = paths::root().join("fake.io");
|
let fakeio_path = paths::root().join("fake.io");
|
||||||
let fakeio_url = fakeio_path.to_url().unwrap();
|
let fakeio_url = fakeio_path.into_url().unwrap();
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
"Cargo.toml",
|
"Cargo.toml",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user