Imported Upstream version 0.7.4
[platform/upstream/libsolv.git] / src / evr.c
index 30dacfb..afd5fc5 100644 (file)
--- a/src/evr.c
+++ b/src/evr.c
@@ -17,6 +17,9 @@
 #include "evr.h"
 #include "pool.h"
 
+#ifdef ENABLE_CONDA
+#include "conda.h"
+#endif
 
 
 #if defined(DEBIAN) || defined(MULTI_SEMANTICS)
@@ -77,10 +80,10 @@ solv_vercmp_rpm(const char *s1, const char *q1, const char *s2, const char *q2)
   for (;;)
     {
       while (s1 < q1 && !(*s1 >= '0' && *s1 <= '9') &&
-          !(*s1 >= 'a' && *s1 <= 'z') && !(*s1 >= 'A' && *s1 <= 'Z') && *s1 != '~')
+          !(*s1 >= 'a' && *s1 <= 'z') && !(*s1 >= 'A' && *s1 <= 'Z') && *s1 != '~' && *s1 != '^')
        s1++;
       while (s2 < q2 && !(*s2 >= '0' && *s2 <= '9') &&
-          !(*s2 >= 'a' && *s2 <= 'z') && !(*s2 >= 'A' && *s2 <= 'Z') && *s2 != '~')
+          !(*s2 >= 'a' && *s2 <= 'z') && !(*s2 >= 'A' && *s2 <= 'Z') && *s2 != '~' && *s2 != '^')
        s2++;
       if (s1 < q1 && *s1 == '~')
         {
@@ -94,6 +97,18 @@ solv_vercmp_rpm(const char *s1, const char *q1, const char *s2, const char *q2)
         }
       if (s2 < q2 && *s2 == '~')
        return 1;
+      if (s1 < q1 && *s1 == '^')
+       {
+         if (s2 < q2 && *s2 == '^')
+           {
+             s1++;
+             s2++;
+             continue;
+           }
+         return s2 < q2 ? -1 : 1;
+       }
+      if (s2 < q2 && *s2 == '^')
+       return s1 < q1 ? 1 : -1;
       if (s1 >= q1 || s2 >= q2)
        break;
       if ((*s1 >= '0' && *s1 <= '9') || (*s2 >= '0' && *s2 <= '9'))
@@ -242,7 +257,7 @@ solv_cmp_version_part_haiku(const char *s1, const char *q1, const char *s2,
 
       while (part1 + 1 < s1 && *part1 == '0')
         part1++;
-      while (part2 + 1 < s1 && *part2 == '0')
+      while (part2 + 1 < s2 && *part2 == '0')
         part2++;
 
       len1 = s1 - part1;
@@ -268,9 +283,9 @@ solv_vercmp_haiku(const char *s1, const char *q1, const char *s2, const char *q2
   int cmp;
 
   /* find pre-release separator */
-  while (pre1 != q1 && *pre1 != '-')
+  while (pre1 != q1 && *pre1 != '~')
     pre1++;
-  while (pre2 != q2 && *pre2 != '-')
+  while (pre2 != q2 && *pre2 != '~')
     pre2++;
 
   /* compare main versions */
@@ -284,13 +299,14 @@ solv_vercmp_haiku(const char *s1, const char *q1, const char *s2, const char *q2
   if (pre2 == q2)
     return -1;
 
-  return solv_cmp_version_part_haiku(pre1 + 1, q1, pre2 + 1, q2);
+  cmp = solv_cmp_version_part_haiku(pre1 + 1, q1, pre2 + 1, q2);
+  return cmp == 0 ? 0 : cmp < 0 ? -1 : 1; /* must return -1, 0, or 1 */
 }
 
 #endif /* HAIKU */
-/* 
+
+
+/*
  * the solv_vercmp variant your system uses.
  */
 int
@@ -309,7 +325,7 @@ solv_vercmp(const char *s1, const char *q1, const char *s2, const char *q2)
 
 #if defined(MULTI_SEMANTICS)
 # define solv_vercmp (*(pool->disttype == DISTTYPE_DEB ? &solv_vercmp_deb : \
-                        pool->disttype == DISTTYPE_HAIKU ? solv_vercmp_haiku : \
+                        pool->disttype == DISTTYPE_HAIKU ? &solv_vercmp_haiku : \
                         &solv_ver##cmp_rpm))
 #elif defined(DEBIAN)
 # define solv_vercmp solv_vercmp_deb
@@ -332,6 +348,11 @@ pool_evrcmp_str(const Pool *pool, const char *evr1, const char *evr2, int mode)
   if (evr1 == evr2)
     return 0;
 
+#ifdef ENABLE_CONDA
+  if (pool->disttype == DISTTYPE_CONDA)
+    return pool_evrcmp_conda(pool, evr1, evr2, mode);
+#endif
+
 #if 0
   POOL_DEBUG(DEBUG_EVRCMP, "evrcmp %s %s mode=%d\n", evr1, evr2, mode);
 #endif
@@ -390,7 +411,6 @@ pool_evrcmp_str(const Pool *pool, const char *evr1, const char *evr2, int mode)
   for (s2 = evr2, r2 = 0; *s2; s2++)
     if (*s2 == '-')
       r2 = s2;
-
   r = 0;
   if (mode != EVRCMP_MATCH || (evr1 != (r1 ? r1 : s1) && evr2 != (r2 ? r2 : s2)))
     r = solv_vercmp(evr1, r1 ? r1 : s1, evr2, r2 ? r2 : s2);