lib/commit: Some misc porting to decl-after-stmnt

Just happened to have this file open.

Closes: #1214
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-09-25 20:39:53 -04:00 committed by Atomic Bot
parent cd70aaac11
commit 3a08f7159d
1 changed files with 24 additions and 52 deletions

View File

@ -2070,22 +2070,10 @@ ostree_repo_write_commit (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; g_autoptr(GDateTime) now = g_date_time_new_now_utc ();
GDateTime *now = NULL; return ostree_repo_write_commit_with_time (self, parent, subject, body,
metadata, root, g_date_time_to_unix (now),
now = g_date_time_new_now_utc (); out_commit, cancellable, error);
ret = ostree_repo_write_commit_with_time (self,
parent,
subject,
body,
metadata,
root,
g_date_time_to_unix (now),
out_commit,
cancellable,
error);
g_date_time_unref (now);
return ret;
} }
/** /**
@ -2206,23 +2194,19 @@ ostree_repo_write_commit_detached_metadata (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
char pathbuf[_OSTREE_LOOSE_PATH_MAX];
g_autoptr(GVariant) normalized = NULL;
gsize normalized_size = 0;
const guint8 *data = NULL;
int dest_dfd; int dest_dfd;
if (self->in_transaction) if (self->in_transaction)
dest_dfd = self->commit_stagedir.fd; dest_dfd = self->commit_stagedir.fd;
else else
dest_dfd = self->objects_dir_fd; dest_dfd = self->objects_dir_fd;
_ostree_loose_path (pathbuf, checksum, OSTREE_OBJECT_TYPE_COMMIT_META, self->mode);
if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, checksum, if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, checksum,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
g_autoptr(GVariant) normalized = NULL;
gsize normalized_size = 0;
const guint8 *data = NULL;
if (metadata != NULL) if (metadata != NULL)
{ {
normalized = g_variant_get_normal_form (metadata); normalized = g_variant_get_normal_form (metadata);
@ -2233,6 +2217,8 @@ ostree_repo_write_commit_detached_metadata (OstreeRepo *self,
if (data == NULL) if (data == NULL)
data = (guint8*)""; data = (guint8*)"";
char pathbuf[_OSTREE_LOOSE_PATH_MAX];
_ostree_loose_path (pathbuf, checksum, OSTREE_OBJECT_TYPE_COMMIT_META, self->mode);
if (!glnx_file_replace_contents_at (dest_dfd, pathbuf, if (!glnx_file_replace_contents_at (dest_dfd, pathbuf,
data, normalized_size, data, normalized_size,
0, cancellable, error)) 0, cancellable, error))
@ -2250,14 +2236,11 @@ create_tree_variant_from_hashes (GHashTable *file_checksums,
GHashTable *dir_metadata_checksums) GHashTable *dir_metadata_checksums)
{ {
GVariantBuilder files_builder; GVariantBuilder files_builder;
GVariantBuilder dirs_builder;
GSList *sorted_filenames = NULL;
GSList *iter;
GVariant *serialized_tree;
g_variant_builder_init (&files_builder, G_VARIANT_TYPE ("a(say)")); g_variant_builder_init (&files_builder, G_VARIANT_TYPE ("a(say)"));
GVariantBuilder dirs_builder;
g_variant_builder_init (&dirs_builder, G_VARIANT_TYPE ("a(sayay)")); g_variant_builder_init (&dirs_builder, G_VARIANT_TYPE ("a(sayay)"));
GSList *sorted_filenames = NULL;
GLNX_HASH_TABLE_FOREACH (file_checksums, const char*, name) GLNX_HASH_TABLE_FOREACH (file_checksums, const char*, name)
{ {
/* Should have been validated earlier, but be paranoid */ /* Should have been validated earlier, but be paranoid */
@ -2265,10 +2248,8 @@ create_tree_variant_from_hashes (GHashTable *file_checksums,
sorted_filenames = g_slist_prepend (sorted_filenames, (char*)name); sorted_filenames = g_slist_prepend (sorted_filenames, (char*)name);
} }
sorted_filenames = g_slist_sort (sorted_filenames, (GCompareFunc)strcmp); sorted_filenames = g_slist_sort (sorted_filenames, (GCompareFunc)strcmp);
for (GSList *iter = sorted_filenames; iter; iter = iter->next)
for (iter = sorted_filenames; iter; iter = iter->next)
{ {
const char *name = iter->data; const char *name = iter->data;
const char *value; const char *value;
@ -2277,25 +2258,20 @@ create_tree_variant_from_hashes (GHashTable *file_checksums,
g_variant_builder_add (&files_builder, "(s@ay)", name, g_variant_builder_add (&files_builder, "(s@ay)", name,
ostree_checksum_to_bytes_v (value)); ostree_checksum_to_bytes_v (value));
} }
g_slist_free (sorted_filenames); g_slist_free (sorted_filenames);
sorted_filenames = NULL; sorted_filenames = NULL;
GLNX_HASH_TABLE_FOREACH (dir_metadata_checksums, const char*, name) GLNX_HASH_TABLE_FOREACH (dir_metadata_checksums, const char*, name)
sorted_filenames = g_slist_prepend (sorted_filenames, (char*)name); sorted_filenames = g_slist_prepend (sorted_filenames, (char*)name);
sorted_filenames = g_slist_sort (sorted_filenames, (GCompareFunc)strcmp); sorted_filenames = g_slist_sort (sorted_filenames, (GCompareFunc)strcmp);
for (iter = sorted_filenames; iter; iter = iter->next) for (GSList *iter = sorted_filenames; iter; iter = iter->next)
{ {
const char *name = iter->data; const char *name = iter->data;
const char *content_checksum; const char *content_checksum = g_hash_table_lookup (dir_contents_checksums, name);
const char *meta_checksum; const char *meta_checksum = g_hash_table_lookup (dir_metadata_checksums, name);
content_checksum = g_hash_table_lookup (dir_contents_checksums, name); g_variant_builder_add (&dirs_builder, "(s@ay@ay)", name,
meta_checksum = g_hash_table_lookup (dir_metadata_checksums, name);
g_variant_builder_add (&dirs_builder, "(s@ay@ay)",
name,
ostree_checksum_to_bytes_v (content_checksum), ostree_checksum_to_bytes_v (content_checksum),
ostree_checksum_to_bytes_v (meta_checksum)); ostree_checksum_to_bytes_v (meta_checksum));
} }
@ -2303,12 +2279,11 @@ create_tree_variant_from_hashes (GHashTable *file_checksums,
g_slist_free (sorted_filenames); g_slist_free (sorted_filenames);
sorted_filenames = NULL; sorted_filenames = NULL;
serialized_tree = g_variant_new ("(@a(say)@a(sayay))", GVariant *serialized_tree =
g_variant_builder_end (&files_builder), g_variant_new ("(@a(say)@a(sayay))",
g_variant_builder_end (&dirs_builder)); g_variant_builder_end (&files_builder),
g_variant_ref_sink (serialized_tree); g_variant_builder_end (&dirs_builder));
return g_variant_ref_sink (serialized_tree);
return serialized_tree;
} }
/* If any filtering is set up, perform it, and return modified file info in /* If any filtering is set up, perform it, and return modified file info in
@ -2369,16 +2344,13 @@ _ostree_repo_commit_modifier_apply (OstreeRepo *self,
static char * static char *
ptrarray_path_join (GPtrArray *path) ptrarray_path_join (GPtrArray *path)
{ {
GString *path_buf; GString *path_buf = g_string_new ("");
path_buf = g_string_new ("");
if (path->len == 0) if (path->len == 0)
g_string_append_c (path_buf, '/'); g_string_append_c (path_buf, '/');
else else
{ {
guint i; for (guint i = 0; i < path->len; i++)
for (i = 0; i < path->len; i++)
{ {
const char *elt = path->pdata[i]; const char *elt = path->pdata[i];