Documentation
¶
Overview ¶
Package vercmp provides many different string-based version comparison algorithms, intended to be used a la `strings.Sort`.
The package is designed with the goal in mind of processing hundreds of packages at a time, and therefore calling a given package system's version comparison algorithm lots of times, such as to sort them or resolve their dependencies.
Strings are taken to be version numbers. No parsing or marshalling is done; versions are *strings*. No need to marshal a version string when there are hundreds of such strings to be processed.
The library does not attempt to describe parts of versions, such as major or minor portions. The library simply focuses on comparing versions.
If the version string is compliant, the algorithm is correct.
If the version number is not exactly compliant with the version spec, the algorithm tries its best to compare the strings well anyway. Packages do not always have perfectly compliant version numbers, so it is important to be able to handle some amount of noise when dealing with hundreds of packages.
Index ¶
- func DebianCompare(a string, b string) int
- func MavenCompare(a string, b string) int
- func MavenNormalize(a string) string
- func NaiveCompare(a string, b string) int
- func PythonCompare(a string, b string) int
- func PythonNormalize(a string) string
- func RpmCompare(a string, b string) int
- func RpmNormalize(a string) string
- func RubyCompare(a string, b string) int
- func RubyNormalize(a string) string
- func SemverCompare(a string, b string) int
- func SemverNormalize(a string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebianCompare ¶
Compare two strings as if they were debian package version numbers, as outlined in the Debian Policy Manual: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version Return an integer less than 0 if version `a` is older than version `b`, a positive integer if version `a` compares as newer than version `b`, and 0 otherwise.
Epoch numbers, upstream versions, and debian revision version parts are fully supported.
With the exceptions of `NaiveCompare` and `PythonCompare`, all other vercmp algorithms in vercmp are completely implemented in terms of this function.
func MavenCompare ¶
Compare two maven version numbers. Simply calls `vercmp.MavenNormalize` on the versions and then feeds the results to `vercmp.DebianCompare`.
func MavenNormalize ¶
Convert a maven version number to a debian version number such that the function call
vercmp.DebianCompare(vercmp.MavenNormalize(a),
vercmp.MavenNormalize(b))
would compare two correct maven version numbers correctly.
func NaiveCompare ¶
Compare two version numbers, separated into parts by punctuation. Compare each part in turn. If both parts are numeric, comare them as numbers. If one part is numeric, but the other alphanumeric, the first part is newer. if both are alphanumeric, compare lexically. Continue until one of the parts is newer than the other, and return a -1, 0, or 1 in the usual manner to indicate if the second argument is newer, if they are both equal, or if the first argument is newer, respectively. This is, in fact, the old rpmvercmp algorithm. It is not used in the modern version of rpm; however, it is still used in comparing the local part of the python version comparison algorithm (`vercmp.PythonCompare`).
func PythonCompare ¶
Compare two python (pip) version numbers according to the PEP 440 standard ( https://www.python.org/dev/peps/pep-0440/ ).
First, it calls `PythonNormalize` on each version’s public version identifier part and then returns the `DebianCompare` of the results, provided both version numbers do not contain a local version identifier.
If a local version id is present on one of the version numbers, but both version numbers are otherwise identical, the version with a local version identifier is considered newer. If both have local version ids, but they are otherwise equal, the local version ids are compared using the `NaiveCompare` function.
func PythonNormalize ¶
Convert a python (pip) version number to a debian version number such that the function call
vercmp.DebianCompare(vercmp.PythonNormalize(a),
vercmp.PythonNormalize(b))
would compare two correct python version numbers correctly according to the PEP 440 standard ( https://www.python.org/dev/peps/pep-0440/ ), *for version numbers which do not contain python local version parts*. Version numbers which *do* contain local version parts are handled specially in PythonCompare.
func RpmCompare ¶
Compare two rpm version numbers. Simply calls `vercmp.RpmNormalize` on each version and then feeds the results to `vercmp.DebianCompare`.
Reference implementation: https://github.com/rpm-software-management/rpm/blob/master/lib/rpmvercmp.c
func RpmNormalize ¶
Convert an rpm version number to a debian version number such that the function call
vercmp.DebianCompare(vercmp.RpmNormalize(a),
vercmp.RpmNormalize(b))
would compare two correct rpm version numbers correctly.
Reference implementation: https://github.com/rpm-software-management/rpm/blob/master/lib/rpmvercmp.c
func RubyCompare ¶
Compare two ruby gem version numbers. Simply calls `vercmp.RubyNormalize` on each version and then feeds the results to `vercmp.DebianCompare`.
Reference: http://ruby-doc.org/stdlib-2.0.0/libdoc/rubygems/rdoc/Gem/Version.html
func RubyNormalize ¶
Convert a Ruby Gem ( https://rubygems.org ) version number to a debian version number such that the function call
vercmp.DebianCompare(vercmp.RubyNormalize(a),
vercmp.RubyNormalize(b))
would compare two correct ruby gem version numbers correctly.
Reference: http://ruby-doc.org/stdlib-2.0.0/libdoc/rubygems/rdoc/Gem/Version.html
func SemverCompare ¶
Compare two SemVer version numbers. Simply calls `vercmp.SemverNormalize` on each version and then feeds the results to `vercmp.DebianCompare`.
Reference: http://semver.org/
func SemverNormalize ¶
Convert a SemVer version number to a debian version number such that the function call
vercmp.DebianCompare(vercmp.SemverNormalize(a),
vercmp.SemverNormalize(b))
would compare two correct SemVer version numbers correctly.
Reference: http://semver.org/
Types ¶
This section is empty.