mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
refactor: Centralize SourceId creation for manifests
This commit is contained in:
parent
b64750d83d
commit
5a351405dc
@ -204,6 +204,17 @@ impl SourceId {
|
||||
SourceId::new(SourceKind::Path, url, None)
|
||||
}
|
||||
|
||||
/// Creates a `SourceId` from a filesystem path.
|
||||
///
|
||||
/// `path`: an absolute path.
|
||||
pub fn for_manifest_path(manifest_path: &Path) -> CargoResult<SourceId> {
|
||||
if crate::util::toml::is_embedded(manifest_path) {
|
||||
Self::for_path(manifest_path)
|
||||
} else {
|
||||
Self::for_path(manifest_path.parent().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a `SourceId` from a Git reference.
|
||||
pub fn for_git(url: &Url, reference: GitReference) -> CargoResult<SourceId> {
|
||||
SourceId::new(SourceKind::Git(reference), url.clone(), None)
|
||||
|
@ -1817,11 +1817,7 @@ impl<'gctx> Packages<'gctx> {
|
||||
match self.packages.entry(manifest_path.to_path_buf()) {
|
||||
Entry::Occupied(e) => Ok(e.into_mut()),
|
||||
Entry::Vacant(v) => {
|
||||
let source_id = if crate::util::toml::is_embedded(manifest_path) {
|
||||
SourceId::for_path(manifest_path)?
|
||||
} else {
|
||||
SourceId::for_path(manifest_path.parent().unwrap())?
|
||||
};
|
||||
let source_id = SourceId::for_manifest_path(manifest_path)?;
|
||||
let manifest = read_manifest(manifest_path, source_id, self.gctx)?;
|
||||
Ok(v.insert(match manifest {
|
||||
EitherManifest::Real(manifest) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user