2 Copyright 2020 Google LLC
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
9 #include "git-compat-util.h"
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"
27 static int compact_stack(const char *stackdir
)
29 struct reftable_stack
*stack
= NULL
;
30 struct reftable_write_options cfg
= { 0 };
32 int err
= reftable_new_stack(&stack
, stackdir
, cfg
);
36 err
= reftable_stack_compact_all(stack
, NULL
);
41 reftable_stack_destroy(stack
);
46 static void print_help(void)
48 printf("usage: dump [-cst] arg\n\n"
53 " -6 sha256 hash format\n"
58 int reftable_dump_main(int argc
, char *const *argv
)
61 int opt_dump_table
= 0;
62 int opt_dump_stack
= 0;
64 uint32_t opt_hash_id
= GIT_SHA1_FORMAT_ID
;
65 const char *arg
= NULL
, *argv0
= argv
[0];
67 for (; argc
> 1; argv
++, argc
--)
70 else if (!strcmp("-t", argv
[1]))
72 else if (!strcmp("-6", argv
[1]))
73 opt_hash_id
= GIT_SHA256_FORMAT_ID
;
74 else if (!strcmp("-s", argv
[1]))
76 else if (!strcmp("-c", argv
[1]))
78 else if (!strcmp("-?", argv
[1]) || !strcmp("-h", argv
[1])) {
84 fprintf(stderr
, "need argument\n");
92 err
= reftable_reader_print_file(arg
);
93 } else if (opt_dump_stack
) {
94 err
= reftable_stack_print_directory(arg
, opt_hash_id
);
95 } else if (opt_compact
) {
96 err
= compact_stack(arg
);
100 fprintf(stderr
, "%s: %s: %s\n", argv0
, arg
,
101 reftable_error_str(err
));