Skip to content

Commit

Permalink
refactor(spec): Allow tracking the kind
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 8, 2023
1 parent 9765a44 commit 9f0e0ac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use self::package_id_spec::PackageIdSpec;
pub use self::registry::Registry;
pub use self::resolver::{Resolve, ResolveVersion};
pub use self::shell::{Shell, Verbosity};
pub use self::source_id::{GitReference, SourceId};
pub use self::source_id::{GitReference, SourceId, SourceKind};
pub use self::summary::{FeatureMap, FeatureValue, Summary};
pub use self::workspace::{
find_workspace_root, resolve_relative_path, MaybePackage, Workspace, WorkspaceConfig,
Expand Down
27 changes: 27 additions & 0 deletions src/cargo/core/package_id_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde::{de, ser};
use url::Url;

use crate::core::PackageId;
use crate::core::SourceKind;
use crate::util::edit_distance;
use crate::util::errors::CargoResult;
use crate::util::{validate_package_name, IntoUrl};
Expand All @@ -26,6 +27,7 @@ pub struct PackageIdSpec {
name: String,
version: Option<PartialVersion>,
url: Option<Url>,
kind: Option<SourceKind>,
}

impl PackageIdSpec {
Expand Down Expand Up @@ -78,6 +80,7 @@ impl PackageIdSpec {
name: String::from(name),
version,
url: None,
kind: None,
})
}

Expand All @@ -101,6 +104,7 @@ impl PackageIdSpec {
name: String::from(package_id.name().as_str()),
version: Some(package_id.version().clone().into()),
url: Some(package_id.source_id().url().clone()),
kind: None,
}
}

Expand Down Expand Up @@ -144,6 +148,7 @@ impl PackageIdSpec {
name,
version,
url: Some(url),
kind: None,
})
}

Expand Down Expand Up @@ -216,6 +221,7 @@ impl PackageIdSpec {
name: self.name.clone(),
version: self.version.clone(),
url: None,
kind: None,
},
&mut suggestion,
);
Expand All @@ -226,6 +232,7 @@ impl PackageIdSpec {
name: self.name.clone(),
version: None,
url: None,
kind: None,
},
&mut suggestion,
);
Expand Down Expand Up @@ -346,6 +353,7 @@ mod tests {
name: String::from("foo"),
version: None,
url: Some(Url::parse("https://crates.io/foo").unwrap()),
kind: None,
},
"https://crates.io/foo",
);
Expand All @@ -355,6 +363,7 @@ mod tests {
name: String::from("foo"),
version: Some("1.2.3".parse().unwrap()),
url: Some(Url::parse("https://crates.io/foo").unwrap()),
kind: None,
},
"https://crates.io/foo#1.2.3",
);
Expand All @@ -364,6 +373,7 @@ mod tests {
name: String::from("foo"),
version: Some("1.2".parse().unwrap()),
url: Some(Url::parse("https://crates.io/foo").unwrap()),
kind: None,
},
"https://crates.io/foo#1.2",
);
Expand All @@ -373,6 +383,7 @@ mod tests {
name: String::from("bar"),
version: Some("1.2.3".parse().unwrap()),
url: Some(Url::parse("https://crates.io/foo").unwrap()),
kind: None,
},
"https://crates.io/foo#[email protected]",
);
Expand All @@ -382,6 +393,7 @@ mod tests {
name: String::from("bar"),
version: Some("1.2.3".parse().unwrap()),
url: Some(Url::parse("https://crates.io/foo").unwrap()),
kind: None,
},
"https://crates.io/foo#[email protected]",
);
Expand All @@ -391,6 +403,7 @@ mod tests {
name: String::from("bar"),
version: Some("1.2".parse().unwrap()),
url: Some(Url::parse("https://crates.io/foo").unwrap()),
kind: None,
},
"https://crates.io/foo#[email protected]",
);
Expand All @@ -400,6 +413,7 @@ mod tests {
name: String::from("foo"),
version: None,
url: None,
kind: None,
},
"foo",
);
Expand All @@ -409,6 +423,7 @@ mod tests {
name: String::from("foo"),
version: Some("1.2.3".parse().unwrap()),
url: None,
kind: None,
},
"[email protected]",
);
Expand All @@ -418,6 +433,7 @@ mod tests {
name: String::from("foo"),
version: Some("1.2.3".parse().unwrap()),
url: None,
kind: None,
},
"[email protected]",
);
Expand All @@ -427,6 +443,7 @@ mod tests {
name: String::from("foo"),
version: Some("1.2".parse().unwrap()),
url: None,
kind: None,
},
"[email protected]",
);
Expand All @@ -438,6 +455,7 @@ mod tests {
name: String::from("regex"),
version: None,
url: None,
kind: None,
},
"regex",
);
Expand All @@ -447,6 +465,7 @@ mod tests {
name: String::from("regex"),
version: Some("1.4".parse().unwrap()),
url: None,
kind: None,
},
"[email protected]",
);
Expand All @@ -456,6 +475,7 @@ mod tests {
name: String::from("regex"),
version: Some("1.4.3".parse().unwrap()),
url: None,
kind: None,
},
"[email protected]",
);
Expand All @@ -465,6 +485,7 @@ mod tests {
name: String::from("regex"),
version: None,
url: Some(Url::parse("https://github.com/rust-lang/crates.io-index").unwrap()),
kind: None,
},
"https://github.com/rust-lang/crates.io-index#regex",
);
Expand All @@ -474,6 +495,7 @@ mod tests {
name: String::from("regex"),
version: Some("1.4.3".parse().unwrap()),
url: Some(Url::parse("https://github.com/rust-lang/crates.io-index").unwrap()),
kind: None,
},
"https://github.com/rust-lang/crates.io-index#[email protected]",
);
Expand All @@ -483,6 +505,7 @@ mod tests {
name: String::from("cargo"),
version: Some("0.52.0".parse().unwrap()),
url: Some(Url::parse("https://github.com/rust-lang/cargo").unwrap()),
kind: None,
},
"https://github.com/rust-lang/cargo#0.52.0",
);
Expand All @@ -492,6 +515,7 @@ mod tests {
name: String::from("cargo-platform"),
version: Some("0.1.2".parse().unwrap()),
url: Some(Url::parse("https://github.com/rust-lang/cargo").unwrap()),
kind: None,
},
"https://github.com/rust-lang/cargo#[email protected]",
);
Expand All @@ -501,6 +525,7 @@ mod tests {
name: String::from("regex"),
version: Some("1.4.3".parse().unwrap()),
url: Some(Url::parse("ssh://[email protected]/rust-lang/regex.git").unwrap()),
kind: None,
},
"ssh://[email protected]/rust-lang/regex.git#[email protected]",
);
Expand All @@ -510,6 +535,7 @@ mod tests {
name: String::from("foo"),
version: None,
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()),
kind: None,
},
"file:///path/to/my/project/foo",
);
Expand All @@ -519,6 +545,7 @@ mod tests {
name: String::from("foo"),
version: Some("1.1.8".parse().unwrap()),
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()),
kind: None,
},
"file:///path/to/my/project/foo#1.1.8",
);
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl fmt::Display for Precise {
/// The possible kinds of code source.
/// Along with [`SourceIdInner`], this fully defines the source.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum SourceKind {
pub enum SourceKind {
/// A git repository.
Git(GitReference),
/// A local path.
Expand Down

0 comments on commit 9f0e0ac

Please sign in to comment.