[ostree] core: Stub out a diff API and builtin
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: Stub out a diff API and builtin
- Date: Thu, 10 Nov 2011 14:32:56 +0000 (UTC)
commit a3043c0d647271da5000f81d25f4f17dba750588
Author: Colin Walters <walters verbum org>
Date: Thu Nov 10 09:27:22 2011 -0500
core: Stub out a diff API and builtin
Makefile-ostree.am | 1 +
libostree/ostree-repo.c | 30 ++++++++++++++++
libostree/ostree-repo.h | 24 +++++++++++++
ostree/main.c | 1 +
ostree/ot-builtin-diff.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++
ostree/ot-builtins.h | 1 +
6 files changed, 141 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-ostree.am b/Makefile-ostree.am
index 4a3733c..10c9aff 100644
--- a/Makefile-ostree.am
+++ b/Makefile-ostree.am
@@ -25,6 +25,7 @@ ostree_SOURCES = ostree/main.c \
ostree/ot-builtin-checkout.c \
ostree/ot-builtin-commit.c \
ostree/ot-builtin-compose.c \
+ ostree/ot-builtin-diff.c \
ostree/ot-builtin-fsck.c \
ostree/ot-builtin-init.c \
ostree/ot-builtin-log.c \
diff --git a/libostree/ostree-repo.c b/libostree/ostree-repo.c
index 1d9e853..a82381d 100644
--- a/libostree/ostree-repo.c
+++ b/libostree/ostree-repo.c
@@ -1842,3 +1842,33 @@ ostree_repo_checkout (OstreeRepo *self,
g_clear_object (&root_info);
return ret;
}
+
+gboolean
+ostree_repo_diff (OstreeRepo *self,
+ const char *ref,
+ GFile *target,
+ GPtrArray **out_modified,
+ GPtrArray **out_removed,
+ GPtrArray **out_added,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ GPtrArray *ret_modified = NULL;
+ GPtrArray *ret_removed = NULL;
+ GPtrArray *ret_added = NULL;
+
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ "Not implemented yet");
+ goto out;
+
+ ret = TRUE;
+ out:
+ if (ret_modified)
+ g_ptr_array_free (ret_modified, TRUE);
+ if (ret_removed)
+ g_ptr_array_free (ret_removed, TRUE);
+ if (ret_added)
+ g_ptr_array_free (ret_added, TRUE);
+ return ret;
+}
diff --git a/libostree/ostree-repo.h b/libostree/ostree-repo.h
index 5f46e46..50514bc 100644
--- a/libostree/ostree-repo.h
+++ b/libostree/ostree-repo.h
@@ -124,6 +124,30 @@ gboolean ostree_repo_checkout (OstreeRepo *self,
GCancellable *cancellable,
GError **error);
+typedef struct {
+ guint content_differs : 1;
+ guint xattrs_differs : 1;
+ guint unused : 30;
+
+ GFileInfo *src_info;
+ GFileInfo *target_info;
+
+ char *src_file_checksum;
+ char *target_file_checksum;
+
+ GVariant *src_xattrs;
+ GVariant *target_xattrs;
+} OstreeRepoDiffItem;
+
+gboolean ostree_repo_diff (OstreeRepo *self,
+ const char *ref,
+ GFile *target,
+ GPtrArray **out_modified, /* OstreeRepoDiffItem */
+ GPtrArray **out_removed, /* OstreeRepoDiffItem */
+ GPtrArray **out_added, /* OstreeRepoDiffItem */
+ GCancellable *cancellable,
+ GError **error);
+
typedef void (*OstreeRepoObjectIter) (OstreeRepo *self, const char *path,
GFileInfo *fileinfo, gpointer user_data);
diff --git a/ostree/main.c b/ostree/main.c
index 574f9b7..56ba4f3 100644
--- a/ostree/main.c
+++ b/ostree/main.c
@@ -29,6 +29,7 @@
static OstreeBuiltin builtins[] = {
{ "checkout", ostree_builtin_checkout, 0 },
+ { "diff", ostree_builtin_diff, 0 },
{ "init", ostree_builtin_init, 0 },
{ "commit", ostree_builtin_commit, 0 },
{ "compose", ostree_builtin_compose, 0 },
diff --git a/ostree/ot-builtin-diff.c b/ostree/ot-builtin-diff.c
new file mode 100644
index 0000000..73d1998
--- /dev/null
+++ b/ostree/ot-builtin-diff.c
@@ -0,0 +1,84 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters verbum org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters verbum org>
+ */
+
+#include "config.h"
+
+#include "ot-builtins.h"
+#include "ostree.h"
+
+#include <glib/gi18n.h>
+
+static GOptionEntry options[] = {
+ { NULL }
+};
+
+gboolean
+ostree_builtin_diff (int argc, char **argv, const char *repo_path, GError **error)
+{
+ GOptionContext *context;
+ gboolean ret = FALSE;
+ OstreeRepo *repo = NULL;
+ const char *target;
+ const char *rev;
+ GFile *targetf = NULL;
+ GPtrArray *modified = NULL;
+ GPtrArray *removed = NULL;
+ GPtrArray *added = NULL;
+
+ context = g_option_context_new ("REV TARGETDIR - Compare directory TARGETDIR against revision REV");
+ g_option_context_add_main_entries (context, options, NULL);
+
+ if (!g_option_context_parse (context, &argc, &argv, error))
+ goto out;
+
+ repo = ostree_repo_new (repo_path);
+ if (!ostree_repo_check (repo, error))
+ goto out;
+
+ if (argc < 3)
+ {
+ gchar *help = g_option_context_get_help (context, TRUE, NULL);
+ g_printerr ("%s\n", help);
+ g_free (help);
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "REV and TARGETDIR must be specified");
+ goto out;
+ }
+
+ rev = argv[1];
+ target = argv[2];
+ targetf = ot_util_new_file_for_path (target);
+
+ if (!ostree_repo_diff (repo, rev, targetf, &modified, &removed, &added, NULL, error))
+ goto out;
+
+ ret = TRUE;
+ out:
+ g_clear_object (&repo);
+ g_clear_object (&targetf);
+ if (modified)
+ g_ptr_array_free (modified, TRUE);
+ if (removed)
+ g_ptr_array_free (removed, TRUE);
+ if (added)
+ g_ptr_array_free (added, TRUE);
+ return ret;
+}
diff --git a/ostree/ot-builtins.h b/ostree/ot-builtins.h
index 5682b2b..a1d9918 100644
--- a/ostree/ot-builtins.h
+++ b/ostree/ot-builtins.h
@@ -39,6 +39,7 @@ typedef struct {
gboolean ostree_builtin_checkout (int argc, char **argv, const char *repo, GError **error);
gboolean ostree_builtin_commit (int argc, char **argv, const char *repo, GError **error);
gboolean ostree_builtin_compose (int argc, char **argv, const char *repo, GError **error);
+gboolean ostree_builtin_diff (int argc, char **argv, const char *repo, GError **error);
gboolean ostree_builtin_init (int argc, char **argv, const char *repo, GError **error);
gboolean ostree_builtin_log (int argc, char **argv, const char *repo, GError **error);
gboolean ostree_builtin_pull (int argc, char **argv, const char *repo, GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]