1
-/*
2
-Copyright 2020 Google LLC
3
-
4
-Use of this source code is governed by a BSD-style
5
-license that can be found in the LICENSE file or at
6
-https://developers.google.com/open-source/licenses/bsd
7
-*/
8
-
9
-#include "git-compat-util.h"
10
-#include "hash.h"
11
-
12
-#include "reftable-blocksource.h"
13
-#include "reftable-error.h"
14
-#include "reftable-record.h"
15
-#include "reftable-tests.h"
16
-#include "reftable-writer.h"
17
-#include "reftable-iterator.h"
18
-#include "reftable-reader.h"
19
-#include "reftable-stack.h"
20
-
21
-#include <stddef.h>
22
-#include <stdio.h>
23
-#include <stdlib.h>
24
-#include <unistd.h>
25
-#include <string.h>
26
-
27
-static void print_help(void)
28
-{
29
- printf("usage: dump [-st] arg\n\n"
30
- "options: \n"
31
- " -b dump blocks\n"
32
- " -t dump table\n"
33
- " -s dump stack\n"
34
- " -6 sha256 hash format\n"
35
- " -h this help\n"
36
- "\n");
37
-}
38
-
39
-int reftable_dump_main(int argc, char *const *argv)
40
-{
41
- int err = 0;
42
- int opt_dump_blocks = 0;
43
- int opt_dump_table = 0;
44
- int opt_dump_stack = 0;
45
- uint32_t opt_hash_id = GIT_SHA1_FORMAT_ID;
46
- const char *arg = NULL, *argv0 = argv[0];
47
-
48
- for (; argc > 1; argv++, argc--)
49
- if (*argv[1] != '-')
50
- break;
51
- else if (!strcmp("-b", argv[1]))
52
- opt_dump_blocks = 1;
53
- else if (!strcmp("-t", argv[1]))
54
- opt_dump_table = 1;
55
- else if (!strcmp("-6", argv[1]))
56
- opt_hash_id = GIT_SHA256_FORMAT_ID;
57
- else if (!strcmp("-s", argv[1]))
58
- opt_dump_stack = 1;
59
- else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) {
60
- print_help();
61
- return 2;
62
- }
63
-
64
- if (argc != 2) {
65
- fprintf(stderr, "need argument\n");
66
- print_help();
67
- return 2;
68
- }
69
-
70
- arg = argv[1];
71
-
72
- if (opt_dump_blocks) {
73
- err = reftable_reader_print_blocks(arg);
74
- } else if (opt_dump_table) {
75
- err = reftable_reader_print_file(arg);
76
- } else if (opt_dump_stack) {
77
- err = reftable_stack_print_directory(arg, opt_hash_id);
78
- }
79
-
80
- if (err < 0) {
81
- fprintf(stderr, "%s: %s: %s\n", argv0, arg,
82
- reftable_error_str(err));
83
- return 1;
84
- }
85
- return 0;
86
-}