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>...]"),
44 static int parse_options_cmd_bundle(int argc
,
47 const char * const usagestr
[],
48 const struct option options
[],
51 newargc
= parse_options(argc
, argv
, NULL
, options
, usagestr
,
52 PARSE_OPT_STOP_AT_NON_OPTION
);
54 usage_with_options(usagestr
, options
);
55 *bundle_file
= prefix_filename(prefix
, argv
[0]);
59 static int cmd_bundle_create(int argc
, const char **argv
, const char *prefix
) {
60 int all_progress_implied
= 0;
61 int progress
= isatty(STDERR_FILENO
);
62 struct strvec pack_opts
;
65 struct option options
[] = {
66 OPT_SET_INT('q', "quiet", &progress
,
67 N_("do not show progress meter"), 0),
68 OPT_SET_INT(0, "progress", &progress
,
69 N_("show progress meter"), 1),
70 OPT_SET_INT(0, "all-progress", &progress
,
71 N_("show progress meter during object writing phase"), 2),
72 OPT_BOOL(0, "all-progress-implied",
73 &all_progress_implied
,
74 N_("similar to --all-progress when progress meter is shown")),
75 OPT_INTEGER(0, "version", &version
,
76 N_("specify bundle format version")),
81 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
82 builtin_bundle_create_usage
, options
, &bundle_file
);
83 /* bundle internals use argv[1] as further parameters */
85 strvec_init(&pack_opts
);
87 strvec_push(&pack_opts
, "--quiet");
88 else if (progress
== 1)
89 strvec_push(&pack_opts
, "--progress");
90 else if (progress
== 2)
91 strvec_push(&pack_opts
, "--all-progress");
92 if (progress
&& all_progress_implied
)
93 strvec_push(&pack_opts
, "--all-progress-implied");
95 if (!startup_info
->have_repository
)
96 die(_("Need a repository to create a bundle."));
97 ret
= !!create_bundle(the_repository
, bundle_file
, argc
, argv
, &pack_opts
, version
);
102 static int cmd_bundle_verify(int argc
, const char **argv
, const char *prefix
) {
103 struct bundle_header header
= BUNDLE_HEADER_INIT
;
107 struct option options
[] = {
108 OPT_BOOL('q', "quiet", &quiet
,
109 N_("do not show bundle details")),
114 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
115 builtin_bundle_verify_usage
, options
, &bundle_file
);
116 /* bundle internals use argv[1] as further parameters */
118 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0) {
123 if (verify_bundle(the_repository
, &header
, !quiet
)) {
128 fprintf(stderr
, _("%s is okay\n"), bundle_file
);
132 bundle_header_release(&header
);
136 static int cmd_bundle_list_heads(int argc
, const char **argv
, const char *prefix
) {
137 struct bundle_header header
= BUNDLE_HEADER_INIT
;
140 struct option options
[] = {
145 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
146 builtin_bundle_list_heads_usage
, options
, &bundle_file
);
147 /* bundle internals use argv[1] as further parameters */
149 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0) {
154 ret
= !!list_bundle_refs(&header
, argc
, argv
);
157 bundle_header_release(&header
);
161 static int cmd_bundle_unbundle(int argc
, const char **argv
, const char *prefix
) {
162 struct bundle_header header
= BUNDLE_HEADER_INIT
;
165 struct option options
[] = {
170 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
171 builtin_bundle_unbundle_usage
, options
, &bundle_file
);
172 /* bundle internals use argv[1] as further parameters */
174 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0) {
178 if (!startup_info
->have_repository
)
179 die(_("Need a repository to unbundle."));
180 ret
= !!unbundle(the_repository
, &header
, bundle_fd
, 0) ||
181 list_bundle_refs(&header
, argc
, argv
);
182 bundle_header_release(&header
);
188 int cmd_bundle(int argc
, const char **argv
, const char *prefix
)
190 struct option options
[] = {
191 OPT__VERBOSE(&verbose
, N_("be verbose; must be placed before a subcommand")),
196 argc
= parse_options(argc
, argv
, prefix
, options
, builtin_bundle_usage
,
197 PARSE_OPT_STOP_AT_NON_OPTION
);
199 packet_trace_identity("bundle");
202 usage_with_options(builtin_bundle_usage
, options
);
204 else if (!strcmp(argv
[0], "create"))
205 result
= cmd_bundle_create(argc
, argv
, prefix
);
206 else if (!strcmp(argv
[0], "verify"))
207 result
= cmd_bundle_verify(argc
, argv
, prefix
);
208 else if (!strcmp(argv
[0], "list-heads"))
209 result
= cmd_bundle_list_heads(argc
, argv
, prefix
);
210 else if (!strcmp(argv
[0], "unbundle"))
211 result
= cmd_bundle_unbundle(argc
, argv
, prefix
);
213 error(_("Unknown subcommand: %s"), argv
[0]);
214 usage_with_options(builtin_bundle_usage
, options
);
216 return result
? 1 : 0;