@matheusbsbs / matheus-bagliano / commits / 79862b6b77
Fork 0

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/git@vger.kernel.org/msg182844.html <robbat2-20190806T191156-796782357Z@orbis-terrarum.net> Signed-off-by: Robin H. Johnson <robbat2@gentoo.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Robin H. Johnson committed Nov 10, 2019 at 12:41 UTC 79862b6b77c07b88ae1137fa602bf2046f979ad9
4 files changed +65 -10
Documentation/git-bundle.txt
+31 -2
@@ -9,7 +9,7 @@ git-bundle - Move objects and refs by archive
9 SYNOPSIS
10 --------
11 [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>
13 'git bundle' verify <file>
14 'git bundle' list-heads <file> [<refname>...]
15 'git bundle' unbundle <file> [<refname>...]
@@ -33,9 +33,11 @@ destination repository.
33 OPTIONS
34 -------
35
36 -create <file>::
36 +create [options] <file> <git-rev-list-args>::
37 Used to create a bundle named 'file'. This requires the
38 'git-rev-list-args' arguments to define the bundle contents.
39 + 'options' contains the options specific to the 'git bundle create'
40 + subcommand.
41
42 verify <file>::
43 Used to check that a bundle file is valid and will apply
@@ -75,6 +77,33 @@ unbundle <file>::
77 necessarily everything in the pack (in this case, 'git bundle' acts
78 like 'git fetch-pack').
79
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 +
107 SPECIFYING REFERENCES
108 ---------------------
109
builtin/bundle.c
+27 -3
@@ -1,4 +1,5 @@
1 #include "builtin.h"
2 +#include "argv-array.h"
3 #include "parse-options.h"
4 #include "cache.h"
5 #include "bundle.h"
@@ -11,7 +12,7 @@
12 */
13
14 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>"),
16 N_("git bundle verify <file>"),
17 N_("git bundle list-heads <file> [<refname>...]"),
18 N_("git bundle unbundle <file> [<refname>...]"),
@@ -19,7 +20,7 @@ static const char * const builtin_bundle_usage[] = {
20 };
21
22 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>"),
24 NULL
25 };
26
@@ -56,7 +57,20 @@ static int parse_options_cmd_bundle(int argc,
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;
@@ -65,9 +79,19 @@ static int cmd_bundle_create(int argc, const char **argv, const char *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."));
70 - return !!create_bundle(the_repository, bundle_file, argc, argv);
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) {
bundle.c
+5 -4
@@ -249,15 +249,16 @@ out:
249
250
251 /* 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)
253 {
254 struct child_process pack_objects = CHILD_PROCESS_INIT;
255 int i;
256
257 argv_array_pushl(&pack_objects.args,
258 - "pack-objects", "--all-progress-implied",
258 + "pack-objects",
259 "--stdout", "--thin", "--delta-base-offset",
260 NULL);
261 + argv_array_pushv(&pack_objects.args, pack_options->argv);
262 pack_objects.in = -1;
263 pack_objects.out = bundle_fd;
264 pack_objects.git_cmd = 1;
@@ -428,7 +429,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
429 }
430
431 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)
433 {
434 struct lock_file lock = LOCK_INIT;
435 int bundle_fd = -1;
@@ -470,7 +471,7 @@ int create_bundle(struct repository *r, const char *path,
471 goto err;
472
473 /* write pack */
473 - if (write_pack_data(bundle_fd, &revs))
474 + if (write_pack_data(bundle_fd, &revs, pack_options))
475 goto err;
476
477 if (!bundle_to_stdout) {
bundle.h
+2 -1
@@ -1,6 +1,7 @@
1 #ifndef BUNDLE_H
2 #define BUNDLE_H
3
4 +#include "argv-array.h"
5 #include "cache.h"
6
7 struct ref_list {
@@ -19,7 +20,7 @@ struct bundle_header {
20 int is_bundle(const char *path, int quiet);
21 int read_bundle_header(const char *path, struct bundle_header *header);
22 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);
24 int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
25 #define BUNDLE_VERBOSE 1
26 int unbundle(struct repository *r, struct bundle_header *header,