mirror of
https://github.com/ostreedev/ostree.git
synced 2025-01-10 05:18:30 +03:00
core: Stub out a diff API and builtin
This commit is contained in:
parent
f265579367
commit
a3043c0d64
@ -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 \
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 },
|
||||
|
84
ostree/ot-builtin-diff.c
Normal file
84
ostree/ot-builtin-diff.c
Normal file
@ -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;
|
||||
}
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user