Skip to content

Commit fe0ac50

Browse files
committed
helper to copy a precise from a source
1 parent 8e3caf6 commit fe0ac50

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/cargo/core/dependency.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,7 @@ impl Dependency {
352352
// Only update the `precise` of this source to preserve other
353353
// information about dependency's source which may not otherwise be
354354
// tested during equality/hashing.
355-
me.source_id = me
356-
.source_id
357-
.with_precise(id.source_id().precise().map(|s| s.to_string()));
355+
me.source_id = me.source_id.with_precise_from(id.source_id());
358356
self
359357
}
360358

src/cargo/core/source_id.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,14 @@ impl SourceId {
494494
})
495495
}
496496

497+
/// Creates a new `SourceId` from this source with the `precise` from some other `SourceId`.
498+
pub fn with_precise_from(self, v: Self) -> SourceId {
499+
SourceId::wrap(SourceIdInner {
500+
precise: v.inner.precise.clone(),
501+
..(*self.inner).clone()
502+
})
503+
}
504+
497505
/// When updating a lock file on a version using `cargo update --precise`
498506
/// the requested version is stored in the precise field.
499507
/// On a registry dependency we also need to keep track of the package that

src/cargo/ops/resolve.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,8 @@ pub fn resolve_with_previous<'cfg>(
389389
}) {
390390
Some(id_using_default) => {
391391
let id_using_master = id_using_default.with_source_id(
392-
dep.source_id().with_precise(
393-
id_using_default
394-
.source_id()
395-
.precise()
396-
.map(|s| s.to_string()),
397-
),
392+
dep.source_id()
393+
.with_precise_from(id_using_default.source_id()),
398394
);
399395

400396
let mut locked_dep = dep.clone();
@@ -796,7 +792,7 @@ fn master_branch_git_source(id: PackageId, resolve: &Resolve) -> Option<PackageI
796792
let new_source =
797793
SourceId::for_git(source.url(), GitReference::Branch("master".to_string()))
798794
.unwrap()
799-
.with_precise(source.precise().map(|s| s.to_string()));
795+
.with_precise_from(source);
800796
return Some(id.with_source_id(new_source));
801797
}
802798
}

src/cargo/sources/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
145145
// Attempt to interpret the source name as an alt registry name
146146
if let Ok(alt_id) = SourceId::alt_registry(self.config, name) {
147147
debug!("following pointer to registry {}", name);
148-
break alt_id.with_precise(id.precise().map(str::to_string));
148+
break alt_id.with_precise_from(id);
149149
}
150150
bail!(
151151
"could not find a configured source with the \
@@ -163,7 +163,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
163163
}
164164
None if id == cfg.id => return id.load(self.config, yanked_whitelist),
165165
None => {
166-
break cfg.id.with_precise(id.precise().map(|s| s.to_string()));
166+
break cfg.id.with_precise_from(id);
167167
}
168168
}
169169
debug!("following pointer to {}", name);

0 commit comments

Comments
 (0)