Blame SOURCES/0003-Add-support-for-sorting-caret-higher-than-base-versi.patch

ed184b
From c7e711bba58374f03347c795a567441cbef3de58 Mon Sep 17 00:00:00 2001
ed184b
Message-Id: <c7e711bba58374f03347c795a567441cbef3de58.1574338784.git.pmatilai@redhat.com>
ed184b
In-Reply-To: <871065ddd493c76d80345d2e80b38b9ce4c7acdd.1574338784.git.pmatilai@redhat.com>
ed184b
References: <871065ddd493c76d80345d2e80b38b9ce4c7acdd.1574338784.git.pmatilai@redhat.com>
ed184b
From: Igor Gnatenko <i.gnatenko.brain@gmail.com>
ed184b
Date: Sat, 10 Sep 2016 11:39:23 +0200
ed184b
Subject: [PATCH 3/3] Add support for sorting caret ('^') higher than base
ed184b
 version
ed184b
ed184b
1.1^20160101 means 1.1 version (base) and patches which were applied at
ed184b
that date on top of it.
ed184b
ed184b
* 1.1^201601 > 1.1
ed184b
* 1.1^201601 < 1.1.1
ed184b
ed184b
Having symmetry is also good.
ed184b
ed184b
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
ed184b
---
ed184b
 build/pack.c       |  4 ++++
ed184b
 lib/rpmds.c        |  3 +++
ed184b
 lib/rpmvercmp.c    | 19 +++++++++++++++++--
ed184b
 tests/rpmvercmp.at | 26 ++++++++++++++++++++++++++
ed184b
 4 files changed, 50 insertions(+), 2 deletions(-)
ed184b
ed184b
diff --git a/build/pack.c b/build/pack.c
ed184b
index c94964be2..d7adcb0e2 100644
ed184b
--- a/build/pack.c
ed184b
+++ b/build/pack.c
ed184b
@@ -354,6 +354,10 @@ static void finalizeDeps(Package pkg)
ed184b
     if (haveCharInDep(pkg, '~'))
ed184b
 	(void) rpmlibNeedsFeature(pkg, "TildeInVersions", "4.10.0-1");
ed184b
 
ed184b
+    /* check if the package has a dependency with a '^' */
ed184b
+    if (haveCharInDep(pkg, '^'))
ed184b
+	(void) rpmlibNeedsFeature(pkg, "CaretInVersions", "4.15.0-1");
ed184b
+
ed184b
     /* check if the package has a rich dependency */
ed184b
     if (haveRichDep(pkg))
ed184b
 	(void) rpmlibNeedsFeature(pkg, "RichDependencies", "4.12.0-1");
ed184b
diff --git a/lib/rpmds.c b/lib/rpmds.c
ed184b
index 01aa1022b..730a58c35 100644
ed184b
--- a/lib/rpmds.c
ed184b
+++ b/lib/rpmds.c
ed184b
@@ -1240,6 +1240,9 @@ static const struct rpmlibProvides_s rpmlibProvides[] = {
ed184b
     { "rpmlib(TildeInVersions)",    "4.10.0-1",
ed184b
 	(		RPMSENSE_EQUAL),
ed184b
     N_("dependency comparison supports versions with tilde.") },
ed184b
+    { "rpmlib(CaretInVersions)",    "4.15.0-1",
ed184b
+	(		RPMSENSE_EQUAL),
ed184b
+    N_("dependency comparison supports versions with caret.") },
ed184b
     { "rpmlib(LargeFiles)", 	"4.12.0-1",
ed184b
 	(		RPMSENSE_EQUAL),
ed184b
     N_("support files larger than 4GB") },
ed184b
diff --git a/lib/rpmvercmp.c b/lib/rpmvercmp.c
ed184b
index b3d08faa4..13857e151 100644
ed184b
--- a/lib/rpmvercmp.c
ed184b
+++ b/lib/rpmvercmp.c
ed184b
@@ -33,8 +33,8 @@ int rpmvercmp(const char * a, const char * b)
ed184b
 
ed184b
     /* loop through each version segment of str1 and str2 and compare them */
ed184b
     while (*one || *two) {
ed184b
-	while (*one && !risalnum(*one) && *one != '~') one++;
ed184b
-	while (*two && !risalnum(*two) && *two != '~') two++;
ed184b
+	while (*one && !risalnum(*one) && *one != '~' && *one != '^') one++;
ed184b
+	while (*two && !risalnum(*two) && *two != '~' && *two != '^') two++;
ed184b
 
ed184b
 	/* handle the tilde separator, it sorts before everything else */
ed184b
 	if (*one == '~' || *two == '~') {
ed184b
@@ -45,6 +45,21 @@ int rpmvercmp(const char * a, const char * b)
ed184b
 	    continue;
ed184b
 	}
ed184b
 
ed184b
+	/*
ed184b
+	 * Handle caret separator. Concept is the same as tilde,
ed184b
+	 * except that if one of the strings ends (base version),
ed184b
+	 * the other is considered as higher version.
ed184b
+	 */
ed184b
+	if (*one == '^' || *two == '^') {
ed184b
+	    if (!*one) return -1;
ed184b
+	    if (!*two) return 1;
ed184b
+	    if (*one != '^') return 1;
ed184b
+	    if (*two != '^') return -1;
ed184b
+	    one++;
ed184b
+	    two++;
ed184b
+	    continue;
ed184b
+	}
ed184b
+
ed184b
 	/* If we ran to the end of either, we are finished with the loop */
ed184b
 	if (!(*one && *two)) break;
ed184b
 
ed184b
diff --git a/tests/rpmvercmp.at b/tests/rpmvercmp.at
ed184b
index 8b32209aa..1e7c960ea 100644
ed184b
--- a/tests/rpmvercmp.at
ed184b
+++ b/tests/rpmvercmp.at
ed184b
@@ -102,6 +102,32 @@ RPMVERCMP(1.0~rc1~git123, 1.0~rc1~git123, 0)
ed184b
 RPMVERCMP(1.0~rc1~git123, 1.0~rc1, -1)
ed184b
 RPMVERCMP(1.0~rc1, 1.0~rc1~git123, 1)
ed184b
 
ed184b
+dnl Basic testcases for caret sorting
ed184b
+RPMVERCMP(1.0^, 1.0^, 0)
ed184b
+RPMVERCMP(1.0^, 1.0, 1)
ed184b
+RPMVERCMP(1.0, 1.0^, -1)
ed184b
+RPMVERCMP(1.0^git1, 1.0^git1, 0)
ed184b
+RPMVERCMP(1.0^git1, 1.0, 1)
ed184b
+RPMVERCMP(1.0, 1.0^git1, -1)
ed184b
+RPMVERCMP(1.0^git1, 1.0^git2, -1)
ed184b
+RPMVERCMP(1.0^git2, 1.0^git1, 1)
ed184b
+RPMVERCMP(1.0^git1, 1.01, -1)
ed184b
+RPMVERCMP(1.01, 1.0^git1, 1)
ed184b
+RPMVERCMP(1.0^20160101, 1.0^20160101, 0)
ed184b
+RPMVERCMP(1.0^20160101, 1.0.1, -1)
ed184b
+RPMVERCMP(1.0.1, 1.0^20160101, 1)
ed184b
+RPMVERCMP(1.0^20160101^git1, 1.0^20160101^git1, 0)
ed184b
+RPMVERCMP(1.0^20160102, 1.0^20160101^git1, 1)
ed184b
+RPMVERCMP(1.0^20160101^git1, 1.0^20160102, -1)
ed184b
+
ed184b
+dnl Basic testcases for tilde and caret sorting
ed184b
+RPMVERCMP(1.0~rc1^git1, 1.0~rc1^git1, 0)
ed184b
+RPMVERCMP(1.0~rc1^git1, 1.0~rc1, 1)
ed184b
+RPMVERCMP(1.0~rc1, 1.0~rc1^git1, -1)
ed184b
+RPMVERCMP(1.0^git1~pre, 1.0^git1~pre, 0)
ed184b
+RPMVERCMP(1.0^git1, 1.0^git1~pre, 1)
ed184b
+RPMVERCMP(1.0^git1~pre, 1.0^git1, -1)
ed184b
+
ed184b
 dnl These are included here to document current, arguably buggy behaviors
ed184b
 dnl for reference purposes and for easy checking against  unintended
ed184b
 dnl behavior changes.
ed184b
-- 
ed184b
2.23.0
ed184b