1 #define USE_THE_REPOSITORY_VARIABLE
5 #include "parse-options.h"
9 #define REFS_MIGRATE_USAGE \
10 N_("git refs migrate --ref-format=<format> [--dry-run]")
12 #define REFS_VERIFY_USAGE \
13 N_("git refs verify [--strict] [--verbose]")
15 static int cmd_refs_migrate(int argc
, const char **argv
, const char *prefix
)
17 const char * const migrate_usage
[] = {
21 const char *format_str
= NULL
;
22 enum ref_storage_format format
;
23 unsigned int flags
= 0;
24 struct option options
[] = {
25 OPT_STRING_F(0, "ref-format", &format_str
, N_("format"),
26 N_("specify the reference format to convert to"),
28 OPT_BIT(0, "dry-run", &flags
,
29 N_("perform a non-destructive dry-run"),
30 REPO_MIGRATE_REF_STORAGE_FORMAT_DRYRUN
),
33 struct strbuf errbuf
= STRBUF_INIT
;
36 argc
= parse_options(argc
, argv
, prefix
, options
, migrate_usage
, 0);
38 usage(_("too many arguments"));
40 usage(_("missing --ref-format=<format>"));
42 format
= ref_storage_format_by_name(format_str
);
43 if (format
== REF_STORAGE_FORMAT_UNKNOWN
) {
44 err
= error(_("unknown ref storage format '%s'"), format_str
);
48 if (the_repository
->ref_storage_format
== format
) {
49 err
= error(_("repository already uses '%s' format"),
50 ref_storage_format_to_name(format
));
54 if (repo_migrate_ref_storage_format(the_repository
, format
, flags
, &errbuf
) < 0) {
55 err
= error("%s", errbuf
.buf
);
62 strbuf_release(&errbuf
);
66 static int cmd_refs_verify(int argc
, const char **argv
, const char *prefix
)
68 struct fsck_options fsck_refs_options
= FSCK_REFS_OPTIONS_DEFAULT
;
69 const char * const verify_usage
[] = {
73 struct option options
[] = {
74 OPT_BOOL(0, "verbose", &fsck_refs_options
.verbose
, N_("be verbose")),
75 OPT_BOOL(0, "strict", &fsck_refs_options
.strict
, N_("enable strict checking")),
80 argc
= parse_options(argc
, argv
, prefix
, options
, verify_usage
, 0);
82 usage(_("'git refs verify' takes no arguments"));
84 git_config(git_fsck_config
, &fsck_refs_options
);
85 prepare_repo_settings(the_repository
);
87 ret
= refs_fsck(get_main_ref_store(the_repository
), &fsck_refs_options
);
89 fsck_options_clear(&fsck_refs_options
);
93 int cmd_refs(int argc
,
96 struct repository
*repo UNUSED
)
98 const char * const refs_usage
[] = {
103 parse_opt_subcommand_fn
*fn
= NULL
;
104 struct option opts
[] = {
105 OPT_SUBCOMMAND("migrate", &fn
, cmd_refs_migrate
),
106 OPT_SUBCOMMAND("verify", &fn
, cmd_refs_verify
),
110 argc
= parse_options(argc
, argv
, prefix
, opts
, refs_usage
, 0);
111 return fn(argc
, argv
, prefix
);