Skip to content

Commit 3928e90

Browse files
committed
Merge branch 'ds/partial-bundle-more'
Code clean-up. * ds/partial-bundle-more: pack-objects: lazily set up "struct rev_info", don't leak bundle: output hash information in 'verify' bundle: move capabilities to end of 'verify' pack-objects: parse --filter directly into revs.filter pack-objects: move revs out of get_object_list() list-objects-filter: remove CL_ARG__FILTER
2 parents 1041d58 + 5cb2827 commit 3928e90

File tree

8 files changed

+94
-47
lines changed

8 files changed

+94
-47
lines changed

Documentation/git-bundle.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ verify <file>::
7575
cleanly to the current repository. This includes checks on the
7676
bundle format itself as well as checking that the prerequisite
7777
commits exist and are fully linked in the current repository.
78-
Information about additional capabilities, such as "object filter",
79-
is printed. See "Capabilities" in link:technical/bundle-format.html
80-
for more information. Finally, 'git bundle' prints a list of
81-
missing commits, if any. The exit code is zero for success, but
82-
will be nonzero if the bundle file is invalid.
78+
Then, 'git bundle' prints a list of missing commits, if any.
79+
Finally, information about additional capabilities, such as "object
80+
filter", is printed. See "Capabilities" in link:technical/bundle-format.html
81+
for more information. The exit code is zero for success, but will
82+
be nonzero if the bundle file is invalid.
8383

8484
list-heads <file>::
8585
Lists the references defined in the bundle. If followed by a

builtin/fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
153153
args.from_promisor = 1;
154154
continue;
155155
}
156-
if (skip_prefix(arg, ("--" CL_ARG__FILTER "="), &arg)) {
156+
if (skip_prefix(arg, ("--filter="), &arg)) {
157157
parse_list_objects_filter(&args.filter_options, arg);
158158
continue;
159159
}
160-
if (!strcmp(arg, ("--no-" CL_ARG__FILTER))) {
160+
if (!strcmp(arg, ("--no-filter"))) {
161161
list_objects_filter_set_no_filter(&args.filter_options);
162162
continue;
163163
}

builtin/pack-objects.c

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ static unsigned long cache_max_small_delta_size = 1000;
237237

238238
static unsigned long window_memory_limit = 0;
239239

240-
static struct list_objects_filter_options filter_options;
241-
242240
static struct string_list uri_protocols = STRING_LIST_INIT_NODUP;
243241

244242
enum missing_action {
@@ -3724,20 +3722,17 @@ static void mark_bitmap_preferred_tips(void)
37243722
}
37253723
}
37263724

3727-
static void get_object_list(int ac, const char **av)
3725+
static void get_object_list(struct rev_info *revs, int ac, const char **av)
37283726
{
3729-
struct rev_info revs;
37303727
struct setup_revision_opt s_r_opt = {
37313728
.allow_exclude_promisor_objects = 1,
37323729
};
37333730
char line[1000];
37343731
int flags = 0;
37353732
int save_warning;
37363733

3737-
repo_init_revisions(the_repository, &revs, NULL);
37383734
save_commit_buffer = 0;
3739-
setup_revisions(ac, av, &revs, &s_r_opt);
3740-
list_objects_filter_copy(&revs.filter, &filter_options);
3735+
setup_revisions(ac, av, revs, &s_r_opt);
37413736

37423737
/* make sure shallows are read */
37433738
is_repository_shallow(the_repository);
@@ -3767,13 +3762,13 @@ static void get_object_list(int ac, const char **av)
37673762
}
37683763
die(_("not a rev '%s'"), line);
37693764
}
3770-
if (handle_revision_arg(line, &revs, flags, REVARG_CANNOT_BE_FILENAME))
3765+
if (handle_revision_arg(line, revs, flags, REVARG_CANNOT_BE_FILENAME))
37713766
die(_("bad revision '%s'"), line);
37723767
}
37733768

37743769
warn_on_object_refname_ambiguity = save_warning;
37753770

3776-
if (use_bitmap_index && !get_object_list_from_bitmap(&revs))
3771+
if (use_bitmap_index && !get_object_list_from_bitmap(revs))
37773772
return;
37783773

37793774
if (use_delta_islands)
@@ -3782,24 +3777,24 @@ static void get_object_list(int ac, const char **av)
37823777
if (write_bitmap_index)
37833778
mark_bitmap_preferred_tips();
37843779

3785-
if (prepare_revision_walk(&revs))
3780+
if (prepare_revision_walk(revs))
37863781
die(_("revision walk setup failed"));
3787-
mark_edges_uninteresting(&revs, show_edge, sparse);
3782+
mark_edges_uninteresting(revs, show_edge, sparse);
37883783

37893784
if (!fn_show_object)
37903785
fn_show_object = show_object;
3791-
traverse_commit_list(&revs,
3786+
traverse_commit_list(revs,
37923787
show_commit, fn_show_object,
37933788
NULL);
37943789

37953790
if (unpack_unreachable_expiration) {
3796-
revs.ignore_missing_links = 1;
3797-
if (add_unseen_recent_objects_to_traversal(&revs,
3791+
revs->ignore_missing_links = 1;
3792+
if (add_unseen_recent_objects_to_traversal(revs,
37983793
unpack_unreachable_expiration))
37993794
die(_("unable to add recent objects"));
3800-
if (prepare_revision_walk(&revs))
3795+
if (prepare_revision_walk(revs))
38013796
die(_("revision walk setup failed"));
3802-
traverse_commit_list(&revs, record_recent_commit,
3797+
traverse_commit_list(revs, record_recent_commit,
38033798
record_recent_object, NULL);
38043799
}
38053800

@@ -3872,6 +3867,21 @@ static int option_parse_unpack_unreachable(const struct option *opt,
38723867
return 0;
38733868
}
38743869

3870+
struct po_filter_data {
3871+
unsigned have_revs:1;
3872+
struct rev_info revs;
3873+
};
3874+
3875+
static struct list_objects_filter_options *po_filter_revs_init(void *value)
3876+
{
3877+
struct po_filter_data *data = value;
3878+
3879+
repo_init_revisions(the_repository, &data->revs, NULL);
3880+
data->have_revs = 1;
3881+
3882+
return &data->revs.filter;
3883+
}
3884+
38753885
int cmd_pack_objects(int argc, const char **argv, const char *prefix)
38763886
{
38773887
int use_internal_rev_list = 0;
@@ -3882,6 +3892,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
38823892
int rev_list_index = 0;
38833893
int stdin_packs = 0;
38843894
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
3895+
struct po_filter_data pfd = { .have_revs = 0 };
3896+
38853897
struct option pack_objects_options[] = {
38863898
OPT_SET_INT('q', "quiet", &progress,
38873899
N_("do not show progress meter"), 0),
@@ -3967,7 +3979,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
39673979
&write_bitmap_index,
39683980
N_("write a bitmap index if possible"),
39693981
WRITE_BITMAP_QUIET, PARSE_OPT_HIDDEN),
3970-
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
3982+
OPT_PARSE_LIST_OBJECTS_FILTER_INIT(&pfd, po_filter_revs_init),
39713983
OPT_CALLBACK_F(0, "missing", NULL, N_("action"),
39723984
N_("handling for missing objects"), PARSE_OPT_NONEG,
39733985
option_parse_missing_action),
@@ -4087,7 +4099,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
40874099
if (!rev_list_all || !rev_list_reflog || !rev_list_index)
40884100
unpack_unreachable_expiration = 0;
40894101

4090-
if (filter_options.choice) {
4102+
if (pfd.have_revs && pfd.revs.filter.choice) {
40914103
if (!pack_to_stdout)
40924104
die(_("cannot use --filter without --stdout"));
40934105
if (stdin_packs)
@@ -4163,8 +4175,13 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
41634175
add_unreachable_loose_objects();
41644176
} else if (!use_internal_rev_list) {
41654177
read_object_list_from_stdin();
4178+
} else if (pfd.have_revs) {
4179+
get_object_list(&pfd.revs, rp.nr, rp.v);
41664180
} else {
4167-
get_object_list(rp.nr, rp.v);
4181+
struct rev_info revs;
4182+
4183+
repo_init_revisions(the_repository, &revs, NULL);
4184+
get_object_list(&revs, rp.nr, rp.v);
41684185
}
41694186
cleanup_preferred_base();
41704187
if (include_tag && nr_result)

bundle.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,6 @@ int verify_bundle(struct repository *r,
267267
(uintmax_t)r->nr);
268268
list_refs(r, 0, NULL);
269269

270-
if (header->filter.choice) {
271-
printf_ln("The bundle uses this filter: %s",
272-
list_objects_filter_spec(&header->filter));
273-
}
274-
275270
r = &header->prerequisites;
276271
if (!r->nr) {
277272
printf_ln(_("The bundle records a complete history."));
@@ -282,6 +277,12 @@ int verify_bundle(struct repository *r,
282277
(uintmax_t)r->nr);
283278
list_refs(r, 0, NULL);
284279
}
280+
281+
printf_ln("The bundle uses this hash algorithm: %s",
282+
header->hash_algo->name);
283+
if (header->filter.choice)
284+
printf_ln("The bundle uses this filter: %s",
285+
list_objects_filter_spec(&header->filter));
285286
}
286287
return ret;
287288
}

list-objects-filter-options.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ int opt_parse_list_objects_filter(const struct option *opt,
285285
const char *arg, int unset)
286286
{
287287
struct list_objects_filter_options *filter_options = opt->value;
288+
opt_lof_init init = (opt_lof_init)opt->defval;
289+
290+
if (init)
291+
filter_options = init(opt->value);
288292

289293
if (unset || !arg)
290294
list_objects_filter_set_no_filter(filter_options);

list-objects-filter-options.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ struct list_objects_filter_options {
6969
*/
7070
};
7171

72-
/* Normalized command line arguments */
73-
#define CL_ARG__FILTER "filter"
74-
7572
/*
7673
* Parse value of the argument to the "filter" keyword.
7774
* On the command line this looks like:
@@ -107,13 +104,31 @@ void parse_list_objects_filter(
107104
struct list_objects_filter_options *filter_options,
108105
const char *arg);
109106

107+
/**
108+
* The opt->value to opt_parse_list_objects_filter() is either a
109+
* "struct list_objects_filter_option *" when using
110+
* OPT_PARSE_LIST_OBJECTS_FILTER().
111+
*
112+
* Or, if using no "struct option" field is used by the callback,
113+
* except the "defval" which is expected to be an "opt_lof_init"
114+
* function, which is called with the "opt->value" and must return a
115+
* pointer to the ""struct list_objects_filter_option *" to be used.
116+
*
117+
* The OPT_PARSE_LIST_OBJECTS_FILTER_INIT() can be used e.g. the
118+
* "struct list_objects_filter_option" is embedded in a "struct
119+
* rev_info", which the "defval" could be tasked with lazily
120+
* initializing. See cmd_pack_objects() for an example.
121+
*/
110122
int opt_parse_list_objects_filter(const struct option *opt,
111123
const char *arg, int unset);
124+
typedef struct list_objects_filter_options *(*opt_lof_init)(void *);
125+
#define OPT_PARSE_LIST_OBJECTS_FILTER_INIT(fo, init) \
126+
{ OPTION_CALLBACK, 0, "filter", (fo), N_("args"), \
127+
N_("object filtering"), 0, opt_parse_list_objects_filter, \
128+
(intptr_t)(init) }
112129

113130
#define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
114-
OPT_CALLBACK(0, CL_ARG__FILTER, fo, N_("args"), \
115-
N_("object filtering"), \
116-
opt_parse_list_objects_filter)
131+
OPT_PARSE_LIST_OBJECTS_FILTER_INIT((fo), NULL)
117132

118133
/*
119134
* Translates abbreviated numbers in the filter's filter_spec into their

revision.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,9 +2691,9 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
26912691
revs->no_walk = 0;
26922692
} else if (!strcmp(arg, "--single-worktree")) {
26932693
revs->single_worktree = 1;
2694-
} else if (skip_prefix(arg, ("--" CL_ARG__FILTER "="), &arg)) {
2694+
} else if (skip_prefix(arg, ("--filter="), &arg)) {
26952695
parse_list_objects_filter(&revs->filter, arg);
2696-
} else if (!strcmp(arg, ("--no-" CL_ARG__FILTER))) {
2696+
} else if (!strcmp(arg, ("--no-filter"))) {
26972697
list_objects_filter_set_no_filter(&revs->filter);
26982698
} else {
26992699
return 0;

t/t6020-bundle-misc.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ format_and_save_expect () {
122122
sed -e 's/Z$//' >expect
123123
}
124124

125+
HASH_MESSAGE="The bundle uses this hash algorithm: $GIT_DEFAULT_HASH"
126+
125127
# (C) (D, pull/1/head, topic/1)
126128
# o --- o
127129
# / \ (L)
@@ -194,11 +196,12 @@ test_expect_success 'create bundle from special rev: main^!' '
194196
195197
git bundle verify special-rev.bdl |
196198
make_user_friendly_and_stable_output >actual &&
197-
format_and_save_expect <<-\EOF &&
199+
format_and_save_expect <<-EOF &&
198200
The bundle contains this ref:
199201
<COMMIT-P> refs/heads/main
200202
The bundle requires this ref:
201203
<COMMIT-O> Z
204+
$HASH_MESSAGE
202205
EOF
203206
test_cmp expect actual &&
204207
@@ -215,12 +218,13 @@ test_expect_success 'create bundle with --max-count option' '
215218
216219
git bundle verify max-count.bdl |
217220
make_user_friendly_and_stable_output >actual &&
218-
format_and_save_expect <<-\EOF &&
221+
format_and_save_expect <<-EOF &&
219222
The bundle contains these 2 refs:
220223
<COMMIT-P> refs/heads/main
221224
<TAG-1> refs/tags/v1
222225
The bundle requires this ref:
223226
<COMMIT-O> Z
227+
$HASH_MESSAGE
224228
EOF
225229
test_cmp expect actual &&
226230
@@ -240,7 +244,7 @@ test_expect_success 'create bundle with --since option' '
240244
241245
git bundle verify since.bdl |
242246
make_user_friendly_and_stable_output >actual &&
243-
format_and_save_expect <<-\EOF &&
247+
format_and_save_expect <<-EOF &&
244248
The bundle contains these 5 refs:
245249
<COMMIT-P> refs/heads/main
246250
<COMMIT-N> refs/heads/release
@@ -250,6 +254,7 @@ test_expect_success 'create bundle with --since option' '
250254
The bundle requires these 2 refs:
251255
<COMMIT-M> Z
252256
<COMMIT-K> Z
257+
$HASH_MESSAGE
253258
EOF
254259
test_cmp expect actual &&
255260
@@ -267,11 +272,12 @@ test_expect_success 'create bundle 1 - no prerequisites' '
267272
EOF
268273
git bundle create stdin-1.bdl --stdin <input &&
269274
270-
cat >expect <<-\EOF &&
275+
format_and_save_expect <<-EOF &&
271276
The bundle contains these 2 refs:
272277
<COMMIT-D> refs/heads/topic/1
273278
<COMMIT-H> refs/heads/topic/2
274279
The bundle records a complete history.
280+
$HASH_MESSAGE
275281
EOF
276282
277283
# verify bundle, which has no prerequisites
@@ -308,13 +314,14 @@ test_expect_success 'create bundle 2 - has prerequisites' '
308314
--stdin \
309315
release <input &&
310316
311-
format_and_save_expect <<-\EOF &&
317+
format_and_save_expect <<-EOF &&
312318
The bundle contains this ref:
313319
<COMMIT-N> refs/heads/release
314320
The bundle requires these 3 refs:
315321
<COMMIT-D> Z
316322
<COMMIT-E> Z
317323
<COMMIT-G> Z
324+
$HASH_MESSAGE
318325
EOF
319326
320327
git bundle verify 2.bdl |
@@ -367,13 +374,14 @@ test_expect_success 'create bundle 3 - two refs, same object' '
367374
--stdin \
368375
main HEAD <input &&
369376
370-
format_and_save_expect <<-\EOF &&
377+
format_and_save_expect <<-EOF &&
371378
The bundle contains these 2 refs:
372379
<COMMIT-P> refs/heads/main
373380
<COMMIT-P> HEAD
374381
The bundle requires these 2 refs:
375382
<COMMIT-M> Z
376383
<COMMIT-K> Z
384+
$HASH_MESSAGE
377385
EOF
378386
379387
git bundle verify 3.bdl |
@@ -409,12 +417,13 @@ test_expect_success 'create bundle 4 - with tags' '
409417
--stdin \
410418
--all <input &&
411419
412-
cat >expect <<-\EOF &&
420+
cat >expect <<-EOF &&
413421
The bundle contains these 3 refs:
414422
<TAG-1> refs/tags/v1
415423
<TAG-2> refs/tags/v2
416424
<TAG-3> refs/tags/v3
417425
The bundle records a complete history.
426+
$HASH_MESSAGE
418427
EOF
419428
420429
git bundle verify 4.bdl |
@@ -510,8 +519,9 @@ do
510519
<TAG-2> refs/tags/v2
511520
<TAG-3> refs/tags/v3
512521
<COMMIT-P> HEAD
513-
The bundle uses this filter: $filter
514522
The bundle records a complete history.
523+
$HASH_MESSAGE
524+
The bundle uses this filter: $filter
515525
EOF
516526
test_cmp expect actual &&
517527

0 commit comments

Comments
 (0)