deploy: Clean up bootserial assignment function

The reason we were returning a hashtable is a bit lost to history,
there's no reason to do so now anyways.  Also port to declare-and-initialize
style and add more comments.

Closes: #1538
Approved by: jlebon
This commit is contained in:
Colin Walters 2018-04-12 12:43:39 -04:00 committed by Atomic Bot
parent eb506c759c
commit 56de631721
1 changed files with 10 additions and 10 deletions

View File

@ -1874,26 +1874,26 @@ swap_bootloader (OstreeSysroot *sysroot,
return TRUE; return TRUE;
} }
static GHashTable * /* Deployments may share boot checksums; the bootserial indexes them
* per-bootchecksum. It's used by the symbolic links after the bootloader.
*/
static void
assign_bootserials (GPtrArray *deployments) assign_bootserials (GPtrArray *deployments)
{ {
guint i; g_autoptr(GHashTable) serials =
GHashTable *ret =
g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
for (i = 0; i < deployments->len; i++) for (guint i = 0; i < deployments->len; i++)
{ {
OstreeDeployment *deployment = deployments->pdata[i]; OstreeDeployment *deployment = deployments->pdata[i];
const char *bootcsum = ostree_deployment_get_bootcsum (deployment); const char *bootcsum = ostree_deployment_get_bootcsum (deployment);
guint count; /* Note that not-found maps to NULL which converts to zero */
guint count = GPOINTER_TO_UINT (g_hash_table_lookup (serials, bootcsum));
count = GPOINTER_TO_UINT (g_hash_table_lookup (ret, bootcsum)); g_hash_table_replace (serials, (char*) bootcsum,
g_hash_table_replace (ret, (char*) bootcsum,
GUINT_TO_POINTER (count + 1)); GUINT_TO_POINTER (count + 1));
ostree_deployment_set_bootserial (deployment, count); ostree_deployment_set_bootserial (deployment, count);
} }
return ret;
} }
/* OSTree implements a special optimization where we want to avoid touching /* OSTree implements a special optimization where we want to avoid touching
@ -2146,7 +2146,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self,
/* Assign a bootserial to each new deployment. /* Assign a bootserial to each new deployment.
*/ */
g_hash_table_unref (assign_bootserials (new_deployments)); assign_bootserials (new_deployments);
/* Determine whether or not we need to touch the bootloader /* Determine whether or not we need to touch the bootloader
* configuration. If we have an equal number of deployments with * configuration. If we have an equal number of deployments with