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 static const char * const builtin_bundle_usage
[] = {
15 N_("git bundle create [<options>] <file> <git-rev-list args>"),
16 N_("git bundle verify [<options>] <file>"),
17 N_("git bundle list-heads <file> [<refname>...]"),
18 N_("git bundle unbundle <file> [<refname>...]"),
22 static const char * const builtin_bundle_create_usage
[] = {
23 N_("git bundle create [<options>] <file> <git-rev-list args>"),
27 static const char * const builtin_bundle_verify_usage
[] = {
28 N_("git bundle verify [<options>] <file>"),
32 static const char * const builtin_bundle_list_heads_usage
[] = {
33 N_("git bundle list-heads <file> [<refname>...]"),
37 static const char * const builtin_bundle_unbundle_usage
[] = {
38 N_("git bundle unbundle <file> [<refname>...]"),
42 static int parse_options_cmd_bundle(int argc
,
45 const char * const usagestr
[],
46 const struct option options
[],
49 newargc
= parse_options(argc
, argv
, NULL
, options
, usagestr
,
50 PARSE_OPT_STOP_AT_NON_OPTION
);
52 usage_with_options(usagestr
, options
);
53 *bundle_file
= prefix_filename(prefix
, argv
[0]);
57 static int cmd_bundle_create(int argc
, const char **argv
, const char *prefix
) {
58 int all_progress_implied
= 0;
59 int progress
= isatty(STDERR_FILENO
);
60 struct strvec pack_opts
;
63 struct option options
[] = {
64 OPT_SET_INT('q', "quiet", &progress
,
65 N_("do not show progress meter"), 0),
66 OPT_SET_INT(0, "progress", &progress
,
67 N_("show progress meter"), 1),
68 OPT_SET_INT(0, "all-progress", &progress
,
69 N_("show progress meter during object writing phase"), 2),
70 OPT_BOOL(0, "all-progress-implied",
71 &all_progress_implied
,
72 N_("similar to --all-progress when progress meter is shown")),
73 OPT_INTEGER(0, "version", &version
,
74 N_("specify bundle format version")),
79 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
80 builtin_bundle_create_usage
, options
, &bundle_file
);
81 /* bundle internals use argv[1] as further parameters */
83 strvec_init(&pack_opts
);
85 strvec_push(&pack_opts
, "--quiet");
86 else if (progress
== 1)
87 strvec_push(&pack_opts
, "--progress");
88 else if (progress
== 2)
89 strvec_push(&pack_opts
, "--all-progress");
90 if (progress
&& all_progress_implied
)
91 strvec_push(&pack_opts
, "--all-progress-implied");
93 if (!startup_info
->have_repository
)
94 die(_("Need a repository to create a bundle."));
95 ret
= !!create_bundle(the_repository
, bundle_file
, argc
, argv
, &pack_opts
, version
);
100 static int cmd_bundle_verify(int argc
, const char **argv
, const char *prefix
) {
101 struct bundle_header header
= BUNDLE_HEADER_INIT
;
105 struct option options
[] = {
106 OPT_BOOL('q', "quiet", &quiet
,
107 N_("do not show bundle details")),
112 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
113 builtin_bundle_verify_usage
, options
, &bundle_file
);
114 /* bundle internals use argv[1] as further parameters */
116 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0) {
121 if (verify_bundle(the_repository
, &header
, !quiet
)) {
126 fprintf(stderr
, _("%s is okay\n"), bundle_file
);
130 bundle_header_release(&header
);
134 static int cmd_bundle_list_heads(int argc
, const char **argv
, const char *prefix
) {
135 struct bundle_header header
= BUNDLE_HEADER_INIT
;
138 struct option options
[] = {
143 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
144 builtin_bundle_list_heads_usage
, options
, &bundle_file
);
145 /* bundle internals use argv[1] as further parameters */
147 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0) {
152 ret
= !!list_bundle_refs(&header
, argc
, argv
);
155 bundle_header_release(&header
);
159 static int cmd_bundle_unbundle(int argc
, const char **argv
, const char *prefix
) {
160 struct bundle_header header
= BUNDLE_HEADER_INIT
;
163 int progress
= isatty(2);
165 struct option options
[] = {
166 OPT_BOOL(0, "progress", &progress
,
167 N_("show progress meter")),
171 struct strvec extra_index_pack_args
= STRVEC_INIT
;
173 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
174 builtin_bundle_unbundle_usage
, options
, &bundle_file
);
175 /* bundle internals use argv[1] as further parameters */
177 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0) {
181 if (!startup_info
->have_repository
)
182 die(_("Need a repository to unbundle."));
184 strvec_pushl(&extra_index_pack_args
, "-v", "--progress-title",
185 _("Unbundling objects"), NULL
);
186 ret
= !!unbundle(the_repository
, &header
, bundle_fd
,
187 &extra_index_pack_args
) ||
188 list_bundle_refs(&header
, argc
, argv
);
189 bundle_header_release(&header
);
195 int cmd_bundle(int argc
, const char **argv
, const char *prefix
)
197 struct option options
[] = {
202 argc
= parse_options(argc
, argv
, prefix
, options
, builtin_bundle_usage
,
203 PARSE_OPT_STOP_AT_NON_OPTION
);
205 packet_trace_identity("bundle");
208 usage_with_options(builtin_bundle_usage
, options
);
210 else if (!strcmp(argv
[0], "create"))
211 result
= cmd_bundle_create(argc
, argv
, prefix
);
212 else if (!strcmp(argv
[0], "verify"))
213 result
= cmd_bundle_verify(argc
, argv
, prefix
);
214 else if (!strcmp(argv
[0], "list-heads"))
215 result
= cmd_bundle_list_heads(argc
, argv
, prefix
);
216 else if (!strcmp(argv
[0], "unbundle"))
217 result
= cmd_bundle_unbundle(argc
, argv
, prefix
);
219 error(_("Unknown subcommand: %s"), argv
[0]);
220 usage_with_options(builtin_bundle_usage
, options
);
222 return result
? 1 : 0;