[ostree/wip/repo-file: 7/9] repo: Change the pairs of checksums to instead be based on OstreeRepoFiles



commit 97e519136205fac85da662654c45cb5c8b1d3681
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Sep 6 20:17:44 2013 -0400

    repo: Change the pairs of checksums to instead be based on OstreeRepoFiles
    
    We want an OstreeRepoFile to be the way to reference a "filesystem
    tree" that's stored in the repo, which is a combination of a DIR_TREE
    and a DIR_META. The idea is that once you write an mtree to the repo
    using ostree_repo_write_mtree, it becomes serialized and you get an
    OstreeRepoFile in return.
    
    Change any APIs that care about DIR_TREE / DIR_META checksums to care
    about OstreeRepoFiles instead, which right now is mostly is
    ostree_repo_write_commit.

 src/libostree/ostree-repo-commit.c |   84 +++++++++++++++++++-----------------
 src/libostree/ostree-repo.h        |    5 +-
 src/ostree/ot-builtin-commit.c     |   28 +++---------
 3 files changed, 54 insertions(+), 63 deletions(-)
---
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index 5d200a8..2b38f23 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -1193,8 +1193,7 @@ create_empty_gvariant_dict (void)
  * @parent: (allow-none): ASCII SHA256 checksum for parent, or %NULL for none
  * @subject: Subject
  * @body: (allow-none): Body
- * @root_contents_checksum: ASCII SHA256 checksum for %OSTREE_OBJECT_TYPE_DIR_TREE
- * @root_metadata_checksum: ASCII SHA256 checksum for %OSTREE_OBJECT_TYPE_DIR_META
+ * @root: The tree to point the commit to
  * @out_commit: (out): Resulting ASCII SHA256 checksum for commit
  * @cancellable: Cancellable
  * @error: Error
@@ -1203,25 +1202,23 @@ create_empty_gvariant_dict (void)
  * and @root_metadata_checksum.
  */
 gboolean
-ostree_repo_write_commit (OstreeRepo    *self,
-                          const char    *parent,
-                          const char    *subject,
-                          const char    *body,
-                          const char    *root_contents_checksum,
-                          const char    *root_metadata_checksum,
-                          char         **out_commit,
-                          GCancellable  *cancellable,
-                          GError       **error)
+ostree_repo_write_commit (OstreeRepo      *self,
+                          const char      *parent,
+                          const char      *subject,
+                          const char      *body,
+                          GFile           *root,
+                          char           **out_commit,
+                          GCancellable    *cancellable,
+                          GError         **error)
 {
   gboolean ret = FALSE;
   gs_free char *ret_commit = NULL;
   gs_unref_variant GVariant *commit = NULL;
   gs_free guchar *commit_csum = NULL;
   GDateTime *now = NULL;
+  OstreeRepoFile *repo_root = OSTREE_REPO_FILE (root);
 
   g_return_val_if_fail (subject != NULL, FALSE);
-  g_return_val_if_fail (root_contents_checksum != NULL, FALSE);
-  g_return_val_if_fail (root_metadata_checksum != NULL, FALSE);
 
   now = g_date_time_new_now_utc ();
   commit = g_variant_new ("(@a{sv} ay@a(say)sst ay@ay)",
@@ -1230,8 +1227,8 @@ ostree_repo_write_commit (OstreeRepo    *self,
                           g_variant_new_array (G_VARIANT_TYPE ("(say)"), NULL, 0),
                           subject, body ? body : "",
                           GUINT64_TO_BE (g_date_time_to_unix (now)),
-                          ostree_checksum_to_bytes_v (root_contents_checksum),
-                          ostree_checksum_to_bytes_v (root_metadata_checksum));
+                          ostree_checksum_to_bytes_v (ostree_repo_file_tree_get_contents_checksum 
(repo_root)),
+                          ostree_checksum_to_bytes_v (ostree_repo_file_tree_get_metadata_checksum 
(repo_root)));
   g_variant_ref_sink (commit);
   if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_COMMIT, NULL,
                                    commit, &commit_csum,
@@ -1594,38 +1591,47 @@ ostree_repo_write_directory_to_mtree (OstreeRepo                *self,
  * ostree_repo_write_mtree:
  * @self: Repo
  * @mtree: Mutable tree
- * @out_contents_checksum: (out): Return location for ASCII checksum
+ * @out_file: (out): An #OstreeRepoFile representing @mtree's root.
  * @cancellable: Cancellable
  * @error: Error
  *
  * Write all metadata objects for @mtree to repo; the resulting
- * @out_contents_checksum contains the checksum for the
- * %OSTREE_OBJECT_TYPE_DIR_TREE object.
+ * @out_file points to the %OSTREE_OBJECT_TYPE_DIR_TREE object that
+ * the @mtree represented.
  */
 gboolean
 ostree_repo_write_mtree (OstreeRepo           *self,
                          OstreeMutableTree    *mtree,
-                         char                **out_contents_checksum,
+                         GFile               **out_file,
                          GCancellable         *cancellable,
                          GError              **error)
 {
   gboolean ret = FALSE;
   GHashTableIter hash_iter;
   gpointer key, value;
-  const char *existing_checksum;
-  gs_free char *ret_contents_checksum = NULL;
-  gs_unref_hashtable GHashTable *dir_metadata_checksums = NULL;
-  gs_unref_hashtable GHashTable *dir_contents_checksums = NULL;
-  gs_unref_variant GVariant *serialized_tree = NULL;
-  gs_free guchar *contents_csum = NULL;
-
-  existing_checksum = ostree_mutable_tree_get_contents_checksum (mtree);
-  if (existing_checksum)
+  const char *contents_checksum, *metadata_checksum;
+  gs_unref_object GFile *ret_file = NULL;
+
+  metadata_checksum = ostree_mutable_tree_get_metadata_checksum (mtree);
+  if (!metadata_checksum)
     {
-      ret_contents_checksum = g_strdup (existing_checksum);
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "Can't commit an empty tree");
+      goto out;
+    }
+
+  contents_checksum = ostree_mutable_tree_get_contents_checksum (mtree);
+  if (contents_checksum)
+    {
+      ret_file = ostree_repo_file_new_root (self, contents_checksum, metadata_checksum);
     }
   else
     {
+      gs_unref_hashtable GHashTable *dir_metadata_checksums = NULL;
+      gs_unref_hashtable GHashTable *dir_contents_checksums = NULL;
+      gs_unref_variant GVariant *serialized_tree = NULL;
+      gs_free guchar *contents_csum = NULL;
+
       dir_contents_checksums = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                       (GDestroyNotify)g_free, (GDestroyNotify)g_free);
       dir_metadata_checksums = g_hash_table_new_full (g_str_hash, g_str_equal,
@@ -1635,21 +1641,17 @@ ostree_repo_write_mtree (OstreeRepo           *self,
       while (g_hash_table_iter_next (&hash_iter, &key, &value))
         {
           const char *name = key;
-          const char *metadata_checksum;
+          gs_unref_object GFile *child_file = NULL;
           OstreeMutableTree *child_dir = value;
-          char *child_dir_contents_checksum;
 
-          if (!ostree_repo_write_mtree (self, child_dir, &child_dir_contents_checksum,
+          if (!ostree_repo_write_mtree (self, child_dir, &child_file,
                                         cancellable, error))
             goto out;
 
-          g_assert (child_dir_contents_checksum);
           g_hash_table_replace (dir_contents_checksums, g_strdup (name),
-                                child_dir_contents_checksum); /* Transfer ownership */
-          metadata_checksum = ostree_mutable_tree_get_metadata_checksum (child_dir);
-          g_assert (metadata_checksum);
+                                g_strdup (ostree_repo_file_tree_get_contents_checksum (OSTREE_REPO_FILE 
(child_file))));
           g_hash_table_replace (dir_metadata_checksums, g_strdup (name),
-                                g_strdup (metadata_checksum));
+                                g_strdup (ostree_repo_file_tree_get_metadata_checksum (OSTREE_REPO_FILE 
(child_file))));
         }
 
       serialized_tree = create_tree_variant_from_hashes (ostree_mutable_tree_get_files (mtree),
@@ -1660,11 +1662,15 @@ ostree_repo_write_mtree (OstreeRepo           *self,
                                        serialized_tree, &contents_csum,
                                        cancellable, error))
         goto out;
-      ret_contents_checksum = ostree_checksum_from_bytes (contents_csum);
+
+      contents_checksum = ostree_checksum_from_bytes (contents_csum);
+      ostree_mutable_tree_set_contents_checksum (mtree, (char *) contents_csum);
+
+      ret_file = ostree_repo_file_new_root (self, contents_checksum, metadata_checksum);
     }
 
   ret = TRUE;
-  ot_transfer_out_value(out_contents_checksum, &ret_contents_checksum);
+  ot_transfer_out_value (out_file, &ret_file);
  out:
   return ret;
 }
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index ab4c4c7..2d2f9c0 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -310,7 +310,7 @@ gboolean      ostree_repo_write_archive_to_mtree (OstreeRepo                   *
 
 gboolean      ostree_repo_write_mtree (OstreeRepo         *self,
                                        OstreeMutableTree  *mtree,
-                                       char              **out_contents_checksum,
+                                       GFile             **out_file,
                                        GCancellable       *cancellable,
                                        GError            **error);
 
@@ -318,8 +318,7 @@ gboolean      ostree_repo_write_commit (OstreeRepo   *self,
                                         const char   *parent,
                                         const char   *subject,
                                         const char   *body,
-                                        const char   *root_contents_checksum,
-                                        const char   *root_metadata_checksum,
+                                        GFile        *root,
                                         char        **out_commit,
                                         GCancellable *cancellable,
                                         GError      **error);
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index fd52a3e..27521a7 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -227,7 +227,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   gs_unref_object GFile *arg = NULL;
   gs_free char *parent = NULL;
   gs_free char *commit_checksum = NULL;
-  gs_free char *contents_checksum = NULL;
+  gs_unref_object GFile *root = NULL;
   gs_unref_object OstreeMutableTree *mtree = NULL;
   gs_free char *tree_type = NULL;
   gs_unref_hashtable GHashTable *mode_adds = NULL;
@@ -374,38 +374,24 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
                    "Unmatched statoverride paths");
       goto out;
     }
-          
-  if (!ostree_repo_write_mtree (repo, mtree, &contents_checksum, cancellable, error))
+
+  if (!ostree_repo_write_mtree (repo, mtree, &root, cancellable, error))
     goto out;
 
   if (opt_skip_if_unchanged && parent)
     {
-      const char *metadata_checksum;
-      gs_unref_object OstreeRepoFile *parent_root;
+      gs_unref_object GFile *parent_root;
 
-      if (!ostree_repo_read_commit (repo, parent, (GFile **) &parent_root, cancellable, error))
+      if (!ostree_repo_read_commit (repo, parent, &parent_root, cancellable, error))
         goto out;
 
-      metadata_checksum = ostree_mutable_tree_get_metadata_checksum (mtree);
-
-      if (strcmp (contents_checksum, ostree_repo_file_tree_get_contents_checksum (parent_root)) == 0 &&
-          strcmp (metadata_checksum, ostree_repo_file_tree_get_metadata_checksum (parent_root)) == 0)
+      if (g_file_equal (root, parent_root))
         skip_commit = TRUE;
     }
 
   if (!skip_commit)
     {
-      const char *root_metadata = ostree_mutable_tree_get_metadata_checksum (mtree);
-      
-      if (!root_metadata)
-        {
-          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                       "Can't commit an empty tree");
-          goto out;
-        }
-
-      if (!ostree_repo_write_commit (repo, parent, opt_subject, opt_body,
-                                     contents_checksum, root_metadata,
+      if (!ostree_repo_write_commit (repo, parent, opt_subject, opt_body, root,
                                      &commit_checksum, cancellable, error))
         goto out;
 


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