From 3b9da094d8537777f2ac1d26b127818310568cf9 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 23 Jul 2013 18:16:54 -0400 Subject: [PATCH] main: Drop log builtin We may revive this later, but commits in their current form aren't very useful for humans to read, so it doesn't make sense to have a tool to show a history of useless stuff. More interesting things are diffs between commits, object statistics, etc. --- Makefile-ostree.am | 1 - Makefile-tests.am | 1 - src/libotutil/ot-unix-utils.c | 40 --------- src/libotutil/ot-unix-utils.h | 2 - src/ostree/main.c | 1 - src/ostree/ot-builtin-log.c | 147 ---------------------------------- src/ostree/ot-builtins.h | 1 - tests/test-log.sh | 30 ------- 8 files changed, 223 deletions(-) delete mode 100644 src/ostree/ot-builtin-log.c delete mode 100755 tests/test-log.sh diff --git a/Makefile-ostree.am b/Makefile-ostree.am index 949641e6..ee49c38e 100644 --- a/Makefile-ostree.am +++ b/Makefile-ostree.am @@ -31,7 +31,6 @@ ostree_SOURCES = src/ostree/main.c \ src/ostree/ot-builtin-fsck.c \ src/ostree/ot-builtin-init.c \ src/ostree/ot-builtin-pull-local.c \ - src/ostree/ot-builtin-log.c \ src/ostree/ot-builtin-ls.c \ src/ostree/ot-builtin-prune.c \ src/ostree/ot-builtin-refs.c \ diff --git a/Makefile-tests.am b/Makefile-tests.am index 19764e66..c7d9e545 100644 --- a/Makefile-tests.am +++ b/Makefile-tests.am @@ -23,7 +23,6 @@ insttestdir=$(pkglibexecdir)/installed-tests testfiles = test-basic \ test-archive \ test-archivez \ - test-log \ test-remote-add \ test-corruption \ test-libarchive \ diff --git a/src/libotutil/ot-unix-utils.c b/src/libotutil/ot-unix-utils.c index 8cb19926..2933d649 100644 --- a/src/libotutil/ot-unix-utils.c +++ b/src/libotutil/ot-unix-utils.c @@ -36,46 +36,6 @@ #include #include -gboolean -ot_util_spawn_pager (GOutputStream **out_stream, - GError **error) -{ - gboolean ret = FALSE; - const char *pager; - char *argv[2]; - int stdin_fd; - pid_t pid; - gs_free GOutputStream *ret_stream = NULL; - - if (!isatty (1)) - { - ret_stream = (GOutputStream*)g_unix_output_stream_new (1, TRUE); - } - else - { - pager = g_getenv ("GIT_PAGER"); - if (pager == NULL) - pager = "less"; - - argv[0] = (char*)pager; - argv[1] = NULL; - - if (!g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, &pid, &stdin_fd, NULL, NULL, error)) - { - g_prefix_error (error, "%s", "Failed to spawn pager: "); - goto out; - } - - ret_stream = (GOutputStream*)g_unix_output_stream_new (stdin_fd, TRUE); - } - - ot_transfer_out_value(out_stream, &ret_stream); - ret = TRUE; - out: - return ret; -} - gboolean ot_util_filename_validate (const char *name, GError **error) diff --git a/src/libotutil/ot-unix-utils.h b/src/libotutil/ot-unix-utils.h index ed15379f..aba997fe 100644 --- a/src/libotutil/ot-unix-utils.h +++ b/src/libotutil/ot-unix-utils.h @@ -36,8 +36,6 @@ G_BEGIN_DECLS -gboolean ot_util_spawn_pager (GOutputStream **out_stream, GError **error); - void ot_util_fatal_literal (const char *msg) G_GNUC_NORETURN; void ot_util_fatal_gerror (GError *error) G_GNUC_NORETURN; diff --git a/src/ostree/main.c b/src/ostree/main.c index b20cdbb0..580fc8e2 100644 --- a/src/ostree/main.c +++ b/src/ostree/main.c @@ -40,7 +40,6 @@ static OstreeCommand commands[] = { { "diff", ostree_builtin_diff, 0 }, { "fsck", ostree_builtin_fsck, 0 }, { "init", ostree_builtin_init, 0 }, - { "log", ostree_builtin_log, 0 }, { "ls", ostree_builtin_ls, 0 }, { "refs", ostree_builtin_refs, 0 }, { "prune", ostree_builtin_prune, 0 }, diff --git a/src/ostree/ot-builtin-log.c b/src/ostree/ot-builtin-log.c deleted file mode 100644 index a5e9715b..00000000 --- a/src/ostree/ot-builtin-log.c +++ /dev/null @@ -1,147 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- - * - * Copyright (C) 2011 Colin Walters - * - * 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: Colin Walters - */ - -#include "config.h" - -#include "ot-builtins.h" -#include "ostree.h" - -static GOptionEntry options[] = { - { NULL } -}; - -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_unref_object GOutputStream *pager = NULL; - gs_unref_variant GVariant *commit = NULL; - gs_free char *resolved_rev = NULL; - - context = g_option_context_new ("- Show revision log"); - g_option_context_add_main_entries (context, options, NULL); - - if (!g_option_context_parse (context, &argc, &argv, error)) - goto out; - - if (argc < 2) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "A revision must be specified"); - goto out; - } - - rev = argv[1]; - - repo = ostree_repo_new (repo_path); - if (!ostree_repo_check (repo, error)) - goto out; - - if (!ot_util_spawn_pager (&pager, error)) - goto out; - - if (!ostree_repo_resolve_rev (repo, rev, FALSE, &resolved_rev, error)) - goto out; - - while (TRUE) - { - char *formatted = NULL; - GVariant *parent_csum_v = NULL; - const char *subject; - const char *body; - guint64 timestamp; - GVariant *content_csum_v = NULL; - GVariant *metadata_csum_v = NULL; - GDateTime *time_obj = NULL; - char *formatted_date = NULL; - const char *body_newline; - gsize bytes_written; - GVariant *commit_metadata = NULL; - char *formatted_metadata = NULL; - - g_clear_pointer (&commit, (GDestroyNotify) g_variant_unref); - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, resolved_rev, &commit, error)) - goto out; - - /* Ignore commit metadata for now */ - g_clear_pointer (&commit_metadata, (GDestroyNotify) g_variant_unref); - g_clear_pointer (&parent_csum_v, (GDestroyNotify) g_variant_unref); - g_clear_pointer (&content_csum_v, (GDestroyNotify) g_variant_unref); - g_clear_pointer (&metadata_csum_v, (GDestroyNotify) g_variant_unref); - g_variant_get (commit, "(@a{sv}@ay@a(say)&s&st@ay@ay)", - &commit_metadata, &parent_csum_v, NULL, &subject, &body, - ×tamp, &content_csum_v, &metadata_csum_v); - timestamp = GUINT64_FROM_BE (timestamp); - time_obj = g_date_time_new_from_unix_utc (timestamp); - formatted_date = g_date_time_format (time_obj, "%a %b %d %H:%M:%S %Y %z"); - g_date_time_unref (time_obj); - time_obj = NULL; - - g_clear_pointer (&commit_metadata, (GDestroyNotify) g_variant_unref); - formatted = g_strdup_printf ("commit %s\nSubject: %s\nDate: %s\nMetadata: %s\n\n", - resolved_rev, subject, formatted_date, formatted_metadata); - g_free (formatted_metadata); - g_free (formatted_date); - formatted_date = NULL; - - if (!g_output_stream_write_all (pager, formatted, strlen (formatted), &bytes_written, NULL, error)) - { - g_free (formatted); - goto out; - } - g_free (formatted); - - body_newline = strchr (body, '\n'); - do { - gsize len; - if (!g_output_stream_write_all (pager, " ", 4, &bytes_written, NULL, error)) - goto out; - len = body_newline ? body_newline - body : strlen (body); - if (!g_output_stream_write_all (pager, body, len, &bytes_written, NULL, error)) - goto out; - if (!g_output_stream_write_all (pager, "\n\n", 2, &bytes_written, NULL, error)) - goto out; - body_newline = strchr (body, '\n'); - if (!body_newline) - break; - else - body_newline += 1; - } while (*body_newline); - - if (g_variant_n_children (parent_csum_v) == 0) - break; - g_free (resolved_rev); - resolved_rev = ostree_checksum_from_bytes_v (parent_csum_v); - } - - if (!g_output_stream_close (pager, NULL, error)) - goto out; - - ret = TRUE; - out: - if (context) - g_option_context_free (context); - return ret; -} diff --git a/src/ostree/ot-builtins.h b/src/ostree/ot-builtins.h index 777a5e7c..358ceead 100644 --- a/src/ostree/ot-builtins.h +++ b/src/ostree/ot-builtins.h @@ -36,7 +36,6 @@ gboolean ostree_builtin_diff (int argc, char **argv, GFile *repo_path, GCancella gboolean ostree_builtin_init (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_log (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_prune (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error); gboolean ostree_builtin_refs (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error); diff --git a/tests/test-log.sh b/tests/test-log.sh deleted file mode 100755 index 7c415ff8..00000000 --- a/tests/test-log.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2011 Colin Walters -# -# 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. - -set -e - -. $(dirname $0)/libtest.sh - -echo "1..1" - -setup_test_repository "bare" -$OSTREE log test2 > $test_tmpdir/log.txt -assert_file_has_content $test_tmpdir/log.txt "Test Commit 1" -assert_file_has_content $test_tmpdir/log.txt "Test Commit 2" -echo "ok log"