mirror of https://github.com/astral-sh/uv
Refactored Refresh::combine (#15609)
This commit is contained in:
parent
22f80ca00d
commit
36216363eb
|
|
@ -1217,35 +1217,30 @@ impl Refresh {
|
||||||
/// Combine two [`Refresh`] policies, taking the "max" of the two policies.
|
/// Combine two [`Refresh`] policies, taking the "max" of the two policies.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn combine(self, other: Self) -> Self {
|
pub fn combine(self, other: Self) -> Self {
|
||||||
/// Return the maximum of two timestamps.
|
|
||||||
fn max(a: Timestamp, b: Timestamp) -> Timestamp {
|
|
||||||
if a > b { a } else { b }
|
|
||||||
}
|
|
||||||
|
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
// If the policy is `None`, return the existing refresh policy.
|
// If the policy is `None`, return the existing refresh policy.
|
||||||
// Take the `max` of the two timestamps.
|
// Take the `max` of the two timestamps.
|
||||||
(Self::None(t1), Self::None(t2)) => Self::None(max(t1, t2)),
|
(Self::None(t1), Self::None(t2)) => Self::None(t1.max(t2)),
|
||||||
(Self::None(t1), Self::All(t2)) => Self::All(max(t1, t2)),
|
(Self::None(t1), Self::All(t2)) => Self::All(t1.max(t2)),
|
||||||
(Self::None(t1), Self::Packages(packages, paths, t2)) => {
|
(Self::None(t1), Self::Packages(packages, paths, t2)) => {
|
||||||
Self::Packages(packages, paths, max(t1, t2))
|
Self::Packages(packages, paths, t1.max(t2))
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the policy is `All`, refresh all packages.
|
// If the policy is `All`, refresh all packages.
|
||||||
(Self::All(t1), Self::None(t2)) => Self::All(max(t1, t2)),
|
(Self::All(t1), Self::None(t2) | Self::All(t2) | Self::Packages(.., t2)) => {
|
||||||
(Self::All(t1), Self::All(t2)) => Self::All(max(t1, t2)),
|
Self::All(t1.max(t2))
|
||||||
(Self::All(t1), Self::Packages(.., t2)) => Self::All(max(t1, t2)),
|
}
|
||||||
|
|
||||||
// If the policy is `Packages`, take the "max" of the two policies.
|
// If the policy is `Packages`, take the "max" of the two policies.
|
||||||
(Self::Packages(packages, paths, t1), Self::None(t2)) => {
|
(Self::Packages(packages, paths, t1), Self::None(t2)) => {
|
||||||
Self::Packages(packages, paths, max(t1, t2))
|
Self::Packages(packages, paths, t1.max(t2))
|
||||||
}
|
}
|
||||||
(Self::Packages(.., t1), Self::All(t2)) => Self::All(max(t1, t2)),
|
(Self::Packages(.., t1), Self::All(t2)) => Self::All(t1.max(t2)),
|
||||||
(Self::Packages(packages1, paths1, t1), Self::Packages(packages2, paths2, t2)) => {
|
(Self::Packages(packages1, paths1, t1), Self::Packages(packages2, paths2, t2)) => {
|
||||||
Self::Packages(
|
Self::Packages(
|
||||||
packages1.into_iter().chain(packages2).collect(),
|
packages1.into_iter().chain(packages2).collect(),
|
||||||
paths1.into_iter().chain(paths2).collect(),
|
paths1.into_iter().chain(paths2).collect(),
|
||||||
max(t1, t2),
|
t1.max(t2),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue