Skip to content

Commit ca5c8aa

Browse files
committed
Merge branch 'rj/bundle-ui-updates'
"git bundle" has been taught to use the parse options API. "git bundle verify" learned "--quiet" and "git bundle create" learned options to control the progress output. * rj/bundle-ui-updates: bundle-verify: add --quiet bundle-create: progress output control bundle: framework for options before bundle file
2 parents d2489ce + e0eba64 commit ca5c8aa

File tree

4 files changed

+211
-53
lines changed

4 files changed

+211
-53
lines changed

Documentation/git-bundle.txt

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ git-bundle - Move objects and refs by archive
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git bundle' create <file> <git-rev-list-args>
13-
'git bundle' verify <file>
12+
'git bundle' create [-q | --quiet | --progress | --all-progress] [--all-progress-implied] <file> <git-rev-list-args>
13+
'git bundle' verify [-q | --quiet] <file>
1414
'git bundle' list-heads <file> [<refname>...]
1515
'git bundle' unbundle <file> [<refname>...]
1616

@@ -33,9 +33,11 @@ destination repository.
3333
OPTIONS
3434
-------
3535

36-
create <file>::
36+
create [options] <file> <git-rev-list-args>::
3737
Used to create a bundle named 'file'. This requires the
3838
'git-rev-list-args' arguments to define the bundle contents.
39+
'options' contains the options specific to the 'git bundle create'
40+
subcommand.
3941

4042
verify <file>::
4143
Used to check that a bundle file is valid and will apply
@@ -75,6 +77,33 @@ unbundle <file>::
7577
necessarily everything in the pack (in this case, 'git bundle' acts
7678
like 'git fetch-pack').
7779

80+
--progress::
81+
Progress status is reported on the standard error stream
82+
by default when it is attached to a terminal, unless -q
83+
is specified. This flag forces progress status even if
84+
the standard error stream is not directed to a terminal.
85+
86+
--all-progress::
87+
When --stdout is specified then progress report is
88+
displayed during the object count and compression phases
89+
but inhibited during the write-out phase. The reason is
90+
that in some cases the output stream is directly linked
91+
to another command which may wish to display progress
92+
status of its own as it processes incoming pack data.
93+
This flag is like --progress except that it forces progress
94+
report for the write-out phase as well even if --stdout is
95+
used.
96+
97+
--all-progress-implied::
98+
This is used to imply --all-progress whenever progress display
99+
is activated. Unlike --all-progress this flag doesn't actually
100+
force any progress display by itself.
101+
102+
-q::
103+
--quiet::
104+
This flag makes the command not to report its progress
105+
on the standard error stream.
106+
78107
SPECIFYING REFERENCES
79108
---------------------
80109

builtin/bundle.c

Lines changed: 172 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "builtin.h"
2+
#include "argv-array.h"
3+
#include "parse-options.h"
24
#include "cache.h"
35
#include "bundle.h"
46

@@ -9,59 +11,184 @@
911
* bundle supporting "fetch", "pull", and "ls-remote".
1012
*/
1113

12-
static const char builtin_bundle_usage[] =
13-
"git bundle create <file> <git-rev-list args>\n"
14-
" or: git bundle verify <file>\n"
15-
" or: git bundle list-heads <file> [<refname>...]\n"
16-
" or: git bundle unbundle <file> [<refname>...]";
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>...]"),
19+
NULL
20+
};
1721

18-
int cmd_bundle(int argc, const char **argv, const char *prefix)
19-
{
22+
static const char * const builtin_bundle_create_usage[] = {
23+
N_("git bundle create [<options>] <file> <git-rev-list args>"),
24+
NULL
25+
};
26+
27+
static const char * const builtin_bundle_verify_usage[] = {
28+
N_("git bundle verify [<options>] <file>"),
29+
NULL
30+
};
31+
32+
static const char * const builtin_bundle_list_heads_usage[] = {
33+
N_("git bundle list-heads <file> [<refname>...]"),
34+
NULL
35+
};
36+
37+
static const char * const builtin_bundle_unbundle_usage[] = {
38+
N_("git bundle unbundle <file> [<refname>...]"),
39+
NULL
40+
};
41+
42+
static int verbose;
43+
44+
static int parse_options_cmd_bundle(int argc,
45+
const char **argv,
46+
const char* prefix,
47+
const char * const usagestr[],
48+
const struct option options[],
49+
const char **bundle_file) {
50+
int newargc;
51+
newargc = parse_options(argc, argv, NULL, options, usagestr,
52+
PARSE_OPT_STOP_AT_NON_OPTION);
53+
if (argc < 1)
54+
usage_with_options(usagestr, options);
55+
*bundle_file = prefix_filename(prefix, argv[0]);
56+
return newargc;
57+
}
58+
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 argv_array pack_opts;
63+
64+
struct option options[] = {
65+
OPT_SET_INT('q', "quiet", &progress,
66+
N_("do not show progress meter"), 0),
67+
OPT_SET_INT(0, "progress", &progress,
68+
N_("show progress meter"), 1),
69+
OPT_SET_INT(0, "all-progress", &progress,
70+
N_("show progress meter during object writing phase"), 2),
71+
OPT_BOOL(0, "all-progress-implied",
72+
&all_progress_implied,
73+
N_("similar to --all-progress when progress meter is shown")),
74+
OPT_END()
75+
};
76+
const char* bundle_file;
77+
78+
argc = parse_options_cmd_bundle(argc, argv, prefix,
79+
builtin_bundle_create_usage, options, &bundle_file);
80+
/* bundle internals use argv[1] as further parameters */
81+
82+
argv_array_init(&pack_opts);
83+
if (progress == 0)
84+
argv_array_push(&pack_opts, "--quiet");
85+
else if (progress == 1)
86+
argv_array_push(&pack_opts, "--progress");
87+
else if (progress == 2)
88+
argv_array_push(&pack_opts, "--all-progress");
89+
if (progress && all_progress_implied)
90+
argv_array_push(&pack_opts, "--all-progress-implied");
91+
92+
if (!startup_info->have_repository)
93+
die(_("Need a repository to create a bundle."));
94+
return !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts);
95+
}
96+
97+
static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
2098
struct bundle_header header;
21-
const char *cmd, *bundle_file;
2299
int bundle_fd = -1;
100+
int quiet = 0;
23101

24-
if (argc < 3)
25-
usage(builtin_bundle_usage);
102+
struct option options[] = {
103+
OPT_BOOL('q', "quiet", &quiet,
104+
N_("do not show bundle details")),
105+
OPT_END()
106+
};
107+
const char* bundle_file;
26108

27-
cmd = argv[1];
28-
bundle_file = prefix_filename(prefix, argv[2]);
29-
argc -= 2;
30-
argv += 2;
109+
argc = parse_options_cmd_bundle(argc, argv, prefix,
110+
builtin_bundle_verify_usage, options, &bundle_file);
111+
/* bundle internals use argv[1] as further parameters */
31112

32113
memset(&header, 0, sizeof(header));
33-
if (strcmp(cmd, "create") && (bundle_fd =
34-
read_bundle_header(bundle_file, &header)) < 0)
114+
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0)
115+
return 1;
116+
close(bundle_fd);
117+
if (verify_bundle(the_repository, &header, !quiet))
35118
return 1;
119+
fprintf(stderr, _("%s is okay\n"), bundle_file);
120+
return 0;
121+
}
36122

37-
if (!strcmp(cmd, "verify")) {
38-
close(bundle_fd);
39-
if (argc != 1) {
40-
usage(builtin_bundle_usage);
41-
return 1;
42-
}
43-
if (verify_bundle(the_repository, &header, 1))
44-
return 1;
45-
fprintf(stderr, _("%s is okay\n"), bundle_file);
46-
return 0;
47-
}
48-
if (!strcmp(cmd, "list-heads")) {
49-
close(bundle_fd);
50-
return !!list_bundle_refs(&header, argc, argv);
123+
static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix) {
124+
struct bundle_header header;
125+
int bundle_fd = -1;
126+
127+
struct option options[] = {
128+
OPT_END()
129+
};
130+
const char* bundle_file;
131+
132+
argc = parse_options_cmd_bundle(argc, argv, prefix,
133+
builtin_bundle_list_heads_usage, options, &bundle_file);
134+
/* bundle internals use argv[1] as further parameters */
135+
136+
memset(&header, 0, sizeof(header));
137+
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0)
138+
return 1;
139+
close(bundle_fd);
140+
return !!list_bundle_refs(&header, argc, argv);
141+
}
142+
143+
static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix) {
144+
struct bundle_header header;
145+
int bundle_fd = -1;
146+
147+
struct option options[] = {
148+
OPT_END()
149+
};
150+
const char* bundle_file;
151+
152+
argc = parse_options_cmd_bundle(argc, argv, prefix,
153+
builtin_bundle_unbundle_usage, options, &bundle_file);
154+
/* bundle internals use argv[1] as further parameters */
155+
156+
memset(&header, 0, sizeof(header));
157+
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0)
158+
return 1;
159+
if (!startup_info->have_repository)
160+
die(_("Need a repository to unbundle."));
161+
return !!unbundle(the_repository, &header, bundle_fd, 0) ||
162+
list_bundle_refs(&header, argc, argv);
163+
}
164+
165+
int cmd_bundle(int argc, const char **argv, const char *prefix)
166+
{
167+
struct option options[] = {
168+
OPT__VERBOSE(&verbose, N_("be verbose; must be placed before a subcommand")),
169+
OPT_END()
170+
};
171+
int result;
172+
173+
argc = parse_options(argc, argv, prefix, options, builtin_bundle_usage,
174+
PARSE_OPT_STOP_AT_NON_OPTION);
175+
176+
packet_trace_identity("bundle");
177+
178+
if (argc < 2)
179+
usage_with_options(builtin_bundle_usage, options);
180+
181+
else if (!strcmp(argv[0], "create"))
182+
result = cmd_bundle_create(argc, argv, prefix);
183+
else if (!strcmp(argv[0], "verify"))
184+
result = cmd_bundle_verify(argc, argv, prefix);
185+
else if (!strcmp(argv[0], "list-heads"))
186+
result = cmd_bundle_list_heads(argc, argv, prefix);
187+
else if (!strcmp(argv[0], "unbundle"))
188+
result = cmd_bundle_unbundle(argc, argv, prefix);
189+
else {
190+
error(_("Unknown subcommand: %s"), argv[0]);
191+
usage_with_options(builtin_bundle_usage, options);
51192
}
52-
if (!strcmp(cmd, "create")) {
53-
if (argc < 2) {
54-
usage(builtin_bundle_usage);
55-
return 1;
56-
}
57-
if (!startup_info->have_repository)
58-
die(_("Need a repository to create a bundle."));
59-
return !!create_bundle(the_repository, bundle_file, argc, argv);
60-
} else if (!strcmp(cmd, "unbundle")) {
61-
if (!startup_info->have_repository)
62-
die(_("Need a repository to unbundle."));
63-
return !!unbundle(the_repository, &header, bundle_fd, 0) ||
64-
list_bundle_refs(&header, argc, argv);
65-
} else
66-
usage(builtin_bundle_usage);
193+
return result ? 1 : 0;
67194
}

bundle.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,16 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
249249

250250

251251
/* Write the pack data to bundle_fd */
252-
static int write_pack_data(int bundle_fd, struct rev_info *revs)
252+
static int write_pack_data(int bundle_fd, struct rev_info *revs, struct argv_array *pack_options)
253253
{
254254
struct child_process pack_objects = CHILD_PROCESS_INIT;
255255
int i;
256256

257257
argv_array_pushl(&pack_objects.args,
258-
"pack-objects", "--all-progress-implied",
258+
"pack-objects",
259259
"--stdout", "--thin", "--delta-base-offset",
260260
NULL);
261+
argv_array_pushv(&pack_objects.args, pack_options->argv);
261262
pack_objects.in = -1;
262263
pack_objects.out = bundle_fd;
263264
pack_objects.git_cmd = 1;
@@ -428,7 +429,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
428429
}
429430

430431
int create_bundle(struct repository *r, const char *path,
431-
int argc, const char **argv)
432+
int argc, const char **argv, struct argv_array *pack_options)
432433
{
433434
struct lock_file lock = LOCK_INIT;
434435
int bundle_fd = -1;
@@ -470,7 +471,7 @@ int create_bundle(struct repository *r, const char *path,
470471
goto err;
471472

472473
/* write pack */
473-
if (write_pack_data(bundle_fd, &revs))
474+
if (write_pack_data(bundle_fd, &revs, pack_options))
474475
goto err;
475476

476477
if (!bundle_to_stdout) {

bundle.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef BUNDLE_H
22
#define BUNDLE_H
33

4+
#include "argv-array.h"
45
#include "cache.h"
56

67
struct ref_list {
@@ -19,7 +20,7 @@ struct bundle_header {
1920
int is_bundle(const char *path, int quiet);
2021
int read_bundle_header(const char *path, struct bundle_header *header);
2122
int create_bundle(struct repository *r, const char *path,
22-
int argc, const char **argv);
23+
int argc, const char **argv, struct argv_array *pack_options);
2324
int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
2425
#define BUNDLE_VERBOSE 1
2526
int unbundle(struct repository *r, struct bundle_header *header,

0 commit comments

Comments
 (0)