Allow updating transitive deps

Previously `cargo update foo` would only update the package `foo` if it were a
direct dependency of the local package. This meant that to update a transitive
dependency you would have to update the top-level dependency.

This commit adds the ability to update any dependency by name, regardless of
where it is in the dependency graph. This commit is a bit lossy in terms of
behavior. We are guaranteed that the set of immediate dependencies for any one
package have unique names, but not for the entire package graph. This means that
when you invoke `cargo update foo` it could possibly update two packages named
`foo`.

I believe this behavior to be acceptable for now and we can add a more stringent
update syntax later (something like `cargo update --namespace foo bar`). I
believe we'll always want this CLI usage, however.
This commit is contained in:
Alex Crichton 2014-08-15 18:25:12 -07:00
parent a216b9f7cd
commit ae1962d759
2 changed files with 8 additions and 7 deletions

View file

@ -63,13 +63,8 @@ pub fn update_lockfile(manifest_path: &Path,
let sources = match to_update {
Some(name) => {
let mut to_avoid = HashSet::new();
match resolve.deps(package.get_package_id()) {
Some(deps) => {
for dep in deps.filter(|d| d.get_name() == name.as_slice()) {
fill_with_deps(&resolve, dep, &mut to_avoid);
}
}
None => {}
for dep in resolve.iter().filter(|d| d.get_name() == name.as_slice()) {
fill_with_deps(&resolve, dep, &mut to_avoid);
}
resolve.iter().filter(|pkgid| !to_avoid.contains(pkgid))
.map(|pkgid| pkgid.get_source_id().clone()).collect()

View file

@ -678,6 +678,12 @@ test!(update_with_shared_deps {
{compiling} foo v0.5.0 ({dir})\n",
git = git_project.url(),
compiling = COMPILING, dir = p.url())));
// We should be able to update transitive deps
assert_that(p.process(cargo_dir().join("cargo-update")).arg("bar"),
execs().with_stdout(format!("{} git repository `{}`",
UPDATING,
git_project.url())));
})
test!(dep_with_submodule {