Skip to content

Commit 1f020f0

Browse files
committed
Auto merge of #13993 - epage:path-source, r=ehuss
refactor(source): Split `RecursivePathSource` out of `PathSource` ### What does this PR try to resolve? `PathSource` serves a couple of roles - When a dependency / patch uses `path` (non-recursive) - As the implementation details of a `git` source (recursive) - Dependency overrides (recursive) Instead of using a `PathSource::new` vs `PathSouce::new_recursive`, this does `RecursivePathSource::new`. This makes the intent a lot clearer and makes it easier to customize the behavior to each role that is played. Specifically, there are two ways I expect to leverage this refactor - Improve the interplay between `RecursivePathSource` and `read_packages` to reduce the duplicate package warnings for git sources (#13992) - cargo script will change the semantics of path sources slightly and I'm assuming having a distinct source will make this easier ### How should we test and review this PR? ### Additional information
2 parents d503f74 + 406bf68 commit 1f020f0

File tree

5 files changed

+771
-600
lines changed

5 files changed

+771
-600
lines changed

src/cargo/core/workspace.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1142,8 +1142,7 @@ impl<'gctx> Workspace<'gctx> {
11421142
MaybePackage::Package(ref p) => p.clone(),
11431143
MaybePackage::Virtual(_) => continue,
11441144
};
1145-
let mut src = PathSource::new(pkg.root(), pkg.package_id().source_id(), self.gctx);
1146-
src.preload_with(pkg);
1145+
let src = PathSource::preload_with(pkg, self.gctx);
11471146
registry.add_preloaded(Box::new(src));
11481147
}
11491148
}

src/cargo/ops/resolve.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use crate::core::PackageSet;
7373
use crate::core::SourceId;
7474
use crate::core::Workspace;
7575
use crate::ops;
76-
use crate::sources::PathSource;
76+
use crate::sources::RecursivePathSource;
7777
use crate::util::cache_lock::CacheLockMode;
7878
use crate::util::errors::CargoResult;
7979
use crate::util::CanonicalUrl;
@@ -453,7 +453,7 @@ pub fn add_overrides<'a>(
453453

454454
for (path, definition) in paths {
455455
let id = SourceId::for_path(&path)?;
456-
let mut source = PathSource::new_recursive(&path, id, ws.gctx());
456+
let mut source = RecursivePathSource::new(&path, id, ws.gctx());
457457
source.update().with_context(|| {
458458
format!(
459459
"failed to update path override `{}` \

src/cargo/sources/git/source.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::sources::source::MaybePackage;
1010
use crate::sources::source::QueryKind;
1111
use crate::sources::source::Source;
1212
use crate::sources::IndexSummary;
13-
use crate::sources::PathSource;
13+
use crate::sources::RecursivePathSource;
1414
use crate::util::cache_lock::CacheLockMode;
1515
use crate::util::errors::CargoResult;
1616
use crate::util::hex::short_hash;
@@ -24,7 +24,7 @@ use tracing::trace;
2424
use url::Url;
2525

2626
/// `GitSource` contains one or more packages gathering from a Git repository.
27-
/// Under the hood it uses [`PathSource`] to discover packages inside the
27+
/// Under the hood it uses [`RecursivePathSource`] to discover packages inside the
2828
/// repository.
2929
///
3030
/// ## Filesystem layout
@@ -79,7 +79,7 @@ pub struct GitSource<'gctx> {
7979
///
8080
/// This gets set to `Some` after the git repo has been checked out
8181
/// (automatically handled via [`GitSource::block_until_ready`]).
82-
path_source: Option<PathSource<'gctx>>,
82+
path_source: Option<RecursivePathSource<'gctx>>,
8383
/// A short string that uniquely identifies the version of the checkout.
8484
///
8585
/// This is typically a 7-character string of the OID hash, automatically
@@ -356,7 +356,7 @@ impl<'gctx> Source for GitSource<'gctx> {
356356
let source_id = self
357357
.source_id
358358
.with_git_precise(Some(actual_rev.to_string()));
359-
let path_source = PathSource::new_recursive(&checkout_path, source_id, self.gctx);
359+
let path_source = RecursivePathSource::new(&checkout_path, source_id, self.gctx);
360360

361361
self.path_source = Some(path_source);
362362
self.short_id = Some(short_id.as_str().into());

src/cargo/sources/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub use self::config::SourceConfigMap;
3030
pub use self::directory::DirectorySource;
3131
pub use self::git::GitSource;
3232
pub use self::path::PathSource;
33+
pub use self::path::RecursivePathSource;
3334
pub use self::registry::{
3435
IndexSummary, RegistrySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX, CRATES_IO_REGISTRY,
3536
};

0 commit comments

Comments
 (0)