Update to rust-url 1.x
authorSimon Sapin <simon.sapin@exyr.org>
Wed, 2 Mar 2016 15:37:44 +0000 (16:37 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Tue, 3 May 2016 17:41:06 +0000 (19:41 +0200)
Cargo.lock
Cargo.toml
src/cargo/core/package_id_spec.rs
src/cargo/core/source.rs
src/cargo/sources/git/source.rs
src/cargo/sources/registry.rs
src/cargo/util/to_url.rs
src/crates-io/Cargo.toml

index f10d66682a82c84b9421406314347d59b36ade5f..14140245914d2fc9967162e840fdb8ca264f827e 100644 (file)
@@ -6,19 +6,19 @@ dependencies = [
  "bufstream 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "crates-io 0.2.0",
  "crossbeam 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "curl 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "curl 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
  "docopt 0.6.78 (registry+https://github.com/rust-lang/crates.io-index)",
  "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
  "flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
  "fs2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "git2 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "git2-curl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "git2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "git2-curl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
  "hamcrest 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "libgit2-sys 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libgit2-sys 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
  "regex 0.1.58 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -29,7 +29,7 @@ dependencies = [
  "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
  "toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
- "url 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -72,9 +72,9 @@ dependencies = [
 name = "crates-io"
 version = "0.2.0"
 dependencies = [
- "curl 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "curl 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
- "url 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -84,14 +84,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "curl"
-version = "0.2.18"
+version = "0.2.19"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "curl-sys 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl-sys 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -167,24 +167,24 @@ dependencies = [
 
 [[package]]
 name = "git2"
-version = "0.4.2"
+version = "0.4.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "libgit2-sys 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libgit2-sys 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "git2-curl"
-version = "0.4.0"
+version = "0.4.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "curl 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
- "git2 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "curl 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
+ "git2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -200,6 +200,16 @@ dependencies = [
  "num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "idna"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "kernel32-sys"
 version = "0.2.1"
@@ -216,7 +226,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "libgit2-sys"
-version = "0.4.2"
+version = "0.4.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "cmake 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -436,24 +446,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "url"
-version = "0.2.38"
+version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
+ "idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
- "uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "url"
-version = "0.5.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
- "unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -470,15 +467,6 @@ name = "utf8-ranges"
 version = "0.1.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
-[[package]]
-name = "uuid"
-version = "0.1.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
 [[package]]
 name = "winapi"
 version = "0.2.6"
index b522909ad5cd5fd1d9c3a2ba270546eb2c82e69c..a5d6738691146232568d26d02fa9d339c092d7db 100644 (file)
@@ -42,7 +42,7 @@ tempdir = "0.3"
 term = "0.4.4"
 time = "0.1"
 toml = "0.1"
-url = "0.2"
+url = "1.1"
 winapi = "0.2"
 
 [dev-dependencies]
index 1621ccfc261d5ea652dbacbd4b417d7ee4d1888a..a643713b279720e7218b238f9cd947eacd434062 100644 (file)
@@ -2,7 +2,7 @@ use std::collections::HashMap;
 use std::fmt;
 
 use semver::Version;
-use url::{self, Url, UrlParser};
+use url::Url;
 
 use core::PackageId;
 use util::{CargoResult, ToUrl, human, ToSemver, ChainError};
@@ -22,7 +22,7 @@ impl PackageIdSpec {
                 Err(..) => {}
             }
             if !spec.contains("://") {
-                match url(&format!("cargo://{}", spec)) {
+                match Url::parse(&format!("cargo://{}", spec)) {
                     Ok(url) => return PackageIdSpec::from_url(url),
                     Err(..) => {}
                 }
@@ -64,15 +64,16 @@ impl PackageIdSpec {
     }
 
     fn from_url(mut url: Url) -> CargoResult<PackageIdSpec> {
-        if url.query.is_some() {
+        if url.query().is_some() {
             bail!("cannot have a query string in a pkgid: {}", url)
         }
-        let frag = url.fragment.take();
+        let frag = url.fragment().map(|s| s.to_owned());
+        url.set_fragment(None);
         let (name, version) = {
-            let path = try!(url.path().chain_error(|| {
+            let mut path = try!(url.path_segments().chain_error(|| {
                 human(format!("pkgid urls must have a path: {}", url))
             }));
-            let path_name = try!(path.last().chain_error(|| {
+            let path_name = try!(path.next_back().chain_error(|| {
                 human(format!("pkgid urls must have at least one path \
                                component: {}", url))
             }));
@@ -171,31 +172,17 @@ impl PackageIdSpec {
     }
 }
 
-fn url(s: &str) -> url::ParseResult<Url> {
-    return UrlParser::new().scheme_type_mapper(mapper).parse(s);
-
-    fn mapper(scheme: &str) -> url::SchemeType {
-        if scheme == "cargo" {
-            url::SchemeType::Relative(1)
-        } else {
-            url::whatwg_scheme_type_mapper(scheme)
-        }
-    }
-
-}
-
 impl fmt::Display for PackageIdSpec {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         let mut printed_name = false;
         match self.url {
             Some(ref url) => {
-                if url.scheme == "cargo" {
-                    try!(write!(f, "{}/{}", url.host().unwrap(),
-                                url.path().unwrap().join("/")));
+                if url.scheme() == "cargo" {
+                    try!(write!(f, "{}{}", url.host().unwrap(), url.path()));
                 } else {
                     try!(write!(f, "{}", url));
                 }
-                if url.path().unwrap().last().unwrap() != &self.name {
+                if url.path_segments().unwrap().next_back().unwrap() != &self.name {
                     printed_name = true;
                     try!(write!(f, "#{}", self.name));
                 }
@@ -215,7 +202,7 @@ impl fmt::Display for PackageIdSpec {
 #[cfg(test)]
 mod tests {
     use core::{PackageId, SourceId};
-    use super::{PackageIdSpec, url};
+    use super::PackageIdSpec;
     use url::Url;
     use semver::Version;
 
@@ -230,32 +217,32 @@ mod tests {
         ok("http://crates.io/foo#1.2.3", PackageIdSpec {
             name: "foo".to_string(),
             version: Some(Version::parse("1.2.3").unwrap()),
-            url: Some(url("http://crates.io/foo").unwrap()),
+            url: Some(Url::parse("http://crates.io/foo").unwrap()),
         });
         ok("http://crates.io/foo#bar:1.2.3", PackageIdSpec {
             name: "bar".to_string(),
             version: Some(Version::parse("1.2.3").unwrap()),
-            url: Some(url("http://crates.io/foo").unwrap()),
+            url: Some(Url::parse("http://crates.io/foo").unwrap()),
         });
         ok("crates.io/foo", PackageIdSpec {
             name: "foo".to_string(),
             version: None,
-            url: Some(url("cargo://crates.io/foo").unwrap()),
+            url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
         });
         ok("crates.io/foo#1.2.3", PackageIdSpec {
             name: "foo".to_string(),
             version: Some(Version::parse("1.2.3").unwrap()),
-            url: Some(url("cargo://crates.io/foo").unwrap()),
+            url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
         });
         ok("crates.io/foo#bar", PackageIdSpec {
             name: "bar".to_string(),
             version: None,
-            url: Some(url("cargo://crates.io/foo").unwrap()),
+            url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
         });
         ok("crates.io/foo#bar:1.2.3", PackageIdSpec {
             name: "bar".to_string(),
             version: Some(Version::parse("1.2.3").unwrap()),
-            url: Some(url("cargo://crates.io/foo").unwrap()),
+            url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
         });
         ok("foo", PackageIdSpec {
             name: "foo".to_string(),
index c1b6dd3156ad46b36afff7e134ee3fe6acdaa915..2229c33bb6ae694b1f7298b301b1a7d81794feda 100644 (file)
@@ -2,7 +2,6 @@ use std::cmp::{self, Ordering};
 use std::collections::hash_map::{HashMap, Values, IterMut};
 use std::fmt::{self, Formatter};
 use std::hash;
-use std::mem;
 use std::path::Path;
 use std::sync::Arc;
 use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
@@ -101,20 +100,20 @@ impl SourceId {
             "git" => {
                 let mut url = url.to_url().unwrap();
                 let mut reference = GitReference::Branch("master".to_string());
-                let pairs = url.query_pairs().unwrap_or(Vec::new());
-                for &(ref k, ref v) in pairs.iter() {
+                for (k, v) in url.query_pairs() {
                     match &k[..] {
                         // map older 'ref' to branch
                         "branch" |
-                        "ref" => reference = GitReference::Branch(v.clone()),
+                        "ref" => reference = GitReference::Branch(v.into_owned()),
 
-                        "rev" => reference = GitReference::Rev(v.clone()),
-                        "tag" => reference = GitReference::Tag(v.clone()),
+                        "rev" => reference = GitReference::Rev(v.into_owned()),
+                        "tag" => reference = GitReference::Tag(v.into_owned()),
                         _ => {}
                     }
                 }
-                url.query = None;
-                let precise = mem::replace(&mut url.fragment, None);
+                let precise = url.fragment().map(|s| s.to_owned());
+                url.set_fragment(None);
+                url.set_query(None);
                 SourceId::for_git(&url, reference).with_precise(precise)
             }
             "registry" => {
index 1ac3f183fd6502aa76469d758fb0896b276bb00e..b47dda80a9d0fb081e13840885c8be2a56139072 100644 (file)
@@ -1,8 +1,7 @@
 use std::fmt::{self, Debug, Formatter};
 use std::hash::{Hash, Hasher, SipHasher};
-use std::mem;
 
-use url::{self, Url};
+use url::Url;
 
 use core::source::{Source, SourceId};
 use core::GitReference;
@@ -62,15 +61,11 @@ impl<'cfg> GitSource<'cfg> {
 fn ident(url: &Url) -> String {
     let mut hasher = SipHasher::new_with_keys(0,0);
 
-    // FIXME: this really should be able to not use to_str() everywhere, but the
-    //        compiler seems to currently ask for static lifetimes spuriously.
-    //        Perhaps related to rust-lang/rust#15144
     let url = canonicalize_url(url);
-    let ident = url.path().unwrap_or(&[])
-                   .last().map(|a| a.clone()).unwrap_or(String::new());
+    let ident = url.path_segments().and_then(|mut s| s.next_back()).unwrap_or("");
 
     let ident = if ident == "" {
-        "_empty".to_string()
+        "_empty"
     } else {
         ident
     };
@@ -84,39 +79,27 @@ pub fn canonicalize_url(url: &Url) -> Url {
     let mut url = url.clone();
 
     // Strip a trailing slash
-    if let url::SchemeData::Relative(ref mut rel) = url.scheme_data {
-        if rel.path.last().map(|s| s.is_empty()).unwrap_or(false) {
-            rel.path.pop();
-        }
-    }
+    url.path_segments_mut().unwrap().pop_if_empty();
 
     // HACKHACK: For github URL's specifically just lowercase
     // everything.  GitHub treats both the same, but they hash
     // differently, and we're gonna be hashing them. This wants a more
     // general solution, and also we're almost certainly not using the
     // same case conversion rules that GitHub does. (#84)
-    if url.domain() == Some("github.com") {
-        url.scheme = "https".to_string();
-        if let url::SchemeData::Relative(ref mut rel) = url.scheme_data {
-            rel.port = Some(443);
-            rel.default_port = Some(443);
-            let path = mem::replace(&mut rel.path, Vec::new());
-            rel.path = path.into_iter().map(|s| {
-                s.chars().flat_map(|c| c.to_lowercase()).collect()
-            }).collect();
-        }
+    if url.host_str() == Some("github.com") {
+        url.set_scheme("https").unwrap();
+        let path = url.path().to_lowercase();
+        url.set_path(&path);
     }
 
     // Repos generally can be accessed with or w/o '.git'
-    if let url::SchemeData::Relative(ref mut rel) = url.scheme_data {
-        let needs_chopping = {
-            let last = rel.path.last().map(|s| &s[..]).unwrap_or("");
-            last.ends_with(".git")
+    let needs_chopping = url.path().ends_with(".git");
+    if needs_chopping {
+        let last = {
+            let last = url.path_segments().unwrap().next_back().unwrap();
+            last[..last.len() - 4].to_owned()
         };
-        if needs_chopping {
-            let last = rel.path.pop().unwrap();
-            rel.path.push(last[..last.len() - 4].to_string())
-        }
+        url.path_segments_mut().unwrap().pop().push(&last);
     }
 
     url
index 9652d8145e86f6a3d7db4ad6ed8362d0f72ed498..c1695da6bbb1d68fb737831b1a7befc428cd32ec 100644 (file)
@@ -231,7 +231,7 @@ impl<'cfg> RegistrySource<'cfg> {
     pub fn new(source_id: &SourceId,
                config: &'cfg Config) -> RegistrySource<'cfg> {
         let hash = hex::short_hash(source_id);
-        let ident = source_id.url().host().unwrap().to_string();
+        let ident = source_id.url().host_str().unwrap_or("").to_string();
         let part = format!("{}-{}", ident, hash);
         RegistrySource {
             checkout_path: config.registry_index_path().join(&part),
@@ -558,9 +558,10 @@ impl<'cfg> Source for RegistrySource<'cfg> {
         let config = try!(self.config());
         let url = try!(config.dl.to_url().map_err(internal));
         let mut url = url.clone();
-        url.path_mut().unwrap().push(package.name().to_string());
-        url.path_mut().unwrap().push(package.version().to_string());
-        url.path_mut().unwrap().push("download".to_string());
+        url.path_segments_mut().unwrap()
+            .push(package.name())
+            .push(&package.version().to_string())
+            .push("download");
         let krate = try!(self.download_package(package, &url).chain_error(|| {
             internal(format!("failed to download package `{}` from {}",
                              package, url))
index 2e3365cb255cd43e9c495e68acdddc83fa939033..59159cc1d91fa05b650e642ffc2f953954097378 100644 (file)
@@ -1,4 +1,4 @@
-use url::{self, Url, UrlParser};
+use url::Url;
 use std::path::Path;
 
 pub trait ToUrl {
@@ -19,7 +19,7 @@ impl<'a> ToUrl for &'a Url {
 
 impl<'a> ToUrl for &'a str {
     fn to_url(self) -> Result<Url, String> {
-        UrlParser::new().scheme_type_mapper(mapper).parse(self).map_err(|s| {
+        Url::parse(self).map_err(|s| {
             format!("invalid url `{}`: {}", self, s)
         })
     }
@@ -32,11 +32,3 @@ impl<'a> ToUrl for &'a Path {
         })
     }
 }
-
-fn mapper(s: &str) -> url::SchemeType {
-    match s {
-        "git" => url::SchemeType::Relative(9418),
-        "ssh" => url::SchemeType::Relative(22),
-        s => url::whatwg_scheme_type_mapper(s),
-    }
-}
index e049066f85d199169aaf604f69639bdeb19d81a2..72f732295796916c8058438d2341563ca1e16f5f 100644 (file)
@@ -14,5 +14,5 @@ path = "lib.rs"
 
 [dependencies]
 curl = "0.2"
-url = "0.2"
+url = "1.0"
 rustc-serialize = "0.3"