Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support leading-zero logic #15

Open
mathstuf opened this issue Jun 29, 2019 · 4 comments
Open

Support leading-zero logic #15

mathstuf opened this issue Jun 29, 2019 · 4 comments

Comments

@mathstuf
Copy link

The GNU extension function strverscmp supports counting leading zeroes. This would be nice to support here as well. http://man7.org/linux/man-pages/man3/strverscmp.3.html

000 < 001 < 002 < 0010 < 01 < 0

@timvisee
Copy link
Owner

timvisee commented Jun 29, 2019

Interesting, never heard about strverscmp.

Though I'd like to support this, I don't currently think the library allows adding support for this in it's current state (without drastic modifications).

I've already wanted to do a full rewrite of version-compare in an attempt to make it more flexible, to allow support for other versioning schematics such as this one. I have not yet had the time to do that though. I'll be sure to keep an eye on this once I start redesigning it, and it's highly likely I'll add direct support for this versioning schematic then behind a simple toggle.

So, I'm afraid I can't implement support for this right now. Sorry for that. Thank you for suggesting this.

@mathstuf
Copy link
Author

mathstuf commented Jul 8, 2019

That makes sense. It might make sense to have support for multiple version string interpretations. Off-hand I can think of:

  • semver (x.y.z)
  • GNU (leading zeroes matter)
  • rpm ([epoch:]version-release)
  • dpkg (~ is for "negative" versions)
  • old Perl (treat as a floating point number; no longer in use today)

Given a schema, a string can be parsed using that and compared with those using a "compatible" versioning scheme. This could come with "satisfies" queries using the ~, ^, and * operators of semver or other "operators" that may make sense in other versioning schemes.

@timvisee
Copy link
Owner

timvisee commented Jul 8, 2019

Exactly. Thank you for mentioning these other version schemes as well.

I'm wondering what a good (portable and extendable) abstraction would be for this, that would be (almost) as easy to use as the current API specification. Something that would support any versioning format, for which parts are comparable as defined by some function, would be preferred to allow setting up your own scheme, even at runtime. The current implementation has something called a 'Version Manifest' which is intended for configuring version formats, but that isn't really used right now (nor does it provide the desired functionality as described above).

Query operators are something I want to support as well, yes. I'm assuming different schemes can have different operators. So, a similar configurable abstraction would be required for this as well.

I'll have to build some sort of truth-table having some arbitrary version formats some time. That would be a good start for thinking about a proper design as well. But I did not have the time yet to work on rebuilding this crate.

@mathstuf
Copy link
Author

mathstuf commented Jul 8, 2019

Just whinging it here:

trait VersionScheme: FromStr {
    fn cmp(&self, rhs: &Self) -> Ordering;
}

impl<T: VersionScheme> PartialEq for T {
    // use `VersionScheme::cmp`
}

impl<T: VersionScheme> Eq for T {
}

impl<T: VersionScheme> PartialOrd for T {
    // use `VersionScheme::cmp`
}

impl<T: VersionScheme> Ord for T {
    // use `VersionScheme::cmp`
}

trait SatisifiableVersion: VersionScheme {
    type Query;
    fn satisfies(&self, q: &Query) -> bool;
}

Schemes can also implement PartialOrd for other schemes as they see fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants