[ostree/wip/repo-file: 3/9] builtin-commit: Don't parse the parent's GVariant by hand



commit 1f881cc898bd8435f754b0fe9826cbfeb0ec30c9
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Sep 6 19:35:23 2013 -0400

    builtin-commit: Don't parse the parent's GVariant by hand
    
    Instead, use OstreeRepoFile as a handle for the parent commit.
    We need to add an accessor for the metadata checksum, as that
    hasn't been exposed before.

 src/libostree/ostree-repo-file.c |    6 ++++++
 src/libostree/ostree-repo-file.h |    1 +
 src/ostree/ot-builtin-commit.c   |   29 +++++++++--------------------
 3 files changed, 16 insertions(+), 20 deletions(-)
---
diff --git a/src/libostree/ostree-repo-file.c b/src/libostree/ostree-repo-file.c
index aff6037..994d554 100644
--- a/src/libostree/ostree-repo-file.c
+++ b/src/libostree/ostree-repo-file.c
@@ -362,6 +362,12 @@ ostree_repo_file_tree_get_contents_checksum (OstreeRepoFile  *self)
   return self->tree_contents_checksum;
 }
 
+const char *
+ostree_repo_file_tree_get_metadata_checksum (OstreeRepoFile  *self)
+{
+  return self->tree_metadata_checksum;
+}
+
 /**
  * ostree_repo_file_nontree_get_local:
  *
diff --git a/src/libostree/ostree-repo-file.h b/src/libostree/ostree-repo-file.h
index 4243b80..f554be1 100644
--- a/src/libostree/ostree-repo-file.h
+++ b/src/libostree/ostree-repo-file.h
@@ -66,6 +66,7 @@ void ostree_repo_file_tree_set_metadata (OstreeRepoFile *self,
                                           GVariant       *metadata);
 
 const char *ostree_repo_file_tree_get_contents_checksum (OstreeRepoFile  *self);
+const char *ostree_repo_file_tree_get_metadata_checksum (OstreeRepoFile  *self);
 
 gboolean ostree_repo_file_is_tree (OstreeRepoFile  *self);
 
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index 20ab457..329cd53 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -227,15 +227,10 @@ 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_unref_variant GVariant *parent_commit = NULL;
   gs_free char *contents_checksum = NULL;
   gs_unref_object OstreeMutableTree *mtree = NULL;
   gs_free char *tree_type = NULL;
   gs_unref_hashtable GHashTable *mode_adds = NULL;
-  gs_unref_variant GVariant *parent_content_csum_v = NULL;
-  gs_unref_variant GVariant *parent_metadata_csum_v = NULL;
-  gs_free char *parent_content_checksum = NULL;
-  gs_free char *parent_metadata_checksum = NULL;
   OstreeRepoCommitModifier *modifier = NULL;
   OstreeRepoTransactionStats stats;
 
@@ -270,13 +265,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   if (!ostree_repo_resolve_rev (repo, opt_branch, TRUE, &parent, error))
     goto out;
 
-  if (opt_skip_if_unchanged && parent)
-    {
-      if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
-                                     parent, &parent_commit, error))
-        goto out;
-    }
-
   if (!opt_subject && !opt_body)
     {
       if (!commit_editor (repo, opt_branch, &opt_subject, &opt_body, cancellable, error))
@@ -390,17 +378,18 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   if (!ostree_repo_write_mtree (repo, mtree, &contents_checksum, cancellable, error))
     goto out;
 
-  if (opt_skip_if_unchanged && parent_commit)
+  if (opt_skip_if_unchanged && parent)
     {
-      g_variant_get_child (parent_commit, 6, "@ay", &parent_content_csum_v);
-      g_variant_get_child (parent_commit, 7, "@ay", &parent_metadata_csum_v);
+      const char *metadata_checksum;
+      gs_unref_object OstreeRepoFile *parent_root;
+
+      if (!ostree_repo_read_commit (repo, parent, (GFile **) &parent_root, cancellable, error))
+        goto out;
 
-      parent_content_checksum = ostree_checksum_from_bytes_v (parent_content_csum_v);
-      parent_metadata_checksum = ostree_checksum_from_bytes_v (parent_metadata_csum_v);
+      metadata_checksum = ostree_mutable_tree_get_metadata_checksum (mtree);
 
-      if (strcmp (contents_checksum, parent_content_checksum) == 0
-          && strcmp (ostree_mutable_tree_get_metadata_checksum (mtree),
-                     parent_metadata_checksum) == 0)
+      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)
         skip_commit = TRUE;
     }
 


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