mirror of
https://github.com/ostreedev/ostree.git
synced 2024-12-22 17:35:55 +03:00
Add 'ostree log' command
Follows the parent of commits showing each in turn until it reaches the top of the commit tree. https://bugzilla.gnome.org/show_bug.cgi?id=705973
This commit is contained in:
parent
5efb8e86e9
commit
3989e0d397
@ -31,6 +31,7 @@ ostree_SOURCES = src/ostree/main.c \
|
|||||||
src/ostree/ot-builtin-fsck.c \
|
src/ostree/ot-builtin-fsck.c \
|
||||||
src/ostree/ot-builtin-init.c \
|
src/ostree/ot-builtin-init.c \
|
||||||
src/ostree/ot-builtin-pull-local.c \
|
src/ostree/ot-builtin-pull-local.c \
|
||||||
|
src/ostree/ot-builtin-log.c \
|
||||||
src/ostree/ot-builtin-ls.c \
|
src/ostree/ot-builtin-ls.c \
|
||||||
src/ostree/ot-builtin-prune.c \
|
src/ostree/ot-builtin-prune.c \
|
||||||
src/ostree/ot-builtin-refs.c \
|
src/ostree/ot-builtin-refs.c \
|
||||||
|
@ -40,6 +40,7 @@ static OstreeCommand commands[] = {
|
|||||||
{ "diff", ostree_builtin_diff, 0 },
|
{ "diff", ostree_builtin_diff, 0 },
|
||||||
{ "fsck", ostree_builtin_fsck, 0 },
|
{ "fsck", ostree_builtin_fsck, 0 },
|
||||||
{ "init", ostree_builtin_init, 0 },
|
{ "init", ostree_builtin_init, 0 },
|
||||||
|
{ "log", ostree_builtin_log, 0 },
|
||||||
{ "ls", ostree_builtin_ls, 0 },
|
{ "ls", ostree_builtin_ls, 0 },
|
||||||
{ "refs", ostree_builtin_refs, 0 },
|
{ "refs", ostree_builtin_refs, 0 },
|
||||||
{ "prune", ostree_builtin_prune, 0 },
|
{ "prune", ostree_builtin_prune, 0 },
|
||||||
|
107
src/ostree/ot-builtin-log.c
Normal file
107
src/ostree/ot-builtin-log.c
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 Stef Walter <stefw@redhat.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
* Author: Stef Walter <stefw@redhat.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "ot-builtins.h"
|
||||||
|
#include "ot-dump.h"
|
||||||
|
#include "ostree.h"
|
||||||
|
#include "otutil.h"
|
||||||
|
|
||||||
|
static gboolean opt_raw;
|
||||||
|
|
||||||
|
static GOptionEntry options[] = {
|
||||||
|
{ "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "Show raw variant data" },
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
log_commit (OstreeRepo *repo,
|
||||||
|
const gchar *checksum,
|
||||||
|
OstreeDumpFlags flags,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gs_unref_variant GVariant *variant = NULL;
|
||||||
|
gs_free gchar *parent = NULL;
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
|
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, &variant, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ot_dump_object (OSTREE_OBJECT_TYPE_COMMIT, checksum, variant, flags);
|
||||||
|
|
||||||
|
/* Get the parent of this commit */
|
||||||
|
parent = ostree_commit_get_parent (variant);
|
||||||
|
if (parent && !log_commit (repo, parent, flags, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
ostree_builtin_log (int argc,
|
||||||
|
char **argv,
|
||||||
|
GFile *repo_path,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GOptionContext *context;
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
const char *rev;
|
||||||
|
gs_unref_object OstreeRepo *repo = NULL;
|
||||||
|
gs_free char *checksum = NULL;
|
||||||
|
OstreeDumpFlags flags = OSTREE_DUMP_NONE;
|
||||||
|
|
||||||
|
context = g_option_context_new ("REF - Show log starting at commit or ref");
|
||||||
|
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 (opt_raw)
|
||||||
|
flags |= OSTREE_DUMP_RAW;
|
||||||
|
|
||||||
|
if (argc <= 1)
|
||||||
|
{
|
||||||
|
ot_util_usage_error (context, "A ref argument is required", error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
rev = argv[1];
|
||||||
|
|
||||||
|
if (!ostree_repo_resolve_rev (repo, rev, FALSE, &checksum, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!log_commit (repo, checksum, flags, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
if (context)
|
||||||
|
g_option_context_free (context);
|
||||||
|
return ret;
|
||||||
|
}
|
@ -34,6 +34,7 @@ gboolean ostree_builtin_checksum (int argc, char **argv, GFile *repo_path, GCanc
|
|||||||
gboolean ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
gboolean ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
||||||
gboolean ostree_builtin_diff (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
gboolean ostree_builtin_diff (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
||||||
gboolean ostree_builtin_init (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
gboolean ostree_builtin_init (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
||||||
|
gboolean ostree_builtin_log (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
||||||
gboolean ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
gboolean ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
||||||
gboolean ostree_builtin_pull_local (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
gboolean ostree_builtin_pull_local (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
||||||
gboolean ostree_builtin_ls (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
gboolean ostree_builtin_ls (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "1..37"
|
echo "1..38"
|
||||||
|
|
||||||
. $(dirname $0)/libtest.sh
|
. $(dirname $0)/libtest.sh
|
||||||
|
|
||||||
@ -255,3 +255,13 @@ $OSTREE show test4 > show-output
|
|||||||
assert_file_has_content show-output "Third commit"
|
assert_file_has_content show-output "Third commit"
|
||||||
assert_file_has_content show-output "commit $checksum"
|
assert_file_has_content show-output "commit $checksum"
|
||||||
echo "ok show full output"
|
echo "ok show full output"
|
||||||
|
|
||||||
|
cd ${test_tmpdir}
|
||||||
|
checksum1=$($OSTREE commit -b test5 -s "First commit")
|
||||||
|
checksum2=$($OSTREE commit -b test5 -s "Second commit")
|
||||||
|
$OSTREE log test5 > log-output
|
||||||
|
assert_file_has_content log-output "First commit"
|
||||||
|
assert_file_has_content log-output "commit $checksum1"
|
||||||
|
assert_file_has_content log-output "Second commit"
|
||||||
|
assert_file_has_content log-output "commit $checksum2"
|
||||||
|
echo "ok log output"
|
||||||
|
Loading…
Reference in New Issue
Block a user