Allow going back to the 'default' branch

We only want to translate a NULL branch into 'default' for display, and not
actually store it in the GPtrArray.
This commit is contained in:
Richard Hughes 2021-01-20 16:15:29 +00:00
parent 814a5ee874
commit 89ee9edc0a
4 changed files with 25 additions and 15 deletions

View File

@ -2569,6 +2569,11 @@ fu_util_esp_list (FuUtilPrivate *priv, gchar **values, GError **error)
return TRUE; return TRUE;
} }
static gboolean
_g_str_equal0 (gconstpointer str1, gconstpointer str2)
{
return g_strcmp0 (str1, str2) == 0;
}
static gboolean static gboolean
fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error) fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error)
@ -2615,10 +2620,10 @@ fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error)
/* get all the unique branches */ /* get all the unique branches */
for (guint i = 0; i < rels->len; i++) { for (guint i = 0; i < rels->len; i++) {
FwupdRelease *rel_tmp = g_ptr_array_index (rels, i); FwupdRelease *rel_tmp = g_ptr_array_index (rels, i);
const gchar *branch_tmp = fu_util_release_get_branch (rel_tmp); const gchar *branch_tmp = fwupd_release_get_branch (rel_tmp);
#if GLIB_CHECK_VERSION(2,54,3) #if GLIB_CHECK_VERSION(2,54,3)
if (g_ptr_array_find_with_equal_func (branches, branch_tmp, if (g_ptr_array_find_with_equal_func (branches, branch_tmp,
g_str_equal, NULL)) _g_str_equal0, NULL))
continue; continue;
#endif #endif
g_ptr_array_add (branches, g_strdup (branch_tmp)); g_ptr_array_add (branches, g_strdup (branch_tmp));
@ -2639,7 +2644,7 @@ fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error)
g_print ("0.\t%s\n", _("Cancel")); g_print ("0.\t%s\n", _("Cancel"));
for (guint i = 0; i < branches->len; i++) { for (guint i = 0; i < branches->len; i++) {
const gchar *branch_tmp = g_ptr_array_index (branches, i); const gchar *branch_tmp = g_ptr_array_index (branches, i);
g_print ("%u.\t%s\n", i + 1, branch_tmp); g_print ("%u.\t%s\n", i + 1, fu_util_branch_for_display (branch_tmp));
} }
idx = fu_util_prompt_for_number (branches->len); idx = fu_util_prompt_for_number (branches->len);
if (idx == 0) { if (idx == 0) {
@ -2659,7 +2664,7 @@ fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error)
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
"Device %s is already on branch %s", "Device %s is already on branch %s",
fu_device_get_name (dev), fu_device_get_name (dev),
branch); fu_util_branch_for_display (branch));
return FALSE; return FALSE;
} }
@ -2676,7 +2681,7 @@ fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error)
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
"No releases for branch %s", "No releases for branch %s",
branch); fu_util_branch_for_display (branch));
return FALSE; return FALSE;
} }

View File

@ -601,14 +601,13 @@ fu_util_cmd_array_to_string (GPtrArray *array)
} }
const gchar * const gchar *
fu_util_release_get_branch (FwupdRelease *release) fu_util_branch_for_display (const gchar *branch)
{ {
const gchar *tmp = fwupd_release_get_branch (release); if (branch == NULL) {
if (tmp == NULL) {
/* TRANSLATORS: this is the default branch name when unset */ /* TRANSLATORS: this is the default branch name when unset */
return _("default"); return _("default");
} }
return tmp; return branch;
} }
gchar * gchar *

View File

@ -78,7 +78,7 @@ gboolean fu_util_cmd_array_run (GPtrArray *array,
gchar **values, gchar **values,
GError **error); GError **error);
gchar *fu_util_release_get_name (FwupdRelease *release); gchar *fu_util_release_get_name (FwupdRelease *release);
const gchar *fu_util_release_get_branch (FwupdRelease *release); const gchar *fu_util_branch_for_display (const gchar *branch);
const gchar *fu_util_get_systemd_unit (void); const gchar *fu_util_get_systemd_unit (void);
gboolean fu_util_using_correct_daemon (GError **error); gboolean fu_util_using_correct_daemon (GError **error);

View File

@ -1905,6 +1905,12 @@ fu_util_reinstall (FuUtilPrivate *priv, gchar **values, GError **error)
return fu_util_prompt_complete (priv->completion_flags, TRUE, error); return fu_util_prompt_complete (priv->completion_flags, TRUE, error);
} }
static gboolean
_g_str_equal0 (gconstpointer str1, gconstpointer str2)
{
return g_strcmp0 (str1, str2) == 0;
}
static gboolean static gboolean
fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error) fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error)
{ {
@ -1931,10 +1937,10 @@ fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error)
/* get all the unique branches */ /* get all the unique branches */
for (guint i = 0; i < rels->len; i++) { for (guint i = 0; i < rels->len; i++) {
FwupdRelease *rel_tmp = g_ptr_array_index (rels, i); FwupdRelease *rel_tmp = g_ptr_array_index (rels, i);
const gchar *branch_tmp = fu_util_release_get_branch (rel_tmp); const gchar *branch_tmp = fwupd_release_get_branch (rel_tmp);
#if GLIB_CHECK_VERSION(2,54,3) #if GLIB_CHECK_VERSION(2,54,3)
if (g_ptr_array_find_with_equal_func (branches, branch_tmp, if (g_ptr_array_find_with_equal_func (branches, branch_tmp,
g_str_equal, NULL)) _g_str_equal0, NULL))
continue; continue;
#endif #endif
g_ptr_array_add (branches, g_strdup (branch_tmp)); g_ptr_array_add (branches, g_strdup (branch_tmp));
@ -1955,7 +1961,7 @@ fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error)
g_print ("0.\t%s\n", _("Cancel")); g_print ("0.\t%s\n", _("Cancel"));
for (guint i = 0; i < branches->len; i++) { for (guint i = 0; i < branches->len; i++) {
const gchar *branch_tmp = g_ptr_array_index (branches, i); const gchar *branch_tmp = g_ptr_array_index (branches, i);
g_print ("%u.\t%s\n", i + 1, branch_tmp); g_print ("%u.\t%s\n", i + 1, fu_util_branch_for_display (branch_tmp));
} }
idx = fu_util_prompt_for_number (branches->len); idx = fu_util_prompt_for_number (branches->len);
if (idx == 0) { if (idx == 0) {
@ -1975,7 +1981,7 @@ fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error)
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
"Device %s is already on branch %s", "Device %s is already on branch %s",
fu_device_get_name (dev), fu_device_get_name (dev),
branch); fu_util_branch_for_display (branch));
return FALSE; return FALSE;
} }
@ -1992,7 +1998,7 @@ fu_util_switch_branch (FuUtilPrivate *priv, gchar **values, GError **error)
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
"No releases for branch %s", "No releases for branch %s",
branch); fu_util_branch_for_display (branch));
return FALSE; return FALSE;
} }