Skip to content

Commit

Permalink
update to handle majors > 1996 as calver
Browse files Browse the repository at this point in the history
libpkgx handles calver as strictly less than semver, though this can also cause issues.
  • Loading branch information
jhheider committed Mar 18, 2024
1 parent 932f4e1 commit ce1b0f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "semverator"
version = "0.4.3"
version = "0.5.0"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
Expand Down
30 changes: 17 additions & 13 deletions src/semver/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ impl Semver {
self.compare(other) == Ordering::Less
}

// Treat majors >1996 as calver, and less than 0.0.0.
fn handle_calver(&self) -> Vec<usize> {
if self.major < 1996 || self.major == usize::MAX {
self.components.clone()
} else {
let mut cmps = vec![0, 0, 0];
cmps.extend(self.components.iter().cloned());
cmps
}
}

fn compare(&self, other: &Semver) -> Ordering {
let len = self.components.len().max(other.components.len());
let acmps = self.handle_calver();
let bcmps = other.handle_calver();

let len = acmps.len().max(bcmps.len());
for x in 0..len {
if x == 0 {
match (
self.major > 1900 && self.major < usize::MAX,
other.major > 1900 && other.major < usize::MAX,
) {
(true, false) => return Ordering::Less,
(false, true) => return Ordering::Greater,
_ => (),
}
}
let a = self.components.get(x);
let b = other.components.get(x);
let a = acmps.get(x);
let b = bcmps.get(x);
match (a, b) {
(None, _) => return Ordering::Less,
(_, None) => return Ordering::Greater,
Expand Down

0 comments on commit ce1b0f3

Please sign in to comment.