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
[],
49 const char **bundle_file
) {
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")),
79 const char* bundle_file
;
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 return !!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
;
105 struct option options
[] = {
106 OPT_BOOL('q', "quiet", &quiet
,
107 N_("do not show bundle details")),
110 const char* bundle_file
;
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 memset(&header
, 0, sizeof(header
));
117 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0)
120 if (verify_bundle(the_repository
, &header
, !quiet
))
122 fprintf(stderr
, _("%s is okay\n"), bundle_file
);
126 static int cmd_bundle_list_heads(int argc
, const char **argv
, const char *prefix
) {
127 struct bundle_header header
;
130 struct option options
[] = {
133 const char* bundle_file
;
135 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
136 builtin_bundle_list_heads_usage
, options
, &bundle_file
);
137 /* bundle internals use argv[1] as further parameters */
139 memset(&header
, 0, sizeof(header
));
140 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0)
143 return !!list_bundle_refs(&header
, argc
, argv
);
146 static int cmd_bundle_unbundle(int argc
, const char **argv
, const char *prefix
) {
147 struct bundle_header header
;
150 struct option options
[] = {
153 const char* bundle_file
;
155 argc
= parse_options_cmd_bundle(argc
, argv
, prefix
,
156 builtin_bundle_unbundle_usage
, options
, &bundle_file
);
157 /* bundle internals use argv[1] as further parameters */
159 memset(&header
, 0, sizeof(header
));
160 if ((bundle_fd
= read_bundle_header(bundle_file
, &header
)) < 0)
162 if (!startup_info
->have_repository
)
163 die(_("Need a repository to unbundle."));
164 return !!unbundle(the_repository
, &header
, bundle_fd
, 0) ||
165 list_bundle_refs(&header
, argc
, argv
);
168 int cmd_bundle(int argc
, const char **argv
, const char *prefix
)
170 struct option options
[] = {
171 OPT__VERBOSE(&verbose
, N_("be verbose; must be placed before a subcommand")),
176 argc
= parse_options(argc
, argv
, prefix
, options
, builtin_bundle_usage
,
177 PARSE_OPT_STOP_AT_NON_OPTION
);
179 packet_trace_identity("bundle");
182 usage_with_options(builtin_bundle_usage
, options
);
184 else if (!strcmp(argv
[0], "create"))
185 result
= cmd_bundle_create(argc
, argv
, prefix
);
186 else if (!strcmp(argv
[0], "verify"))
187 result
= cmd_bundle_verify(argc
, argv
, prefix
);
188 else if (!strcmp(argv
[0], "list-heads"))
189 result
= cmd_bundle_list_heads(argc
, argv
, prefix
);
190 else if (!strcmp(argv
[0], "unbundle"))
191 result
= cmd_bundle_unbundle(argc
, argv
, prefix
);
193 error(_("Unknown subcommand: %s"), argv
[0]);
194 usage_with_options(builtin_bundle_usage
, options
);
196 return result
? 1 : 0;