Skip to content

Commit 67fc02b

Browse files
committed
Merge branch 'ab/unbundle-progress'
Add progress display to "git bundle unbundle". * ab/unbundle-progress: bundle: show progress on "unbundle" index-pack: add --progress-title option bundle API: change "flags" to be "extra_index_pack_args" bundle API: start writing API documentation
2 parents a1af533 + d941cc4 commit 67fc02b

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

Documentation/git-bundle.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313
[--version=<version>] <file> <git-rev-list-args>
1414
'git bundle' verify [-q | --quiet] <file>
1515
'git bundle' list-heads <file> [<refname>...]
16-
'git bundle' unbundle <file> [<refname>...]
16+
'git bundle' unbundle [--progress] <file> [<refname>...]
1717

1818
DESCRIPTION
1919
-----------

Documentation/git-index-pack.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ OPTIONS
8282
--strict::
8383
Die, if the pack contains broken objects or links.
8484

85+
--progress-title::
86+
For internal use only.
87+
+
88+
Set the title of the progress bar. The title is "Receiving objects" by
89+
default and "Indexing objects" when `--stdin` is specified.
90+
8591
--check-self-contained-and-connected::
8692
Die if the pack contains broken links. For internal use only.
8793

builtin/bundle.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,15 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
162162
struct bundle_header header = BUNDLE_HEADER_INIT;
163163
int bundle_fd = -1;
164164
int ret;
165+
int progress = isatty(2);
166+
165167
struct option options[] = {
168+
OPT_BOOL(0, "progress", &progress,
169+
N_("show progress meter")),
166170
OPT_END()
167171
};
168172
char *bundle_file;
173+
struct strvec extra_index_pack_args = STRVEC_INIT;
169174

170175
argc = parse_options_cmd_bundle(argc, argv, prefix,
171176
builtin_bundle_unbundle_usage, options, &bundle_file);
@@ -177,7 +182,11 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
177182
}
178183
if (!startup_info->have_repository)
179184
die(_("Need a repository to unbundle."));
180-
ret = !!unbundle(the_repository, &header, bundle_fd, 0) ||
185+
if (progress)
186+
strvec_pushl(&extra_index_pack_args, "-v", "--progress-title",
187+
_("Unbundling objects"), NULL);
188+
ret = !!unbundle(the_repository, &header, bundle_fd,
189+
&extra_index_pack_args) ||
181190
list_bundle_refs(&header, argc, argv);
182191
bundle_header_release(&header);
183192
cleanup:

builtin/index-pack.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static int strict;
122122
static int do_fsck_object;
123123
static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
124124
static int verbose;
125+
static const char *progress_title;
125126
static int show_resolving_progress;
126127
static int show_stat;
127128
static int check_self_contained_and_connected;
@@ -1153,6 +1154,7 @@ static void parse_pack_objects(unsigned char *hash)
11531154

11541155
if (verbose)
11551156
progress = start_progress(
1157+
progress_title ? progress_title :
11561158
from_stdin ? _("Receiving objects") : _("Indexing objects"),
11571159
nr_objects);
11581160
for (i = 0; i < nr_objects; i++) {
@@ -1800,6 +1802,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
18001802
input_len = sizeof(*hdr);
18011803
} else if (!strcmp(arg, "-v")) {
18021804
verbose = 1;
1805+
} else if (!strcmp(arg, "--progress-title")) {
1806+
if (progress_title || (i+1) >= argc)
1807+
usage(index_pack_usage);
1808+
progress_title = argv[++i];
18031809
} else if (!strcmp(arg, "--show-resolving-progress")) {
18041810
show_resolving_progress = 1;
18051811
} else if (!strcmp(arg, "--report-end-of-input")) {

bundle.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -569,18 +569,18 @@ int create_bundle(struct repository *r, const char *path,
569569
}
570570

571571
int unbundle(struct repository *r, struct bundle_header *header,
572-
int bundle_fd, int flags)
572+
int bundle_fd, struct strvec *extra_index_pack_args)
573573
{
574-
const char *argv_index_pack[] = {"index-pack",
575-
"--fix-thin", "--stdin", NULL, NULL};
576574
struct child_process ip = CHILD_PROCESS_INIT;
575+
strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL);
577576

578-
if (flags & BUNDLE_VERBOSE)
579-
argv_index_pack[3] = "-v";
577+
if (extra_index_pack_args) {
578+
strvec_pushv(&ip.args, extra_index_pack_args->v);
579+
strvec_clear(extra_index_pack_args);
580+
}
580581

581582
if (verify_bundle(r, header, 0))
582583
return -1;
583-
ip.argv = argv_index_pack;
584584
ip.in = bundle_fd;
585585
ip.no_stdout = 1;
586586
ip.git_cmd = 1;

bundle.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,19 @@ int create_bundle(struct repository *r, const char *path,
2626
int argc, const char **argv, struct strvec *pack_options,
2727
int version);
2828
int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
29-
#define BUNDLE_VERBOSE 1
29+
30+
/**
31+
* Unbundle after reading the header with read_bundle_header().
32+
*
33+
* We'll invoke "git index-pack --stdin --fix-thin" for you on the
34+
* provided `bundle_fd` from read_bundle_header().
35+
*
36+
* Provide "extra_index_pack_args" to pass any extra arguments
37+
* (e.g. "-v" for verbose/progress), NULL otherwise. The provided
38+
* "extra_index_pack_args" (if any) will be strvec_clear()'d for you.
39+
*/
3040
int unbundle(struct repository *r, struct bundle_header *header,
31-
int bundle_fd, int flags);
41+
int bundle_fd, struct strvec *extra_index_pack_args);
3242
int list_bundle_refs(struct bundle_header *header,
3343
int argc, const char **argv);
3444

transport.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,16 @@ static int fetch_refs_from_bundle(struct transport *transport,
162162
int nr_heads, struct ref **to_fetch)
163163
{
164164
struct bundle_transport_data *data = transport->data;
165+
struct strvec extra_index_pack_args = STRVEC_INIT;
165166
int ret;
166167

168+
if (transport->progress)
169+
strvec_push(&extra_index_pack_args, "-v");
170+
167171
if (!data->get_refs_from_bundle_called)
168172
get_refs_from_bundle(transport, 0, NULL);
169173
ret = unbundle(the_repository, &data->header, data->fd,
170-
transport->progress ? BUNDLE_VERBOSE : 0);
174+
&extra_index_pack_args);
171175
transport->hash_algo = data->header.hash_algo;
172176
return ret;
173177
}

0 commit comments

Comments
 (0)