[PATCH] Add support for ~ in versions from upstream rpmvercmp

Dan Nicholson dbn.lists at gmail.com
Fri May 25 12:46:34 PDT 2012


Allows use of dpkg-style sorting of versions where '~' implies a
pre-release. See upstream bug and commit:

http://rpm.org/ticket/56
http://rpm.org/gitweb?p=rpm.git;a=commit;h=db28221
---
 check/check-version |   16 ++++++++++++++++
 check/tilde.pc      |   11 +++++++++++
 pkg.c               |   15 ++++++++++++---
 3 files changed, 39 insertions(+), 3 deletions(-)
 create mode 100644 check/tilde.pc

diff --git a/check/check-version b/check/check-version
index 6e92077..df879cc 100755
--- a/check/check-version
+++ b/check/check-version
@@ -105,3 +105,19 @@ ARGS="--exists --print-errors --max-version=$v3 simple"
 EXPECT_RETURN=0
 RESULT=""
 run_test
+
+# check handling of ~ in version
+ARGS="--exists --print-errors tilde <= 1.0.0"
+EXPECT_RETURN=0
+RESULT=""
+run_test
+
+ARGS="--exists --print-errors tilde = 1.0.0~rc1"
+EXPECT_RETURN=0
+RESULT=""
+run_test
+
+ARGS="--exists --print-errors tilde >= 1.0.0"
+EXPECT_RETURN=1
+RESULT="Requested 'tilde >= 1.0.0' but version of Tilde version test is 1.0.0~rc1"
+run_test
diff --git a/check/tilde.pc b/check/tilde.pc
new file mode 100644
index 0000000..10e8db0
--- /dev/null
+++ b/check/tilde.pc
@@ -0,0 +1,11 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: Tilde version test
+Description: Test package for checking rpmvercmp ~ handling
+Version: 1.0.0~rc1
+Requires:
+Libs: -L${libdir} -ltilde
+Cflags: -I${includedir}
diff --git a/pkg.c b/pkg.c
index 551b867..3238689 100644
--- a/pkg.c
+++ b/pkg.c
@@ -1286,9 +1286,18 @@ static int rpmvercmp(const char * a, const char * b) {
     two = str2;
 
     /* loop through each version segment of str1 and str2 and compare them */
-    while (*one && *two) {
-	while (*one && !isalnum((guchar)*one)) one++;
-	while (*two && !isalnum((guchar)*two)) two++;
+    while (*one || *two) {
+	while (*one && !isalnum((guchar)*one) && *one != '~') one++;
+	while (*two && !isalnum((guchar)*two) && *two != '~') two++;
+
+	/* handle the tilde separator, it sorts before everthing else */
+	if (*one == '~' || *two == '~') {
+	  if (*one != '~') return 1;
+	  if (*two != '~') return -1;
+	  one++;
+	  two++;
+	  continue;
+	}
 
 	/* If we ran to the end of either, we are finished with the loop */
 	if (!(*one && *two)) break;
-- 
1.7.7.6



More information about the pkg-config mailing list