From patchwork Mon Aug 30 14:57:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12465425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5ACAC432BE for ; Mon, 30 Aug 2021 14:58:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E72160E77 for ; Mon, 30 Aug 2021 14:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237357AbhH3O7T (ORCPT ); Mon, 30 Aug 2021 10:59:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237337AbhH3O7D (ORCPT ); Mon, 30 Aug 2021 10:59:03 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F63AC061760 for ; Mon, 30 Aug 2021 07:58:09 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id f9-20020a05600c1549b029025b0f5d8c6cso14934869wmg.4 for ; Mon, 30 Aug 2021 07:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=vRAQxRV4mWm5KzO2JMO1K4ORWwbDDHcdGl0emEa8Wlg=; b=CQVxCFdHMNtfYLEwhiAzel4ofhYO3Yww6NSsj631uwUi+4ftdw6+jPmK17vFPWUiVc BD40rtn+KE/Qd610D0F29Ur3DE0Az4dnKCXeIZDbRC7BL3osuDwwGEcu0pFXoj5IS6ub 7+fgAoomHUgh2L+S7J5LfcHmtD32LFlG7Jd5koTr+wh4soMmvtxWuep72TfSRMoad9/0 VZ70AN4IB5jFuBmI4DhQ/qxBJojj6h0HSmUJIaZKJXLhKOWW8v3uouUJlbMWx4p/fcUs kDeZyY/d+UikOr5rYZzqi/sa9tvIxE/Hqfasy6HDgU12ODsuFLol3Mm9B915Jvtcf+Uz 2BwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=vRAQxRV4mWm5KzO2JMO1K4ORWwbDDHcdGl0emEa8Wlg=; b=IrTIP1rcmbSmtFEom7xikrk/B3eYRjdEqqp0QpLi8AZ2QeiZe9Fo7MAtg1mjZIGePq cdD9Dg1jy8uyVZA4ZBMU8thxnkwSJ914ljUfSnEZ+nDPAgGG691KYE67GTEQs2Rvu/0u SfLAAcmHSRNIBcwKBG/6OUoTikFUIWNL0frSvUlg3Pw88IkV6Id7ZHrX11mo/8CA2rh+ QnopUbsiWDEK6ISLeGQ8kYbTAbq1EuX3UJSDvwR8sjuURD4ErlIfougvllFgC0HMb352 jbWktx6E6ufq60BVk2D0wOlFnquTUqg/5Uy1zlN5r46f5nxst9gyJH892gNXfk7Kgl00 kKJw== X-Gm-Message-State: AOAM533RD361FV2t8DHM4BlnKm50gBrsW+C69ToJbfiOMYF5vY1t/Ntq u5ZfNdpWwLdQ4Xm49kfaChn/NyVqXbw= X-Google-Smtp-Source: ABdhPJyWuP6GCi/D+GZyQgafevuacOhEieQCBrr/QnvZCEgRjFEMRA2+XnkTRGYgJERrulKNdqcyDQ== X-Received: by 2002:a1c:23c7:: with SMTP id j190mr33739577wmj.1.1630335488090; Mon, 30 Aug 2021 07:58:08 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c7sm13427072wmq.13.2021.08.30.07.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 07:58:07 -0700 (PDT) Message-Id: <0170f20b5e75fad4894d935eccb5eb0c0af31e77.1630335476.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 30 Aug 2021 14:57:54 +0000 Subject: [PATCH 18/19] reftable: add dump utility MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys provide a command-line utility for inspecting individual tables, and inspecting a complete ref database Signed-off-by: Han-Wen Nienhuys Helped-by: Carlo Marcelo Arenas Belón --- reftable/dump.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 reftable/dump.c diff --git a/reftable/dump.c b/reftable/dump.c new file mode 100644 index 00000000000..155953d1b82 --- /dev/null +++ b/reftable/dump.c @@ -0,0 +1,107 @@ +/* +Copyright 2020 Google LLC + +Use of this source code is governed by a BSD-style +license that can be found in the LICENSE file or at +https://developers.google.com/open-source/licenses/bsd +*/ + +#include "git-compat-util.h" +#include "hash.h" + +#include "reftable-blocksource.h" +#include "reftable-error.h" +#include "reftable-merged.h" +#include "reftable-record.h" +#include "reftable-tests.h" +#include "reftable-writer.h" +#include "reftable-iterator.h" +#include "reftable-reader.h" +#include "reftable-stack.h" +#include "reftable-generic.h" + +#include +#include +#include +#include +#include + +static int compact_stack(const char *stackdir) +{ + struct reftable_stack *stack = NULL; + struct reftable_write_options cfg = { 0 }; + + int err = reftable_new_stack(&stack, stackdir, cfg); + if (err < 0) + goto done; + + err = reftable_stack_compact_all(stack, NULL); + if (err < 0) + goto done; +done: + if (stack) { + reftable_stack_destroy(stack); + } + return err; +} + +static void print_help(void) +{ + printf("usage: dump [-cst] arg\n\n" + "options: \n" + " -c compact\n" + " -t dump table\n" + " -s dump stack\n" + " -6 sha256 hash format\n" + " -h this help\n" + "\n"); +} + +int reftable_dump_main(int argc, char *const *argv) +{ + int err = 0; + int opt_dump_table = 0; + int opt_dump_stack = 0; + int opt_compact = 0; + uint32_t opt_hash_id = GIT_SHA1_FORMAT_ID; + const char *arg = NULL, *argv0 = argv[0]; + + for (; argc > 1; argv++, argc--) + if (*argv[1] != '-') + break; + else if (!strcmp("-t", argv[1])) + opt_dump_table = 1; + else if (!strcmp("-6", argv[1])) + opt_hash_id = GIT_SHA256_FORMAT_ID; + else if (!strcmp("-s", argv[1])) + opt_dump_stack = 1; + else if (!strcmp("-c", argv[1])) + opt_compact = 1; + else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) { + print_help(); + return 2; + } + + if (argc != 2) { + fprintf(stderr, "need argument\n"); + print_help(); + return 2; + } + + arg = argv[1]; + + if (opt_dump_table) { + err = reftable_reader_print_file(arg); + } else if (opt_dump_stack) { + err = reftable_stack_print_directory(arg, opt_hash_id); + } else if (opt_compact) { + err = compact_stack(arg); + } + + if (err < 0) { + fprintf(stderr, "%s: %s: %s\n", argv0, arg, + reftable_error_str(err)); + return 1; + } + return 0; +}