Skip to content

Commit

Permalink
dont call wrap in a no-op source_id::with*
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Jul 29, 2024
1 parent a7c4206 commit d2d2102
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,34 +468,51 @@ impl SourceId {

/// Creates a new `SourceId` from this source with the given `precise`.
pub fn with_git_precise(self, fragment: Option<String>) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: fragment.map(|f| Precise::GitUrlFragment(f)),
..(*self.inner).clone()
})
let precise = fragment.map(|f| Precise::GitUrlFragment(f));
if self.inner.precise == precise {
self
} else {
SourceId::wrap(SourceIdInner {
precise,
..(*self.inner).clone()
})
}
}

/// Creates a new `SourceId` from this source without a `precise`.
pub fn without_precise(self) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: None,
..(*self.inner).clone()
})
if self.inner.precise.is_none() {
self
} else {
SourceId::wrap(SourceIdInner {
precise: None,
..(*self.inner).clone()
})
}
}

/// Creates a new `SourceId` from this source without a `precise`.
pub fn with_locked_precise(self) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: Some(Precise::Locked),
..(*self.inner).clone()
})
if self.inner.precise == Some(Precise::Locked) {
self
} else {
SourceId::wrap(SourceIdInner {
precise: Some(Precise::Locked),
..(*self.inner).clone()
})
}
}

/// 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()
})
if self.inner.precise == v.inner.precise {
self
} else {
SourceId::wrap(SourceIdInner {
precise: v.inner.precise.clone(),
..(*self.inner).clone()
})
}
}

/// When updating a lock file on a version using `cargo update --precise`
Expand Down

0 comments on commit d2d2102

Please sign in to comment.