3 #include "parse-options.h"
8 * Basic handler for bundle files to connect repositories via sneakernet.
9 * Invocation must include action.
10 * This function can create a bundle or provide information on an existing
11 * bundle supporting "fetch", "pull", and "ls-remote".
14 #define BUILTIN_BUNDLE_CREATE_USAGE \
15 N_("git bundle create [-q | --quiet | --progress | --all-progress] [--all-progress-implied]\n" \
16 " [--version=<version>] <file> <git-rev-list-args>")
17 #define BUILTIN_BUNDLE_VERIFY_USAGE \
18 N_("git bundle verify [-q | --quiet] <file>")
19 #define BUILTIN_BUNDLE_LIST_HEADS_USAGE \
20 N_("git bundle list-heads <file> [<refname>...]")
21 #define BUILTIN_BUNDLE_UNBUNDLE_USAGE \
22 N_("git bundle unbundle [--progress] <file> [<refname>...]")
24 static char const * const builtin_bundle_usage
[] = {
25 BUILTIN_BUNDLE_CREATE_USAGE
,
26 BUILTIN_BUNDLE_VERIFY_USAGE
,
27 BUILTIN_BUNDLE_LIST_HEADS_USAGE
,
28 BUILTIN_BUNDLE_UNBUNDLE_USAGE
,
32 static const char * const builtin_bundle_create_usage
[] = {
33 BUILTIN_BUNDLE_CREATE_USAGE
,
37 static const char * const builtin_bundle_verify_usage
[] = {
38 BUILTIN_BUNDLE_VERIFY_USAGE
,
42 static const char * const builtin_bundle_list_heads_usage
[] = {
43 BUILTIN_BUNDLE_LIST_HEADS_USAGE
,
47 static const char * const builtin_bundle_unbundle_usage
[] = {
48 BUILTIN_BUNDLE_UNBUNDLE_USAGE
,
52 static int parse_options_cmd_bundle(int argc
,
55 const char * const usagestr
[],
56 const struct option options
[],
59 newargc
= parse_options(argc
, argv
, NULL
, options
, usagestr
,
60 PARSE_OPT_STOP_AT_NON_OPTION
);
62 usage_with_options(usagestr
, options
);
63 *bundle_file
= prefix_filename(prefix
, argv
[0]);
67 static int cmd_bundle_create(int argc
, const char **argv
, const char *prefix
) {
68 int all_progress_implied
= 0;
69 int progress
= isatty(STDERR_FILENO
);
70 struct strvec pack_opts
;
73 struct option options
[] = {
74 OPT_SET_INT('q', "quiet", &progress
,
75 N_("do not show progress meter"), 0),
76 OPT_SET_INT(0, "progress", &progress
,
77 N_("show progress meter"), 1),
78 OPT_SET_INT(0, "all-progress", &progress
,
79 N_("show progress meter during object writing phase"), 2),
80 OPT_BOOL(0, "all-progress-implied",
81 &all_progress_implied
,
82 N_("similar to --all-progress when progress meter is shown")),
83 OPT_INTEGER(0, "version", &version
,
84 N_("specify bundle format version")),
89 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
90 builtin_bundle_create_usage
, options
, &bundle_file
);
91 /* bundle internals use argv[1] as further parameters */
93 strvec_init(&pack_opts
);
95 strvec_push(&pack_opts
, "--quiet");
96 else if (progress
== 1)
97 strvec_push(&pack_opts
, "--progress");
98 else if (progress
== 2)
99 strvec_push(&pack_opts
, "--all-progress");
100 if (progress
&& all_progress_implied
)
101 strvec_push(&pack_opts
, "--all-progress-implied");
103 if (!startup_info
->have_repository
)
104 die(_("Need a repository to create a bundle."));
105 ret
= !!create_bundle(the_repository
, bundle_file
, argc
, argv
, &pack_opts
, version
);
106 strvec_clear(&pack_opts
);
111 static int cmd_bundle_verify(int argc
, const char **argv
, const char *prefix
) {
112 struct bundle_header header
= BUNDLE_HEADER_INIT
;
116 struct option options
[] = {
117 OPT_BOOL('q', "quiet", &quiet
,
118 N_("do not show bundle details")),
123 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
124 builtin_bundle_verify_usage
, options
, &bundle_file
);
125 /* bundle internals use argv[1] as further parameters */
127 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0) {
132 if (verify_bundle(the_repository
, &header
,
133 quiet
? VERIFY_BUNDLE_QUIET
: VERIFY_BUNDLE_VERBOSE
)) {
138 fprintf(stderr
, _("%s is okay\n"), bundle_file
);
142 bundle_header_release(&header
);
146 static int cmd_bundle_list_heads(int argc
, const char **argv
, const char *prefix
) {
147 struct bundle_header header
= BUNDLE_HEADER_INIT
;
150 struct option options
[] = {
155 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
156 builtin_bundle_list_heads_usage
, options
, &bundle_file
);
157 /* bundle internals use argv[1] as further parameters */
159 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0) {
164 ret
= !!list_bundle_refs(&header
, argc
, argv
);
167 bundle_header_release(&header
);
171 static int cmd_bundle_unbundle(int argc
, const char **argv
, const char *prefix
) {
172 struct bundle_header header
= BUNDLE_HEADER_INIT
;
175 int progress
= isatty(2);
177 struct option options
[] = {
178 OPT_BOOL(0, "progress", &progress
,
179 N_("show progress meter")),
183 struct strvec extra_index_pack_args
= STRVEC_INIT
;
185 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
186 builtin_bundle_unbundle_usage
, options
, &bundle_file
);
187 /* bundle internals use argv[1] as further parameters */
189 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0) {
193 if (!startup_info
->have_repository
)
194 die(_("Need a repository to unbundle."));
196 strvec_pushl(&extra_index_pack_args
, "-v", "--progress-title",
197 _("Unbundling objects"), NULL
);
198 ret
= !!unbundle(the_repository
, &header
, bundle_fd
,
199 &extra_index_pack_args
, 0) ||
200 list_bundle_refs(&header
, argc
, argv
);
201 bundle_header_release(&header
);
207 int cmd_bundle(int argc
, const char **argv
, const char *prefix
)
209 parse_opt_subcommand_fn
*fn
= NULL
;
210 struct option options
[] = {
211 OPT_SUBCOMMAND("create", &fn
, cmd_bundle_create
),
212 OPT_SUBCOMMAND("verify", &fn
, cmd_bundle_verify
),
213 OPT_SUBCOMMAND("list-heads", &fn
, cmd_bundle_list_heads
),
214 OPT_SUBCOMMAND("unbundle", &fn
, cmd_bundle_unbundle
),
218 argc
= parse_options(argc
, argv
, prefix
, options
, builtin_bundle_usage
,
221 packet_trace_identity("bundle");
223 return !!fn(argc
, argv
, prefix
);