Code for Debian versions comparison?

Do you know code that compare versions of debian packages (for example, that knows if 2:23.2.3~rc1-1 is lower than 2:23.2.3-2?), besides dpkg –compare-versions? If yes, please write a comment to this blog post, preferably with a link to the code.

Also, did someone already write a test suite for that? Who would be interested in such a test suite?

I’m considering writing a function in PL/SQL to compare debian versions (for the Ultimate Debian Database project). If someone already wrote that, I’m interested as well.

10 thoughts on “Code for Debian versions comparison?

  1. Dpkg has the code both in C (in lib/vercmp.c, function verrevcmp) and Perl (in scripts/Dpkg/Version.pm). The Perl one is actually just a translation to Perl of the C version, so the algorithm should be identical.

    Apt has probably its own version.

  2. The python-debian library has an access point to code comparison for Python, which is actually implemented by python-apt, a binding to libapt.

    In the Sodiac project (http://gforge.inria.fr/projects/sodiac/), which contains the various tool of the EDOS toolchain, there is an OCaml implementation of Debian version comparison.

  3. libapt-pkg implements version comparison as well. You get it by:

    #include

    Then debVS.CmpVersion(“2:23.2.3~rc1-1”, “2:23.2.3-2”) works like strcmp.

    The code is in apt sources, in apt-pkg/deb/debversion.cc

    libapt-pkg has also a test case: in the apt sources, it’s in test/versionstest.cc and it uses the data in test/versions.lst

  4. what you include is apt-pkg/debversion.h

    Blog softwares with no preview nor a way to edit one’s comments are probably designed to maximise frustration.

  5. dak (debian archive kit) has an plugin for postgresql doing that (which just links the relevant code from IIRC apt in).

  6. in python-apt:
    import apt_pkg
    apt_pkg.InitSystem()
    apt_pkg.VersionCompare(“1.2”, “1.2~3”)

    (use sign of result to check whether version are higher/lower etc.)

Comments are closed.