util: add a version comparison class based on rpm version rules
This (strives to) implement the same algorithm that rpm uses [1]. All strings are accepted, and the answer is always -1, 0, or +1. This should be also compatible with Debian rules: Debian doesn't allow ^ in versions, but otherwise follows similar rules. The addition of ~ in rpm was modelled after Debian. If Debian adds support for ^ in the future, hopefully it'll be in a way that is compatible. (rpm and deb have different rules how to split the package name version parts, but this shouldn't matter for us, since we're only looking at the version part here.) For all not overly complicated strings this should generally return the result that people expect. For some of the corner cases the results might be nonobvious, but I think it's better to follow one established standard than to try to come up with something fresh. [1] So… I should put a link to some docs here. But I don't think the are is any reference for this. Oh, rpm :---[ https://github.com/rpm-software-management/rpm/blob/master/rpmio/rpmvercmp.c#L12 [2] https://www.debian.org/doc/debian-policy/ch-controlfields.html#version Note on the copyright: I wrote this from scratch based on my understanding of the rules and examples online and the (scant) documentation that is online. The example list is copied from rpm tests, but the way that the examples are structured and invoked is completely different. The only part that was carried over are the version strings to test, so I think it's reasonable to treat this as an indepedent work.
Loading
Please register or sign in to comment