]> git.proxmox.com Git - cargo.git/commitdiff
Allow updating transitive deps
authorAlex Crichton <alex@alexcrichton.com>
Sat, 16 Aug 2014 01:25:12 +0000 (18:25 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 19 Aug 2014 06:43:27 +0000 (23:43 -0700)
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.

src/cargo/ops/cargo_generate_lockfile.rs
tests/test_cargo_compile_git_deps.rs

index 9bf5c126060b41235cc31cf441d9aecb49195c33..1e10f53d39f297e4ff06e865e79e808fb5e42726 100644 (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()
index cfb4c87d08e1d3ee22eaa246b80151e07cefd40b..5219e4f79bed245f71ed00c21b20b7ff7ebed9a2 100644 (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 {