|
|
f39813 |
From d651281e77120ce4c7431364e4787f08189666b6 Mon Sep 17 00:00:00 2001
|
|
|
f39813 |
From: Richard Hughes <richard@hughsie.com>
|
|
|
f39813 |
Date: Wed, 24 Oct 2018 10:15:00 +0100
|
|
|
f39813 |
Subject: [PATCH 1/2] Add as_utils_vercmp_full() for gnome-software
|
|
|
f39813 |
|
|
|
f39813 |
Sometimes we don't want to do the firmware-style heuristics.
|
|
|
f39813 |
---
|
|
|
f39813 |
libappstream-glib/as-utils.c | 42 ++++++++++++++++++++++++++++--------
|
|
|
f39813 |
libappstream-glib/as-utils.h | 14 ++++++++++++
|
|
|
f39813 |
2 files changed, 47 insertions(+), 9 deletions(-)
|
|
|
f39813 |
|
|
|
f39813 |
diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c
|
|
|
f39813 |
index 29f1637..62d411a 100644
|
|
|
f39813 |
--- a/libappstream-glib/as-utils.c
|
|
|
f39813 |
+++ b/libappstream-glib/as-utils.c
|
|
|
f39813 |
@@ -1388,22 +1388,23 @@ as_utils_vercmp_chunk (const gchar *str1, const gchar *str2)
|
|
|
f39813 |
}
|
|
|
f39813 |
|
|
|
f39813 |
/**
|
|
|
f39813 |
- * as_utils_vercmp:
|
|
|
f39813 |
+ * as_utils_vercmp_full:
|
|
|
f39813 |
* @version_a: the release version, e.g. 1.2.3
|
|
|
f39813 |
* @version_b: the release version, e.g. 1.2.3.1
|
|
|
f39813 |
+ * @flags: some #AsVersionCompareFlag
|
|
|
f39813 |
*
|
|
|
f39813 |
* Compares version numbers for sorting.
|
|
|
f39813 |
*
|
|
|
f39813 |
* Returns: -1 if a < b, +1 if a > b, 0 if they are equal, and %G_MAXINT on error
|
|
|
f39813 |
*
|
|
|
f39813 |
- * Since: 0.3.5
|
|
|
f39813 |
+ * Since: 0.7.14
|
|
|
f39813 |
*/
|
|
|
f39813 |
gint
|
|
|
f39813 |
-as_utils_vercmp (const gchar *version_a, const gchar *version_b)
|
|
|
f39813 |
+as_utils_vercmp_full (const gchar *version_a,
|
|
|
f39813 |
+ const gchar *version_b,
|
|
|
f39813 |
+ AsVersionCompareFlag flags)
|
|
|
f39813 |
{
|
|
|
f39813 |
guint longest_split;
|
|
|
f39813 |
- g_autofree gchar *str_a = NULL;
|
|
|
f39813 |
- g_autofree gchar *str_b = NULL;
|
|
|
f39813 |
g_auto(GStrv) split_a = NULL;
|
|
|
f39813 |
g_auto(GStrv) split_b = NULL;
|
|
|
f39813 |
|
|
|
f39813 |
@@ -1416,10 +1417,15 @@ as_utils_vercmp (const gchar *version_a, const gchar *version_b)
|
|
|
f39813 |
return 0;
|
|
|
f39813 |
|
|
|
f39813 |
/* split into sections, and try to parse */
|
|
|
f39813 |
- str_a = as_utils_version_parse (version_a);
|
|
|
f39813 |
- str_b = as_utils_version_parse (version_b);
|
|
|
f39813 |
- split_a = g_strsplit (str_a, ".", -1);
|
|
|
f39813 |
- split_b = g_strsplit (str_b, ".", -1);
|
|
|
f39813 |
+ if (flags & AS_VERSION_COMPARE_FLAG_USE_HEURISTICS) {
|
|
|
f39813 |
+ g_autofree gchar *str_a = as_utils_version_parse (version_a);
|
|
|
f39813 |
+ g_autofree gchar *str_b = as_utils_version_parse (version_b);
|
|
|
f39813 |
+ split_a = g_strsplit (str_a, ".", -1);
|
|
|
f39813 |
+ split_b = g_strsplit (str_b, ".", -1);
|
|
|
f39813 |
+ } else {
|
|
|
f39813 |
+ split_a = g_strsplit (version_a, ".", -1);
|
|
|
f39813 |
+ split_b = g_strsplit (version_b, ".", -1);
|
|
|
f39813 |
+ }
|
|
|
f39813 |
longest_split = MAX (g_strv_length (split_a), g_strv_length (split_b));
|
|
|
f39813 |
for (guint i = 0; i < longest_split; i++) {
|
|
|
f39813 |
gchar *endptr_a = NULL;
|
|
|
f39813 |
@@ -1456,6 +1462,24 @@ as_utils_vercmp (const gchar *version_a, const gchar *version_b)
|
|
|
f39813 |
return 0;
|
|
|
f39813 |
}
|
|
|
f39813 |
|
|
|
f39813 |
+/**
|
|
|
f39813 |
+ * as_utils_vercmp:
|
|
|
f39813 |
+ * @version_a: the release version, e.g. 1.2.3
|
|
|
f39813 |
+ * @version_b: the release version, e.g. 1.2.3.1
|
|
|
f39813 |
+ *
|
|
|
f39813 |
+ * Compares version numbers for sorting.
|
|
|
f39813 |
+ *
|
|
|
f39813 |
+ * Returns: -1 if a < b, +1 if a > b, 0 if they are equal, and %G_MAXINT on error
|
|
|
f39813 |
+ *
|
|
|
f39813 |
+ * Since: 0.3.5
|
|
|
f39813 |
+ */
|
|
|
f39813 |
+gint
|
|
|
f39813 |
+as_utils_vercmp (const gchar *version_a, const gchar *version_b)
|
|
|
f39813 |
+{
|
|
|
f39813 |
+ return as_utils_vercmp_full (version_a, version_b,
|
|
|
f39813 |
+ AS_VERSION_COMPARE_FLAG_USE_HEURISTICS);
|
|
|
f39813 |
+}
|
|
|
f39813 |
+
|
|
|
f39813 |
/**
|
|
|
f39813 |
* as_ptr_array_find_string:
|
|
|
f39813 |
* @array: gchar* array
|
|
|
f39813 |
diff --git a/libappstream-glib/as-utils.h b/libappstream-glib/as-utils.h
|
|
|
f39813 |
index ecb7cdd..8401df8 100644
|
|
|
f39813 |
--- a/libappstream-glib/as-utils.h
|
|
|
f39813 |
+++ b/libappstream-glib/as-utils.h
|
|
|
f39813 |
@@ -95,6 +95,20 @@ typedef enum {
|
|
|
f39813 |
AS_VERSION_PARSE_FLAG_LAST
|
|
|
f39813 |
} AsVersionParseFlag;
|
|
|
f39813 |
|
|
|
f39813 |
+/**
|
|
|
f39813 |
+ * AsVersionCompareFlag:
|
|
|
f39813 |
+ * @AS_VERSION_COMPARE_FLAG_NONE: No flags set
|
|
|
f39813 |
+ * @AS_VERSION_COMPARE_FLAG_USE_HEURISTICS: Use a heuristic to parse version numbers
|
|
|
f39813 |
+ *
|
|
|
f39813 |
+ * The flags used when comparing version numbers.
|
|
|
f39813 |
+ **/
|
|
|
f39813 |
+typedef enum {
|
|
|
f39813 |
+ AS_VERSION_COMPARE_FLAG_NONE = 0,
|
|
|
f39813 |
+ AS_VERSION_COMPARE_FLAG_USE_HEURISTICS = 1 << 0,
|
|
|
f39813 |
+ /*< private >*/
|
|
|
f39813 |
+ AS_VERSION_COMPARE_FLAG_LAST
|
|
|
f39813 |
+} AsVersionCompareFlag;
|
|
|
f39813 |
+
|
|
|
f39813 |
/**
|
|
|
f39813 |
* AsUniqueIdMatchFlags:
|
|
|
f39813 |
* @AS_UNIQUE_ID_MATCH_FLAG_NONE: No flags set
|
|
|
f39813 |
--
|
|
|
f39813 |
2.19.1
|
|
|
f39813 |
|
|
|
f39813 |
|
|
|
f39813 |
From d8f67b1a9be9707c04ed4f1f71eb5365c09c275d Mon Sep 17 00:00:00 2001
|
|
|
f39813 |
From: Kalev Lember <klember@redhat.com>
|
|
|
f39813 |
Date: Wed, 24 Oct 2018 11:45:56 +0200
|
|
|
f39813 |
Subject: [PATCH 2/2] trivial: Add missing prototype for as_utils_vercmp_full
|
|
|
f39813 |
|
|
|
f39813 |
---
|
|
|
f39813 |
libappstream-glib/as-utils.h | 3 +++
|
|
|
f39813 |
1 file changed, 3 insertions(+)
|
|
|
f39813 |
|
|
|
f39813 |
diff --git a/libappstream-glib/as-utils.h b/libappstream-glib/as-utils.h
|
|
|
f39813 |
index 8401df8..2fa5199 100644
|
|
|
f39813 |
--- a/libappstream-glib/as-utils.h
|
|
|
f39813 |
+++ b/libappstream-glib/as-utils.h
|
|
|
f39813 |
@@ -160,6 +160,9 @@ gboolean as_utils_install_filename (AsUtilsLocation location,
|
|
|
f39813 |
GError **error);
|
|
|
f39813 |
gboolean as_utils_search_token_valid (const gchar *token);
|
|
|
f39813 |
gchar **as_utils_search_tokenize (const gchar *search);
|
|
|
f39813 |
+gint as_utils_vercmp_full (const gchar *version_a,
|
|
|
f39813 |
+ const gchar *version_b,
|
|
|
f39813 |
+ AsVersionCompareFlag flags);
|
|
|
f39813 |
gint as_utils_vercmp (const gchar *version_a,
|
|
|
f39813 |
const gchar *version_b);
|
|
|
f39813 |
gboolean as_utils_guid_is_valid (const gchar *guid);
|
|
|
f39813 |
--
|
|
|
f39813 |
2.19.1
|
|
|
f39813 |
|