1 #define USE_THE_REPOSITORY_VARIABLE
7 #include "parse-options.h"
12 * Basic handler for bundle files to connect repositories via sneakernet.
13 * Invocation must include action.
14 * This function can create a bundle or provide information on an existing
15 * bundle supporting "fetch", "pull", and "ls-remote".
18 #define BUILTIN_BUNDLE_CREATE_USAGE \
19 N_("git bundle create [-q | --quiet | --progress]\n" \
20 " [--version=<version>] <file> <git-rev-list-args>")
21 #define BUILTIN_BUNDLE_VERIFY_USAGE \
22 N_("git bundle verify [-q | --quiet] <file>")
23 #define BUILTIN_BUNDLE_LIST_HEADS_USAGE \
24 N_("git bundle list-heads <file> [<refname>...]")
25 #define BUILTIN_BUNDLE_UNBUNDLE_USAGE \
26 N_("git bundle unbundle [--progress] <file> [<refname>...]")
28 static char const * const builtin_bundle_usage
[] = {
29 BUILTIN_BUNDLE_CREATE_USAGE
,
30 BUILTIN_BUNDLE_VERIFY_USAGE
,
31 BUILTIN_BUNDLE_LIST_HEADS_USAGE
,
32 BUILTIN_BUNDLE_UNBUNDLE_USAGE
,
36 static const char * const builtin_bundle_create_usage
[] = {
37 BUILTIN_BUNDLE_CREATE_USAGE
,
41 static const char * const builtin_bundle_verify_usage
[] = {
42 BUILTIN_BUNDLE_VERIFY_USAGE
,
46 static const char * const builtin_bundle_list_heads_usage
[] = {
47 BUILTIN_BUNDLE_LIST_HEADS_USAGE
,
51 static const char * const builtin_bundle_unbundle_usage
[] = {
52 BUILTIN_BUNDLE_UNBUNDLE_USAGE
,
56 static int parse_options_cmd_bundle(int argc
,
59 const char * const usagestr
[],
60 const struct option options
[],
62 argc
= parse_options(argc
, argv
, NULL
, options
, usagestr
,
63 PARSE_OPT_STOP_AT_NON_OPTION
);
65 usage_msg_opt(_("need a <file> argument"), usagestr
, options
);
66 *bundle_file
= prefix_filename_except_for_dash(prefix
, argv
[0]);
70 static int cmd_bundle_create(int argc
, const char **argv
, const char *prefix
) {
71 struct strvec pack_opts
= STRVEC_INIT
;
74 struct option options
[] = {
75 OPT_PASSTHRU_ARGV('q', "quiet", &pack_opts
, NULL
,
76 N_("do not show progress meter"),
78 OPT_PASSTHRU_ARGV(0, "progress", &pack_opts
, NULL
,
79 N_("show progress meter"),
81 OPT_PASSTHRU_ARGV(0, "all-progress", &pack_opts
, NULL
,
82 N_("historical; same as --progress"),
83 PARSE_OPT_NOARG
| PARSE_OPT_HIDDEN
),
84 OPT_PASSTHRU_ARGV(0, "all-progress-implied", &pack_opts
, NULL
,
85 N_("historical; does nothing"),
86 PARSE_OPT_NOARG
| PARSE_OPT_HIDDEN
),
87 OPT_INTEGER(0, "version", &version
,
88 N_("specify bundle format version")),
93 if (isatty(STDERR_FILENO
))
94 strvec_push(&pack_opts
, "--progress");
95 strvec_push(&pack_opts
, "--all-progress-implied");
97 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
98 builtin_bundle_create_usage
, options
, &bundle_file
);
99 /* bundle internals use argv[1] as further parameters */
101 if (!startup_info
->have_repository
)
102 die(_("Need a repository to create a bundle."));
103 ret
= !!create_bundle(the_repository
, bundle_file
, argc
, argv
, &pack_opts
, version
);
104 strvec_clear(&pack_opts
);
110 * Similar to read_bundle_header(), but handle "-" as stdin.
112 static int open_bundle(const char *path
, struct bundle_header
*header
,
115 if (!strcmp(path
, "-")) {
118 return read_bundle_header_fd(0, header
, "<stdin>");
123 return read_bundle_header(path
, header
);
126 static int cmd_bundle_verify(int argc
, const char **argv
, const char *prefix
) {
127 struct bundle_header header
= BUNDLE_HEADER_INIT
;
131 struct option options
[] = {
132 OPT_BOOL('q', "quiet", &quiet
,
133 N_("do not show bundle details")),
139 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
140 builtin_bundle_verify_usage
, options
, &bundle_file
);
141 /* bundle internals use argv[1] as further parameters */
143 if (!startup_info
->have_repository
) {
144 ret
= error(_("need a repository to verify a bundle"));
148 if ((bundle_fd
= open_bundle(bundle_file
, &header
, &name
)) < 0) {
153 if (verify_bundle(the_repository
, &header
,
154 quiet
? VERIFY_BUNDLE_QUIET
: VERIFY_BUNDLE_VERBOSE
)) {
159 fprintf(stderr
, _("%s is okay\n"), name
);
163 bundle_header_release(&header
);
167 static int cmd_bundle_list_heads(int argc
, const char **argv
, const char *prefix
) {
168 struct bundle_header header
= BUNDLE_HEADER_INIT
;
171 struct option options
[] = {
176 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
177 builtin_bundle_list_heads_usage
, options
, &bundle_file
);
178 /* bundle internals use argv[1] as further parameters */
180 if ((bundle_fd
= open_bundle(bundle_file
, &header
, NULL
)) < 0) {
185 ret
= !!list_bundle_refs(&header
, argc
, argv
);
188 bundle_header_release(&header
);
192 static int cmd_bundle_unbundle(int argc
, const char **argv
, const char *prefix
) {
193 struct bundle_header header
= BUNDLE_HEADER_INIT
;
196 int progress
= isatty(2);
198 struct option options
[] = {
199 OPT_BOOL(0, "progress", &progress
,
200 N_("show progress meter")),
204 struct strvec extra_index_pack_args
= STRVEC_INIT
;
206 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
207 builtin_bundle_unbundle_usage
, options
, &bundle_file
);
208 /* bundle internals use argv[1] as further parameters */
210 if (!startup_info
->have_repository
)
211 die(_("Need a repository to unbundle."));
213 if ((bundle_fd
= open_bundle(bundle_file
, &header
, NULL
)) < 0) {
218 strvec_pushl(&extra_index_pack_args
, "-v", "--progress-title",
219 _("Unbundling objects"), NULL
);
220 ret
= !!unbundle(the_repository
, &header
, bundle_fd
,
221 &extra_index_pack_args
, 0) ||
222 list_bundle_refs(&header
, argc
, argv
);
223 bundle_header_release(&header
);
226 strvec_clear(&extra_index_pack_args
);
231 int cmd_bundle(int argc
,
234 struct repository
*repo UNUSED
)
236 parse_opt_subcommand_fn
*fn
= NULL
;
237 struct option options
[] = {
238 OPT_SUBCOMMAND("create", &fn
, cmd_bundle_create
),
239 OPT_SUBCOMMAND("verify", &fn
, cmd_bundle_verify
),
240 OPT_SUBCOMMAND("list-heads", &fn
, cmd_bundle_list_heads
),
241 OPT_SUBCOMMAND("unbundle", &fn
, cmd_bundle_unbundle
),
245 argc
= parse_options(argc
, argv
, prefix
, options
, builtin_bundle_usage
,
248 packet_trace_identity("bundle");
250 return !!fn(argc
, argv
, prefix
);