Skip to content

Commit

Permalink
Switch to use crates-io as the registry name and don't include publis…
Browse files Browse the repository at this point in the history
…h when registry is not specified
  • Loading branch information
cswindle committed Oct 8, 2018
1 parent abd9ac4 commit 1fd3f1b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/bin/cargo/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cargo::CargoResult;
use cargo::core::Workspace;
use cargo::core::compiler::{BuildConfig, MessageFormat};
use cargo::ops::{CompileFilter, CompileOptions, NewOptions, Packages, VersionControl};
use cargo::sources::CRATES_IO_REGISTRY;
use cargo::util::paths;
use cargo::util::important_paths::find_root_manifest_for_wd;

Expand Down Expand Up @@ -361,7 +362,7 @@ pub trait ArgMatchesExt {
));
}

if registry == "crates.io" {
if registry == CRATES_IO_REGISTRY {
// If "crates.io" is specified then we just need to return None
// as that will cause cargo to use crates.io. This is required
// for the case where a default alterative registry is used
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ impl fmt::Debug for PackageId {
mod tests {
use super::PackageId;
use core::source::SourceId;
use sources::CRATES_IO;
use sources::CRATES_IO_INDEX;
use util::ToUrl;

#[test]
fn invalid_version_handled_nicely() {
let loc = CRATES_IO.to_url().unwrap();
let loc = CRATES_IO_INDEX.to_url().unwrap();
let repo = SourceId::for_registry(&loc).unwrap();

assert!(PackageId::new("foo", "1.0", &repo).is_err());
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use url::Url;

use ops;
use sources::git;
use sources::{GitSource, PathSource, RegistrySource, CRATES_IO};
use sources::{GitSource, PathSource, RegistrySource, CRATES_IO_INDEX};
use sources::DirectorySource;
use util::{CargoResult, Config, ToUrl};

Expand Down Expand Up @@ -184,7 +184,7 @@ impl SourceId {
}
&index[..]
} else {
CRATES_IO
CRATES_IO_INDEX
};
let url = url.to_url()?;
SourceId::for_registry(&url)
Expand Down Expand Up @@ -302,7 +302,7 @@ impl SourceId {
Kind::Registry => {}
_ => return false,
}
self.inner.url.to_string() == CRATES_IO
self.inner.url.to_string() == CRATES_IO_INDEX
}

/// Hash `self`
Expand Down
11 changes: 7 additions & 4 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,7 @@ name = "{}"
version = "0.1.0"
authors = [{}]
edition = {}
publish = {}
{}
[dependencies]
{}"#,
name,
Expand All @@ -554,8 +553,12 @@ publish = {}
None => toml::Value::String("2018".to_string()),
},
match opts.registry {
Some(registry) => toml::Value::Array(vec!(toml::Value::String(registry.to_string()))),
None => toml::Value::Boolean(true),
Some(registry) => {
format!("publish = {}\n",
toml::Value::Array(vec!(toml::Value::String(registry.to_string())))
)
}
None => "".to_string(),
},
cargotoml_path_specifier
).as_bytes(),
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 @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
use url::Url;

use core::{GitReference, Source, SourceId};
use sources::ReplacedSource;
use sources::{ReplacedSource, CRATES_IO_REGISTRY};
use util::{Config, ToUrl};
use util::config::ConfigValue;
use util::errors::{CargoResult, CargoResultExt};
Expand Down Expand Up @@ -59,7 +59,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
config,
};
base.add(
"crates-io",
CRATES_IO_REGISTRY,
SourceConfig {
id: SourceId::crates_io(config)?,
replace_with: None,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub use self::config::SourceConfigMap;
pub use self::directory::DirectorySource;
pub use self::git::GitSource;
pub use self::path::PathSource;
pub use self::registry::{RegistrySource, CRATES_IO};
pub use self::registry::{RegistrySource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
pub use self::replaced::ReplacedSource;

pub mod config;
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ use util::to_url::ToUrl;
use util::{internal, CargoResult, Config, FileLock, Filesystem};

const INDEX_LOCK: &str = ".cargo-index-lock";
pub const CRATES_IO: &str = "https://github.com/rust-lang/crates.io-index";
pub const CRATES_IO_INDEX: &str = "https://github.com/rust-lang/crates.io-index";
pub const CRATES_IO_REGISTRY: &str = "crates-io";
const CRATE_TEMPLATE: &str = "{crate}";
const VERSION_TEMPLATE: &str = "{version}";

Expand Down
6 changes: 3 additions & 3 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use core::profiles::Profiles;
use core::{Dependency, Manifest, PackageId, Summary, Target};
use core::{Edition, EitherManifest, Feature, Features, VirtualManifest};
use core::{GitReference, PackageIdSpec, SourceId, WorkspaceConfig, WorkspaceRootConfig};
use sources::CRATES_IO;
use sources::{CRATES_IO_INDEX, CRATES_IO_REGISTRY};
use util::errors::{CargoError, CargoResult, CargoResultExt};
use util::paths;
use util::{self, Config, ToUrl};
Expand Down Expand Up @@ -1140,7 +1140,7 @@ impl TomlManifest {
)
})?;
if spec.url().is_none() {
spec.set_url(CRATES_IO.parse().unwrap());
spec.set_url(CRATES_IO_INDEX.parse().unwrap());
}

let version_specified = match *replacement {
Expand Down Expand Up @@ -1175,7 +1175,7 @@ impl TomlManifest {
let mut patch = HashMap::new();
for (url, deps) in self.patch.iter().flat_map(|x| x) {
let url = match &url[..] {
"crates-io" => CRATES_IO.parse().unwrap(),
CRATES_IO_REGISTRY => CRATES_IO_INDEX.parse().unwrap(),
_ => url.to_url()?,
};
patch.insert(
Expand Down

0 comments on commit 1fd3f1b

Please sign in to comment.