[ostree/wip/packfile-rebase2: 10/11] core: Only pack currently-loose objects
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/packfile-rebase2: 10/11] core: Only pack currently-loose objects
- Date: Thu, 22 Mar 2012 03:14:45 +0000 (UTC)
commit 455a4c0cfa613429985af77e0209c6e0cdfe0268
Author: Colin Walters <walters verbum org>
Date: Wed Mar 21 19:42:22 2012 -0400
core: Only pack currently-loose objects
src/libostree/ostree-core.c | 13 ++++++++++++
src/libostree/ostree-core.h | 2 +
src/libostree/ostree-repo.c | 17 ++-------------
src/ostree/ot-builtin-repack.c | 41 +++++++++++++++++++++++++++------------
4 files changed, 46 insertions(+), 27 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 852adcb..376504c 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -584,6 +584,19 @@ ostree_object_from_string (const char *str,
*out_objtype = ostree_object_type_from_string (dot + 1);
}
+guint
+ostree_hash_object_name (gconstpointer a)
+{
+ GVariant *variant = (gpointer)a;
+ const char *checksum;
+ OstreeObjectType objtype;
+ gint objtype_int;
+
+ ostree_object_name_deserialize (variant, &checksum, &objtype);
+ objtype_int = (gint) objtype;
+ return g_str_hash (checksum) + g_int_hash (&objtype_int);
+}
+
GVariant *
ostree_object_name_serialize (const char *checksum,
OstreeObjectType objtype)
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index d857c8a..5feee23 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -144,6 +144,8 @@ const char * ostree_object_type_to_string (OstreeObjectType objtype);
OstreeObjectType ostree_object_type_from_string (const char *str);
+guint ostree_hash_object_name (gconstpointer a);
+
GVariant *ostree_object_name_serialize (const char *checksum,
OstreeObjectType objtype);
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 523361e..7cc8081 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -2307,19 +2307,6 @@ ostree_repo_commit_modifier_unref (OstreeRepoCommitModifier *modifier)
return;
}
-static guint
-hash_list_object_key (gconstpointer a)
-{
- GVariant *variant = (gpointer)a;
- const char *checksum;
- OstreeObjectType objtype;
- gint objtype_int;
-
- ostree_object_name_deserialize (variant, &checksum, &objtype);
- objtype_int = (gint) objtype;
- return g_str_hash (checksum) + g_int_hash (&objtype_int);
-}
-
static gboolean
list_loose_object_dir (OstreeRepo *self,
GFile *dir,
@@ -3028,7 +3015,9 @@ ostree_repo_list_objects (OstreeRepo *self,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (priv->inited, FALSE);
- ret_objects = g_hash_table_new_full (hash_list_object_key, g_variant_equal, (GDestroyNotify) g_variant_unref, (GDestroyNotify) g_variant_unref);
+ ret_objects = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal,
+ (GDestroyNotify) g_variant_unref,
+ (GDestroyNotify) g_variant_unref);
if (flags & OSTREE_REPO_LIST_OBJECTS_ALL)
flags |= (OSTREE_REPO_LIST_OBJECTS_LOOSE | OSTREE_REPO_LIST_OBJECTS_PACKED);
diff --git a/src/ostree/ot-builtin-repack.c b/src/ostree/ot-builtin-repack.c
index b59c9b5..afa4864 100644
--- a/src/ostree/ot-builtin-repack.c
+++ b/src/ostree/ot-builtin-repack.c
@@ -657,17 +657,18 @@ parse_compression_string (const char *compstr,
}
static gboolean
-do_stats (OtRepackData *data,
- GHashTable *objects,
- GCancellable *cancellable,
- GError **error)
+do_stats_gather_loose (OtRepackData *data,
+ GHashTable *objects,
+ GHashTable **out_loose,
+ GCancellable *cancellable,
+ GError **error)
{
gboolean ret = FALSE;
+ GHashTable *ret_loose = NULL;
guint n_loose = 0;
guint n_loose_and_packed = 0;
guint n_packed = 0;
guint n_dup_packed = 0;
- guint n_multiple_packs = 0;
guint n_commits = 0;
guint n_dirmeta = 0;
guint n_dirtree = 0;
@@ -675,6 +676,10 @@ do_stats (OtRepackData *data,
GHashTableIter hash_iter;
gpointer key, value;
+ ret_loose = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal,
+ (GDestroyNotify) g_variant_unref,
+ NULL);
+
g_hash_table_iter_init (&hash_iter, objects);
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{
@@ -695,7 +700,11 @@ do_stats (OtRepackData *data,
if (is_loose && is_packed)
n_loose_and_packed++;
else if (is_loose)
- n_loose++;
+ {
+ GVariant *copy = g_variant_ref (serialized_key);
+ g_hash_table_replace (ret_loose, copy, copy);
+ n_loose++;
+ }
else if (g_variant_n_children (pack_array) > 0)
n_dup_packed++;
else
@@ -728,12 +737,15 @@ do_stats (OtRepackData *data,
g_print ("Files: %u\n", n_files);
g_print ("\n");
g_print ("Loose+packed objects: %u\n", n_loose_and_packed);
- g_print ("Loose objects: %u\n", n_loose);
+ g_print ("Loose-only objects: %u\n", n_loose);
g_print ("Duplicate packed objects: %u\n", n_dup_packed);
- g_print ("Packed objects: %u\n", n_packed);
+ g_print ("Packed-only objects: %u\n", n_packed);
ret = TRUE;
+ ot_transfer_out_value (out_loose, &ret_loose);
/* out: */
+ if (ret_loose)
+ g_hash_table_unref (ret_loose);
return ret;
}
@@ -749,8 +761,6 @@ ostree_builtin_repack (int argc, char **argv, GFile *repo_path, GError **error)
guint i;
GPtrArray *clusters = NULL;
GHashTable *loose_objects = NULL;
- GHashTableIter hash_iter;
- gpointer key, value;
memset (&data, 0, sizeof (data));
@@ -778,16 +788,19 @@ ostree_builtin_repack (int argc, char **argv, GFile *repo_path, GError **error)
if (!ostree_repo_list_objects (repo, OSTREE_REPO_LIST_OBJECTS_ALL, &objects, cancellable, error))
goto out;
- if (!do_stats (&data, objects, cancellable, error))
+ if (!do_stats_gather_loose (&data, objects, &loose_objects, cancellable, error))
goto out;
g_print ("\n");
g_print ("Using pack size: %" G_GUINT64_FORMAT "\n", data.pack_size);
- if (!cluster_objects_stupidly (&data, objects, &clusters, cancellable, error))
+ if (!cluster_objects_stupidly (&data, loose_objects, &clusters, cancellable, error))
goto out;
- g_print ("Going to create %u packfiles\n", clusters->len);
+ if (clusters->len > 0)
+ g_print ("Going to create %u packfiles\n", clusters->len);
+ else
+ g_print ("Nothing to do\n");
for (i = 0; i < clusters->len; i++)
{
@@ -809,6 +822,8 @@ ostree_builtin_repack (int argc, char **argv, GFile *repo_path, GError **error)
g_clear_object (&repo);
if (clusters)
g_ptr_array_unref (clusters);
+ if (loose_objects)
+ g_hash_table_unref (loose_objects);
if (objects)
g_hash_table_unref (objects);
return ret;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]