Skip to content

Commit 79862b6

Browse files
robbat2gitster
authored andcommitted
bundle-create: progress output control
Support the progress output options from pack-objects in git-bundle's create subcommand. Most notably, this provides --quiet as requested on the git mailing list per [1] Reference: https://www.mail-archive.com/[email protected]/msg182844.html <[email protected]> Signed-off-by: Robin H. Johnson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 73c3253 commit 79862b6

File tree

4 files changed

+65
-10
lines changed

4 files changed

+65
-10
lines changed

Documentation/git-bundle.txt

+31-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-bundle - Move objects and refs by archive
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git bundle' create <file> <git-rev-list-args>
12+
'git bundle' create [-q | --quiet | --progress | --all-progress] [--all-progress-implied] <file> <git-rev-list-args>
1313
'git bundle' verify <file>
1414
'git bundle' list-heads <file> [<refname>...]
1515
'git bundle' unbundle <file> [<refname>...]
@@ -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

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "builtin.h"
2+
#include "argv-array.h"
23
#include "parse-options.h"
34
#include "cache.h"
45
#include "bundle.h"
@@ -11,15 +12,15 @@
1112
*/
1213

1314
static const char * const builtin_bundle_usage[] = {
14-
N_("git bundle create <file> <git-rev-list args>"),
15+
N_("git bundle create [<options>] <file> <git-rev-list args>"),
1516
N_("git bundle verify <file>"),
1617
N_("git bundle list-heads <file> [<refname>...]"),
1718
N_("git bundle unbundle <file> [<refname>...]"),
1819
NULL
1920
};
2021

2122
static const char * const builtin_bundle_create_usage[] = {
22-
N_("git bundle create <file> <git-rev-list args>"),
23+
N_("git bundle create [<options>] <file> <git-rev-list args>"),
2324
NULL
2425
};
2526

@@ -56,7 +57,20 @@ static int parse_options_cmd_bundle(int argc,
5657
}
5758

5859
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+
5964
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")),
6074
OPT_END()
6175
};
6276
const char* bundle_file;
@@ -65,9 +79,19 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
6579
builtin_bundle_create_usage, options, &bundle_file);
6680
/* bundle internals use argv[1] as further parameters */
6781

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+
6892
if (!startup_info->have_repository)
6993
die(_("Need a repository to create a bundle."));
70-
return !!create_bundle(the_repository, bundle_file, argc, argv);
94+
return !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts);
7195
}
7296

7397
static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {

bundle.c

+5-4
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

+2-1
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)