[hacktree] repo: Add API to load variants, and get HEAD
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hacktree] repo: Add API to load variants, and get HEAD
- Date: Sat, 15 Oct 2011 02:10:43 +0000 (UTC)
commit b3c556a34946d79947397853cbe318df7a659cb2
Author: Colin Walters <walters verbum org>
Date: Fri Oct 14 22:09:44 2011 -0400
repo: Add API to load variants, and get HEAD
src/libhacktree/hacktree-repo.c | 99 ++++++++++++++++++++++++++++++++-------
src/libhacktree/hacktree-repo.h | 8 +++
2 files changed, 90 insertions(+), 17 deletions(-)
---
diff --git a/src/libhacktree/hacktree-repo.c b/src/libhacktree/hacktree-repo.c
index d0afb3f..6c0bbf6 100644
--- a/src/libhacktree/hacktree-repo.c
+++ b/src/libhacktree/hacktree-repo.c
@@ -275,11 +275,11 @@ import_gvariant_object (HacktreeRepo *self,
}
static gboolean
-load_gvariant_object (HacktreeRepo *self,
- HacktreeSerializedVariantType expected_type,
- const char *sha256,
- GVariant **out_variant,
- GError **error)
+load_gvariant_object_unknown (HacktreeRepo *self,
+ const char *sha256,
+ HacktreeSerializedVariantType *out_type,
+ GVariant **out_variant,
+ GError **error)
{
HacktreeRepoPrivate *priv = GET_PRIVATE (self);
GMappedFile *mfile = NULL;
@@ -287,6 +287,7 @@ load_gvariant_object (HacktreeRepo *self,
GVariant *ret_variant = NULL;
GVariant *container = NULL;
char *path = NULL;
+ guint32 ret_type;
path = get_object_path_for_checksum (self, sha256);
@@ -295,7 +296,6 @@ load_gvariant_object (HacktreeRepo *self,
goto out;
else
{
- guint32 type;
container = g_variant_new_from_data (G_VARIANT_TYPE (HACKTREE_SERIALIZED_VARIANT_FORMAT),
g_mapped_file_get_contents (mfile),
g_mapped_file_get_length (mfile),
@@ -309,15 +309,7 @@ load_gvariant_object (HacktreeRepo *self,
goto out;
}
g_variant_get (container, "(uv)",
- &type, &ret_variant);
- if (type != expected_type)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Corrupted metadata object '%s'; found type %u, expected %u", sha256,
- type, (guint32)expected_type);
- goto out;
-
- }
+ &ret_type, &ret_variant);
mfile = NULL;
}
@@ -329,7 +321,10 @@ load_gvariant_object (HacktreeRepo *self,
g_variant_unref (ret_variant);
}
else
- *out_variant = ret_variant;
+ {
+ *out_type = ret_type;
+ *out_variant = ret_variant;
+ }
if (container != NULL)
g_variant_unref (container);
g_free (path);
@@ -339,6 +334,40 @@ load_gvariant_object (HacktreeRepo *self,
}
static gboolean
+load_gvariant_object (HacktreeRepo *self,
+ HacktreeSerializedVariantType expected_type,
+ const char *sha256,
+ GVariant **out_variant,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ HacktreeSerializedVariantType type;
+ GVariant *ret_variant = NULL;
+
+ if (!load_gvariant_object_unknown (self, sha256, &type, &ret_variant, error))
+ goto out;
+
+ if (type != expected_type)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Corrupted metadata object '%s'; found type %u, expected %u", sha256,
+ type, (guint32)expected_type);
+ goto out;
+
+ }
+
+ ret = TRUE;
+ *out_variant = ret_variant;
+ out:
+ if (!ret)
+ {
+ if (ret_variant)
+ g_variant_unref (ret_variant);
+ }
+ return ret;
+}
+
+static gboolean
import_directory_meta (HacktreeRepo *self,
const char *path,
GVariant **out_variant,
@@ -1198,7 +1227,7 @@ iter_object_dir (HacktreeRepo *self,
dirpath = g_file_get_path (dir);
- enumerator = g_file_enumerate_children (dir, "standard::*,unix::*",
+ enumerator = g_file_enumerate_children (dir, "standard::name,standard::type,unix::*",
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL,
error);
@@ -1294,3 +1323,39 @@ hacktree_repo_iter_objects (HacktreeRepo *self,
g_clear_object (&objectdir);
return ret;
}
+
+gboolean
+hacktree_repo_load_variant (HacktreeRepo *repo,
+ const char *sha256,
+ HacktreeSerializedVariantType *out_type,
+ GVariant **out_variant,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ HacktreeSerializedVariantType ret_type;
+ GVariant *ret_variant = NULL;
+
+ if (!load_gvariant_object_unknown (repo, sha256, &ret_type, &ret_variant, error))
+ goto out;
+
+ ret = TRUE;
+ *out_type = ret_type;
+ *out_variant = ret_variant;
+ out:
+ if (!ret)
+ {
+ if (ret_variant)
+ g_variant_unref (ret_variant);
+ }
+ return ret;
+}
+
+const char *
+hacktree_repo_get_head (HacktreeRepo *self)
+{
+ HacktreeRepoPrivate *priv = GET_PRIVATE (self);
+
+ g_return_val_if_fail (priv->inited, NULL);
+
+ return priv->current_head;
+}
diff --git a/src/libhacktree/hacktree-repo.h b/src/libhacktree/hacktree-repo.h
index 55da5ee..9c4ea51 100644
--- a/src/libhacktree/hacktree-repo.h
+++ b/src/libhacktree/hacktree-repo.h
@@ -59,6 +59,14 @@ gboolean hacktree_repo_link_file (HacktreeRepo *repo,
gboolean force,
GError **error);
+const char * hacktree_repo_get_head (HacktreeRepo *repo);
+
+gboolean hacktree_repo_load_variant (HacktreeRepo *repo,
+ const char *sha256,
+ HacktreeSerializedVariantType *out_type,
+ GVariant **out_variant,
+ GError **error);
+
gboolean hacktree_repo_commit (HacktreeRepo *repo,
const char *subject,
const char *body,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]