Skip to content

Commit

Permalink
helper to copy a precise from a source
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Oct 18, 2023
1 parent a5549fb commit f7a6a71
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,7 @@ impl Dependency {
// Only update the `precise` of this source to preserve other
// information about dependency's source which may not otherwise be
// tested during equality/hashing.
me.source_id = me
.source_id
.with_precise(id.source_id().precise().map(|s| s.to_string()));
me.source_id = me.source_id.with_precise_from(id.source_id());
self
}

Expand Down
8 changes: 8 additions & 0 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,14 @@ impl SourceId {
})
}

/// Creates a new `SourceId` from this source with the `precise` from some other `SourceId`.
pub fn with_precise_from(self, v: Self) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: v.inner.precise.clone(),
..(*self.inner).clone()
})
}

/// When updating a lock file on a version using `cargo update --precise`
/// the requested version is stored in the precise field.
/// On a registry dependency we also need to keep track of the package that
Expand Down
10 changes: 3 additions & 7 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,8 @@ pub fn resolve_with_previous<'cfg>(
}) {
Some(id_using_default) => {
let id_using_master = id_using_default.with_source_id(
dep.source_id().with_precise(
id_using_default
.source_id()
.precise()
.map(|s| s.to_string()),
),
dep.source_id()
.with_precise_from(id_using_default.source_id()),
);

let mut locked_dep = dep.clone();
Expand Down Expand Up @@ -796,7 +792,7 @@ fn master_branch_git_source(id: PackageId, resolve: &Resolve) -> Option<PackageI
let new_source =
SourceId::for_git(source.url(), GitReference::Branch("master".to_string()))
.unwrap()
.with_precise(source.precise().map(|s| s.to_string()));
.with_precise_from(source);
return Some(id.with_source_id(new_source));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/sources/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
// Attempt to interpret the source name as an alt registry name
if let Ok(alt_id) = SourceId::alt_registry(self.config, name) {
debug!("following pointer to registry {}", name);
break alt_id.with_precise(id.precise().map(str::to_string));
break alt_id.with_precise_from(id);
}
bail!(
"could not find a configured source with the \
Expand All @@ -163,7 +163,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
}
None if id == cfg.id => return id.load(self.config, yanked_whitelist),
None => {
break cfg.id.with_precise(id.precise().map(|s| s.to_string()));
break cfg.id.with_precise_from(id);
}
}
debug!("following pointer to {}", name);
Expand Down

0 comments on commit f7a6a71

Please sign in to comment.