Skip to content

Commit

Permalink
fix(resolver): Don't do git fetches when updating workspace members
Browse files Browse the repository at this point in the history
Before, when running `cargo update <member>`, we'd not reuse the
previous resolve result and when the resolver started walking into the
dependencies, it would do a git fetch.

Now, we won't even try to resolve the workspace members and so we won't
look at those dependencies and do git fetch.

This will make `cargo update <workspace-member>`
match `cargo update --workspace`.
I considered whether there were other ways of handling this but I
figured aiming for consistency in approaches was the best way.
We can investigate improving those approaches separately.

There are other discrepancies in the different code paths (handling of
patches, adding sources) but I'm deferring looking over those.

Between this and rust-lang#12602, this should finnally resolve rust-lang#12599.

Fixes rust-lang#12599
  • Loading branch information
epage committed Nov 14, 2023
1 parent 7ff6c0f commit fbe7621
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 20 additions & 0 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
}
}

// Mirror `--workspace` and never avoid workspace members.
// Filtering them out here so the above processes them normally
// so their dependencies can be updated as requested
to_avoid = to_avoid
.into_iter()
.filter(|id| {
for package in ws.members() {
let member_id = package.package_id();
// Skip checking the `version` because `previous_resolve` might have a stale
// value.
// When dealing with workspace members, the other fields should be a
// sufficiently unique match.
if id.name() == member_id.name() && id.source_id() == member_id.source_id() {
return false;
}
}
true
})
.collect();

registry.add_sources(sources)?;
}

Expand Down
8 changes: 1 addition & 7 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,11 +1091,8 @@ rustdns.workspace = true
p.cargo("update -p rootcrate")
.with_stderr(&format!(
"\
[UPDATING] git repository `{}`
[UPDATING] rootcrate v2.29.8 ([CWD]/rootcrate) -> v2.29.81
[UPDATING] rustdns v0.5.0 ([..]) -> [..]
[UPDATING] subcrate v2.29.8 ([CWD]/subcrate) -> v2.29.81",
git_project.url(),
))
.run();
}
Expand Down Expand Up @@ -1182,11 +1179,8 @@ rustdns.workspace = true
p.cargo("update -p crate2")
.with_stderr(&format!(
"\
[UPDATING] git repository `{}`
[UPDATING] crate1 v2.29.8 ([CWD]/crate1) -> v2.29.81
[UPDATING] crate2 v2.29.8 ([CWD]/crate2) -> v2.29.81
[UPDATING] rustdns v0.5.0 ([..]) -> [..]",
git_project.url(),
[UPDATING] crate2 v2.29.8 ([CWD]/crate2) -> v2.29.81",
))
.run();
}
Expand Down

0 comments on commit fbe7621

Please sign in to comment.