Skip to content

Commit 5a35140

Browse files
committed
refactor: Centralize SourceId creation for manifests
1 parent b64750d commit 5a35140

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/cargo/core/source_id.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ impl SourceId {
204204
SourceId::new(SourceKind::Path, url, None)
205205
}
206206

207+
/// Creates a `SourceId` from a filesystem path.
208+
///
209+
/// `path`: an absolute path.
210+
pub fn for_manifest_path(manifest_path: &Path) -> CargoResult<SourceId> {
211+
if crate::util::toml::is_embedded(manifest_path) {
212+
Self::for_path(manifest_path)
213+
} else {
214+
Self::for_path(manifest_path.parent().unwrap())
215+
}
216+
}
217+
207218
/// Creates a `SourceId` from a Git reference.
208219
pub fn for_git(url: &Url, reference: GitReference) -> CargoResult<SourceId> {
209220
SourceId::new(SourceKind::Git(reference), url.clone(), None)

src/cargo/core/workspace.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,11 +1817,7 @@ impl<'gctx> Packages<'gctx> {
18171817
match self.packages.entry(manifest_path.to_path_buf()) {
18181818
Entry::Occupied(e) => Ok(e.into_mut()),
18191819
Entry::Vacant(v) => {
1820-
let source_id = if crate::util::toml::is_embedded(manifest_path) {
1821-
SourceId::for_path(manifest_path)?
1822-
} else {
1823-
SourceId::for_path(manifest_path.parent().unwrap())?
1824-
};
1820+
let source_id = SourceId::for_manifest_path(manifest_path)?;
18251821
let manifest = read_manifest(manifest_path, source_id, self.gctx)?;
18261822
Ok(v.insert(match manifest {
18271823
EitherManifest::Real(manifest) => {

0 commit comments

Comments
 (0)