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



commit c7f9fc9c63c3686c7899503b64eed79261f7aa3b
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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707727

 src/libostree/ostree-repo-commit.c  |   87 +++++++++++++++++++----------------
 src/libostree/ostree-repo-file.c    |   12 ++--
 src/libostree/ostree-repo-private.h |    5 ++
 src/libostree/ostree-repo.h         |   21 ++++----
 src/ostree/ot-builtin-commit.c      |   29 +++--------
 5 files changed, 76 insertions(+), 78 deletions(-)
---
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index 3a80cde..b77758e 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -1172,8 +1172,7 @@ create_empty_gvariant_dict (void)
  * @subject: Subject
  * @body: (allow-none): Body
  * @metadata: (allow-none): GVariant of type a{sv}, or %NULL for none
- * @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
@@ -1182,26 +1181,24 @@ 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,
-                          GVariant      *metadata,
-                          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,
+                          GVariant        *metadata,
+                          OstreeRepoFile  *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)",
@@ -1210,8 +1207,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,
@@ -1662,38 +1659,48 @@ 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)
+    {
+      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_contents_checksum = g_strdup (existing_checksum);
+      ret_file = G_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;
+      char contents_checksum_buf[65];
+
       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,
@@ -1703,21 +1710,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),
@@ -1728,11 +1731,15 @@ ostree_repo_write_mtree (OstreeRepo           *self,
                                        serialized_tree, &contents_csum,
                                        cancellable, error))
         goto out;
-      ret_contents_checksum = ostree_checksum_from_bytes (contents_csum);
+
+      ostree_checksum_inplace_from_bytes (contents_csum, contents_checksum_buf);
+      ostree_mutable_tree_set_contents_checksum (mtree, contents_checksum_buf);
+
+      ret_file = G_FILE (_ostree_repo_file_new_root (self, contents_checksum_buf, 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-file.c b/src/libostree/ostree-repo-file.c
index d5f2a54..51b12d5 100644
--- a/src/libostree/ostree-repo-file.c
+++ b/src/libostree/ostree-repo-file.c
@@ -104,10 +104,10 @@ set_error_noent (GFile *self, GError **error)
   return FALSE;
 }
 
-static OstreeRepoFile *
-ostree_repo_file_new_root (OstreeRepo *repo,
-                           const char *contents_checksum,
-                           const char *metadata_checksum)
+OstreeRepoFile *
+_ostree_repo_file_new_root (OstreeRepo *repo,
+                            const char *contents_checksum,
+                            const char *metadata_checksum)
 {
   OstreeRepoFile *self;
 
@@ -172,7 +172,7 @@ _ostree_repo_file_new_for_commit (OstreeRepo  *repo,
   ostree_checksum_inplace_from_bytes (g_variant_get_data (tree_metadata_csum_v),
                                       tree_metadata_csum);
 
-  ret = ostree_repo_file_new_root (repo, tree_contents_csum, tree_metadata_csum);
+  ret = _ostree_repo_file_new_root (repo, tree_contents_csum, tree_metadata_csum);
 
  out:
   return ret;
@@ -530,7 +530,7 @@ ostree_repo_file_dup (GFile *file)
   if (self->parent)
     return G_FILE (ostree_repo_file_new_child (self->parent, self->name));
   else
-    return G_FILE (ostree_repo_file_new_root (self->repo, self->tree_contents_checksum, 
self->tree_metadata_checksum));
+    return G_FILE (_ostree_repo_file_new_root (self->repo, self->tree_contents_checksum, 
self->tree_metadata_checksum));
 }
 
 static guint
diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h
index fe9114b..041f567 100644
--- a/src/libostree/ostree-repo-private.h
+++ b/src/libostree/ostree-repo-private.h
@@ -116,5 +116,10 @@ _ostree_repo_file_new_for_commit (OstreeRepo  *repo,
                                   const char  *commit,
                                   GError     **error);
 
+OstreeRepoFile *
+_ostree_repo_file_new_root (OstreeRepo  *repo,
+                            const char  *contents_checksum,
+                            const char  *metadata_checksum);
+
 G_END_DECLS
 
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index ca24a76..2a9d9f3 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -310,20 +310,19 @@ 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);
 
-gboolean      ostree_repo_write_commit (OstreeRepo   *self,
-                                        const char   *parent,
-                                        const char   *subject,
-                                        const char   *body,
-                                        GVariant     *metadata,
-                                        const char   *root_contents_checksum,
-                                        const char   *root_metadata_checksum,
-                                        char        **out_commit,
-                                        GCancellable *cancellable,
-                                        GError      **error);
+gboolean      ostree_repo_write_commit (OstreeRepo      *self,
+                                        const char      *parent,
+                                        const char      *subject,
+                                        const char      *body,
+                                        GVariant        *metadata,
+                                        OstreeRepoFile  *root,
+                                        char           **out_commit,
+                                        GCancellable    *cancellable,
+                                        GError         **error);
 
 gboolean      ostree_repo_read_commit_detached_metadata (OstreeRepo      *self,
                                                          const char      *checksum,
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index e240204..a4ede8f 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -270,7 +270,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_variant GVariant *metadata = NULL;
   gs_unref_variant GVariant *detached_metadata = NULL;
   gs_unref_object OstreeMutableTree *mtree = NULL;
@@ -432,38 +432,25 @@ 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,
-                                     metadata, contents_checksum, root_metadata,
+      if (!ostree_repo_write_commit (repo, parent, opt_subject, opt_body, metadata,
+                                     OSTREE_REPO_FILE (root),
                                      &commit_checksum, cancellable, error))
         goto out;
 


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