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

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