[ostree/wip/transaction: 7/9] repo: Move the transaction stats to a separate struct



commit 7764d4e14680cb53575cede3357c559ded24aa58
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Sep 5 16:48:40 2013 -0400

    repo: Move the transaction stats to a separate struct
    
    This is much easier for callers to handle, and simplifies
    the API a lot.

 doc/ostree-sections.txt             |    1 -
 src/libostree/ostree-repo-commit.c  |   44 +++++++++-------------------------
 src/libostree/ostree-repo-private.h |    6 +----
 src/libostree/ostree-repo-pull.c    |    2 +-
 src/libostree/ostree-repo.h         |   25 ++++++++++---------
 src/ostree/ot-builtin-commit.c      |   24 +++++-------------
 src/ostree/ot-builtin-pull-local.c  |    2 +-
 7 files changed, 35 insertions(+), 69 deletions(-)
---
diff --git a/doc/ostree-sections.txt b/doc/ostree-sections.txt
index 34a2faf..29e8999 100644
--- a/doc/ostree-sections.txt
+++ b/doc/ostree-sections.txt
@@ -65,7 +65,6 @@ ostree_repo_get_parent
 ostree_repo_write_config
 ostree_repo_prepare_transaction
 ostree_repo_commit_transaction
-ostree_repo_commit_transaction_with_stats
 ostree_repo_abort_transaction
 ostree_repo_has_object
 ostree_repo_write_metadata
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index 9533921..eec521c 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -363,18 +363,18 @@ write_object (OstreeRepo         *self,
     {
       if (OSTREE_OBJECT_TYPE_IS_META (objtype))
         {
-          self->txn_metadata_objects_written++;
+          self->txn_stats.metadata_objects_written++;
         }
       else
         {
-          self->txn_content_objects_written++;
-          self->txn_content_bytes_written += file_object_length;
+          self->txn_stats.content_objects_written++;
+          self->txn_stats.content_bytes_written += file_object_length;
         }
     }
   if (OSTREE_OBJECT_TYPE_IS_META (objtype))
-    self->txn_metadata_objects_total++;
+    self->txn_stats.metadata_objects_total++;
   else
-    self->txn_content_objects_total++;
+    self->txn_stats.content_objects_total++;
   g_mutex_unlock (&self->txn_stats_lock);
 
   if (checksum)
@@ -558,11 +558,7 @@ ostree_repo_prepare_transaction (OstreeRepo     *self,
   else
     ret_transaction_resume = FALSE;
 
-  self->txn_metadata_objects_total =
-    self->txn_metadata_objects_written =
-    self->txn_content_objects_total =
-    self->txn_content_objects_written =
-    self->txn_content_bytes_written = 0;
+  memset (&self->txn_stats, 0, sizeof (OstreeRepoTransactionStats));
 
   self->in_transaction = TRUE;
   if (ret_transaction_resume)
@@ -627,14 +623,10 @@ cleanup_tmpdir (OstreeRepo        *self,
 }
 
 gboolean
-ostree_repo_commit_transaction_with_stats (OstreeRepo     *self,
-                                           guint          *out_metadata_objects_total,
-                                           guint          *out_metadata_objects_written,
-                                           guint          *out_content_objects_total,
-                                           guint          *out_content_objects_written,
-                                           guint64        *out_content_bytes_written,
-                                           GCancellable   *cancellable,
-                                           GError        **error)
+ostree_repo_commit_transaction (OstreeRepo                  *self,
+                                OstreeRepoTransactionStats  *out_stats,
+                                GCancellable                *cancellable,
+                                GError                     **error)
 {
   gboolean ret = FALSE;
 
@@ -651,11 +643,8 @@ ostree_repo_commit_transaction_with_stats (OstreeRepo     *self,
   if (!ot_gfile_ensure_unlinked (self->transaction_lock_path, cancellable, error))
     goto out;
 
-  if (out_metadata_objects_total) *out_metadata_objects_total = self->txn_metadata_objects_total;
-  if (out_metadata_objects_written) *out_metadata_objects_written = self->txn_metadata_objects_written;
-  if (out_content_objects_total) *out_content_objects_total = self->txn_content_objects_total;
-  if (out_content_objects_written) *out_content_objects_written = self->txn_content_objects_written;
-  if (out_content_bytes_written) *out_content_bytes_written = self->txn_content_bytes_written;
+  if (out_stats)
+    *out_stats = self->txn_stats;
 
   ret = TRUE;
  out:
@@ -663,15 +652,6 @@ ostree_repo_commit_transaction_with_stats (OstreeRepo     *self,
 }
 
 gboolean
-ostree_repo_commit_transaction (OstreeRepo     *self,
-                                GCancellable   *cancellable,
-                                GError        **error)
-{
-  return ostree_repo_commit_transaction_with_stats (self, NULL, NULL, NULL, NULL, NULL,
-                                                    cancellable, error);
-}
-
-gboolean
 ostree_repo_abort_transaction (OstreeRepo     *self,
                                GCancellable   *cancellable,
                                GError        **error)
diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h
index ab673c9..3bb1f00 100644
--- a/src/libostree/ostree-repo-private.h
+++ b/src/libostree/ostree-repo-private.h
@@ -39,11 +39,7 @@ struct OstreeRepo {
 
   GFile *transaction_lock_path;
   GMutex txn_stats_lock;
-  guint txn_metadata_objects_total;
-  guint txn_metadata_objects_written;
-  guint txn_content_objects_total;
-  guint txn_content_objects_written;
-  guint64 txn_content_bytes_written;
+  OstreeRepoTransactionStats txn_stats;
 
   GMutex cache_lock;
   GPtrArray *cached_meta_indexes;
diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c
index bdb1958..0a42e3f 100644
--- a/src/libostree/ostree-repo-pull.c
+++ b/src/libostree/ostree-repo-pull.c
@@ -1332,7 +1332,7 @@ ostree_repo_pull (OstreeRepo               *self,
   if (!run_mainloop_monitor_fetcher (pull_data))
     goto out;
   
-  if (!ostree_repo_commit_transaction (pull_data->repo, cancellable, error))
+  if (!ostree_repo_commit_transaction (pull_data->repo, NULL, cancellable, error))
     goto out;
 
   g_hash_table_iter_init (&hash_iter, updated_refs);
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 186b480..b3c5506 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -46,6 +46,15 @@ typedef enum {
   OSTREE_REPO_MODE_ARCHIVE_Z2
 } OstreeRepoMode;
 
+typedef struct _OstreeRepoTransactionStats OstreeRepoTransactionStats;
+struct _OstreeRepoTransactionStats {
+  guint metadata_objects_total;
+  guint metadata_objects_written;
+  guint content_objects_total;
+  guint content_objects_written;
+  guint64 content_bytes_written;
+};
+
 gboolean ostree_repo_mode_from_string (const char      *mode,
                                        OstreeRepoMode  *out_mode,
                                        GError         **error);
@@ -85,18 +94,10 @@ gboolean      ostree_repo_prepare_transaction (OstreeRepo     *self,
                                                GCancellable   *cancellable,
                                                GError        **error);
 
-gboolean      ostree_repo_commit_transaction (OstreeRepo     *self,
-                                              GCancellable   *cancellable,
-                                              GError        **error);
-
-gboolean      ostree_repo_commit_transaction_with_stats (OstreeRepo     *self,
-                                                         guint          *out_metadata_objects_total,
-                                                         guint          *out_metadata_objects_written,
-                                                         guint          *out_content_objects_total,
-                                                         guint          *out_content_objects_written,
-                                                         guint64        *out_content_bytes_written,
-                                                         GCancellable   *cancellable,
-                                                         GError        **error);
+gboolean      ostree_repo_commit_transaction (OstreeRepo                  *self,
+                                              OstreeRepoTransactionStats  *out_stats,
+                                              GCancellable                *cancellable,
+                                              GError                     **error);
 
 gboolean      ostree_repo_abort_transaction (OstreeRepo     *self,
                                              GCancellable   *cancellable,
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index 7ef2037..22d6d89 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -225,11 +225,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   gboolean ret = FALSE;
   gboolean skip_commit = FALSE;
   gboolean in_transaction = FALSE;
-  guint metadata_total = 0;
-  guint metadata_written = 0;
-  guint content_total = 0;
-  guint content_written = 0;
-  guint64 content_bytes_written = 0;
   gs_unref_object GFile *arg = NULL;
   gs_free char *parent = NULL;
   gs_free char *commit_checksum = NULL;
@@ -243,6 +238,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   gs_free char *parent_content_checksum = NULL;
   gs_free char *parent_metadata_checksum = NULL;
   OstreeRepoCommitModifier *modifier = NULL;
+  OstreeRepoTransactionStats stats;
 
   context = g_option_context_new ("[ARG] - Commit a new revision");
   g_option_context_add_main_entries (context, options, NULL);
@@ -424,13 +420,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
                                      &commit_checksum, cancellable, error))
         goto out;
 
-      if (!ostree_repo_commit_transaction_with_stats (repo,
-                                                      &metadata_total,
-                                                      &metadata_written,
-                                                      &content_total,
-                                                      &content_written,
-                                                      &content_bytes_written,
-                                                      cancellable, error))
+      if (!ostree_repo_commit_transaction (repo, &stats, cancellable, error))
         goto out;
 
       in_transaction = FALSE;
@@ -452,11 +442,11 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   if (opt_table_output)
     {
       g_print ("Commit: %s\n", commit_checksum);
-      g_print ("Metadata Total: %u\n", metadata_total);
-      g_print ("Metadata Written: %u\n", metadata_written);
-      g_print ("Content Total: %u\n", content_total);
-      g_print ("Content Written: %u\n", content_written);
-      g_print ("Content Bytes Written: %" G_GUINT64_FORMAT "\n", content_bytes_written);
+      g_print ("Metadata Total: %u\n", stats.metadata_objects_total);
+      g_print ("Metadata Written: %u\n", stats.metadata_objects_written);
+      g_print ("Content Total: %u\n", stats.content_objects_total);
+      g_print ("Content Written: %u\n", stats.content_objects_written);
+      g_print ("Content Bytes Written: %" G_GUINT64_FORMAT "\n", stats.content_bytes_written);
     }
   else
     {
diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c
index b7749e1..98ba6cd 100644
--- a/src/ostree/ot-builtin-pull-local.c
+++ b/src/ostree/ot-builtin-pull-local.c
@@ -290,7 +290,7 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeRepo *repo, GCancellable
         gs_console_end_status_line (data->console, NULL, NULL);
     }
 
-  if (!ostree_repo_commit_transaction (data->dest_repo, NULL, error))
+  if (!ostree_repo_commit_transaction (data->dest_repo, NULL, NULL, error))
     goto out;
 
   g_print ("Writing %u refs\n", g_hash_table_size (refs_to_clone));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]