[PATCH 5/5] Add support for ~ in versions from upstream rpmvercmp
Dan Nicholson
dbn.lists at gmail.com
Sat Apr 20 09:41:58 PDT 2013
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/Makefile.am | 3 ++-
check/check-version | 13 +++++++++++++
check/tilde-version.pc | 3 +++
rpmvercmp.c | 15 ++++++++++++---
4 files changed, 30 insertions(+), 4 deletions(-)
create mode 100644 check/tilde-version.pc
diff --git a/check/Makefile.am b/check/Makefile.am
index 5006b5f..c947a19 100644
--- a/check/Makefile.am
+++ b/check/Makefile.am
@@ -92,4 +92,5 @@ EXTRA_DIST = \
gtk/xcb.pc \
gtk/xproto.pc \
gtk/xrender.pc \
- tilde.pc
+ tilde.pc \
+ tilde-version.pc
diff --git a/check/check-version b/check/check-version
index a940c37..967c723 100755
--- a/check/check-version
+++ b/check/check-version
@@ -95,3 +95,16 @@ run_test --print-errors --max-version=$v3 simple
EXPECT_RETURN=0
RESULT='Ignoring incompatible output option "--exact-version"'
run_test --atleast-version=1.0.0 --exact-version=1.0.0 simple
+
+# check handling of ~ in version
+EXPECT_RETURN=0
+RESULT=""
+run_test --exists --print-errors tilde-version \<= 1.0.0
+
+EXPECT_RETURN=0
+RESULT=""
+run_test --exists --print-errors tilde-version = 1.0.0~rc1
+
+EXPECT_RETURN=1
+RESULT="Requested 'tilde-version >= 1.0.0' but version of Tilde version test is 1.0.0~rc1"
+run_test --exists --print-errors tilde-version \>= 1.0.0
diff --git a/check/tilde-version.pc b/check/tilde-version.pc
new file mode 100644
index 0000000..10fc98e
--- /dev/null
+++ b/check/tilde-version.pc
@@ -0,0 +1,3 @@
+Name: Tilde version test
+Description: Test package for checking rpmvercmp ~ handling
+Version: 1.0.0~rc1
diff --git a/rpmvercmp.c b/rpmvercmp.c
index 50d56ac..3ac45ba 100644
--- a/rpmvercmp.c
+++ b/rpmvercmp.c
@@ -53,9 +53,18 @@ 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 && !risalnum(*one)) one++;
- while (*two && !risalnum(*two)) two++;
+ while (*one || *two) {
+ while (*one && !risalnum(*one) && *one != '~') one++;
+ while (*two && !risalnum(*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.8.1.4
More information about the pkg-config
mailing list