Skip to content

Commit cb3d2e5

Browse files
committed
Merge branch 'rs/multi-filter-args'
Fix a bug where `pack-objects` would not respect multiple `--filter` arguments when invoked directly. * rs/multi-filter-args: list-objects-filter: remove OPT_PARSE_LIST_OBJECTS_FILTER_INIT() pack-objects: simplify --filter handling pack-objects: fix handling of multiple --filter options t5317: demonstrate failure to handle multiple --filter options t5317: stop losing return codes of git ls-files
2 parents a1b8e5e + d4f7036 commit cb3d2e5

File tree

4 files changed

+74
-65
lines changed

4 files changed

+74
-65
lines changed

builtin/pack-objects.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4149,21 +4149,6 @@ static int option_parse_cruft_expiration(const struct option *opt,
41494149
return 0;
41504150
}
41514151

4152-
struct po_filter_data {
4153-
unsigned have_revs:1;
4154-
struct rev_info revs;
4155-
};
4156-
4157-
static struct list_objects_filter_options *po_filter_revs_init(void *value)
4158-
{
4159-
struct po_filter_data *data = value;
4160-
4161-
repo_init_revisions(the_repository, &data->revs, NULL);
4162-
data->have_revs = 1;
4163-
4164-
return &data->revs.filter;
4165-
}
4166-
41674152
int cmd_pack_objects(int argc, const char **argv, const char *prefix)
41684153
{
41694154
int use_internal_rev_list = 0;
@@ -4174,7 +4159,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
41744159
int rev_list_index = 0;
41754160
int stdin_packs = 0;
41764161
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
4177-
struct po_filter_data pfd = { .have_revs = 0 };
4162+
struct list_objects_filter_options filter_options =
4163+
LIST_OBJECTS_FILTER_INIT;
41784164

41794165
struct option pack_objects_options[] = {
41804166
OPT_SET_INT('q', "quiet", &progress,
@@ -4265,7 +4251,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
42654251
&write_bitmap_index,
42664252
N_("write a bitmap index if possible"),
42674253
WRITE_BITMAP_QUIET, PARSE_OPT_HIDDEN),
4268-
OPT_PARSE_LIST_OBJECTS_FILTER_INIT(&pfd, po_filter_revs_init),
4254+
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
42694255
OPT_CALLBACK_F(0, "missing", NULL, N_("action"),
42704256
N_("handling for missing objects"), PARSE_OPT_NONEG,
42714257
option_parse_missing_action),
@@ -4385,7 +4371,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
43854371
if (!rev_list_all || !rev_list_reflog || !rev_list_index)
43864372
unpack_unreachable_expiration = 0;
43874373

4388-
if (pfd.have_revs && pfd.revs.filter.choice) {
4374+
if (filter_options.choice) {
43894375
if (!pack_to_stdout)
43904376
die(_("cannot use --filter without --stdout"));
43914377
if (stdin_packs)
@@ -4472,13 +4458,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
44724458
read_cruft_objects();
44734459
} else if (!use_internal_rev_list) {
44744460
read_object_list_from_stdin();
4475-
} else if (pfd.have_revs) {
4476-
get_object_list(&pfd.revs, rp.nr, rp.v);
4477-
release_revisions(&pfd.revs);
44784461
} else {
44794462
struct rev_info revs;
44804463

44814464
repo_init_revisions(the_repository, &revs, NULL);
4465+
list_objects_filter_copy(&revs.filter, &filter_options);
44824466
get_object_list(&revs, rp.nr, rp.v);
44834467
release_revisions(&revs);
44844468
}
@@ -4513,6 +4497,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
45134497
reuse_packfile_objects);
45144498

45154499
cleanup:
4500+
list_objects_filter_release(&filter_options);
45164501
strvec_clear(&rp);
45174502

45184503
return 0;

list-objects-filter-options.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,6 @@ int opt_parse_list_objects_filter(const struct option *opt,
290290
const char *arg, int unset)
291291
{
292292
struct list_objects_filter_options *filter_options = opt->value;
293-
opt_lof_init init = (opt_lof_init)opt->defval;
294-
295-
if (init)
296-
filter_options = init(opt->value);
297293

298294
if (unset || !arg)
299295
list_objects_filter_set_no_filter(filter_options);

list-objects-filter-options.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,13 @@ void parse_list_objects_filter(
111111
* The opt->value to opt_parse_list_objects_filter() is either a
112112
* "struct list_objects_filter_option *" when using
113113
* OPT_PARSE_LIST_OBJECTS_FILTER().
114-
*
115-
* Or, if using no "struct option" field is used by the callback,
116-
* except the "defval" which is expected to be an "opt_lof_init"
117-
* function, which is called with the "opt->value" and must return a
118-
* pointer to the ""struct list_objects_filter_option *" to be used.
119-
*
120-
* The OPT_PARSE_LIST_OBJECTS_FILTER_INIT() can be used e.g. the
121-
* "struct list_objects_filter_option" is embedded in a "struct
122-
* rev_info", which the "defval" could be tasked with lazily
123-
* initializing. See cmd_pack_objects() for an example.
124114
*/
125115
int opt_parse_list_objects_filter(const struct option *opt,
126116
const char *arg, int unset);
127-
typedef struct list_objects_filter_options *(*opt_lof_init)(void *);
128-
#define OPT_PARSE_LIST_OBJECTS_FILTER_INIT(fo, init) \
129-
{ OPTION_CALLBACK, 0, "filter", (fo), N_("args"), \
130-
N_("object filtering"), 0, opt_parse_list_objects_filter, \
131-
(intptr_t)(init) }
132117

133118
#define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
134-
OPT_PARSE_LIST_OBJECTS_FILTER_INIT((fo), NULL)
119+
OPT_CALLBACK(0, "filter", (fo), N_("args"), \
120+
N_("object filtering"), opt_parse_list_objects_filter)
135121

136122
/*
137123
* Translates abbreviated numbers in the filter's filter_spec into their

t/t5317-pack-objects-filter-objects.sh

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ parse_verify_pack_blob_oid () {
2424
}
2525

2626
test_expect_success 'verify blob count in normal packfile' '
27-
git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 |
28-
test_parse_ls_files_stage_oids |
27+
git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
28+
>ls_files_result &&
29+
test_parse_ls_files_stage_oids <ls_files_result |
2930
sort >expected &&
3031
3132
git -C r1 pack-objects --revs --stdout >all.pack <<-EOF &&
@@ -123,8 +124,8 @@ test_expect_success 'setup r2' '
123124
'
124125

125126
test_expect_success 'verify blob count in normal packfile' '
126-
git -C r2 ls-files -s large.1000 large.10000 |
127-
test_parse_ls_files_stage_oids |
127+
git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
128+
test_parse_ls_files_stage_oids <ls_files_result |
128129
sort >expected &&
129130
130131
git -C r2 pack-objects --revs --stdout >all.pack <<-EOF &&
@@ -161,8 +162,8 @@ test_expect_success 'verify blob:limit=1000' '
161162
'
162163

163164
test_expect_success 'verify blob:limit=1001' '
164-
git -C r2 ls-files -s large.1000 |
165-
test_parse_ls_files_stage_oids |
165+
git -C r2 ls-files -s large.1000 >ls_files_result &&
166+
test_parse_ls_files_stage_oids <ls_files_result |
166167
sort >expected &&
167168
168169
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
@@ -179,8 +180,8 @@ test_expect_success 'verify blob:limit=1001' '
179180
'
180181

181182
test_expect_success 'verify blob:limit=10001' '
182-
git -C r2 ls-files -s large.1000 large.10000 |
183-
test_parse_ls_files_stage_oids |
183+
git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
184+
test_parse_ls_files_stage_oids <ls_files_result |
184185
sort >expected &&
185186
186187
git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
@@ -197,8 +198,8 @@ test_expect_success 'verify blob:limit=10001' '
197198
'
198199

199200
test_expect_success 'verify blob:limit=1k' '
200-
git -C r2 ls-files -s large.1000 |
201-
test_parse_ls_files_stage_oids |
201+
git -C r2 ls-files -s large.1000 >ls_files_result &&
202+
test_parse_ls_files_stage_oids <ls_files_result |
202203
sort >expected &&
203204
204205
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
@@ -215,8 +216,8 @@ test_expect_success 'verify blob:limit=1k' '
215216
'
216217

217218
test_expect_success 'verify explicitly specifying oversized blob in input' '
218-
git -C r2 ls-files -s large.1000 large.10000 |
219-
test_parse_ls_files_stage_oids |
219+
git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
220+
test_parse_ls_files_stage_oids <ls_files_result |
220221
sort >expected &&
221222
222223
echo HEAD >objects &&
@@ -233,8 +234,8 @@ test_expect_success 'verify explicitly specifying oversized blob in input' '
233234
'
234235

235236
test_expect_success 'verify blob:limit=1m' '
236-
git -C r2 ls-files -s large.1000 large.10000 |
237-
test_parse_ls_files_stage_oids |
237+
git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
238+
test_parse_ls_files_stage_oids <ls_files_result |
238239
sort >expected &&
239240
240241
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
@@ -264,6 +265,44 @@ test_expect_success 'verify normal and blob:limit packfiles have same commits/tr
264265
test_cmp expected observed
265266
'
266267

268+
test_expect_success 'verify small limit and big limit results in small limit' '
269+
git -C r2 ls-files -s large.1000 >ls_files_result &&
270+
test_parse_ls_files_stage_oids <ls_files_result |
271+
sort >expected &&
272+
273+
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 \
274+
--filter=blob:limit=10001 >filter.pack <<-EOF &&
275+
HEAD
276+
EOF
277+
git -C r2 index-pack ../filter.pack &&
278+
279+
git -C r2 verify-pack -v ../filter.pack >verify_result &&
280+
grep blob verify_result |
281+
parse_verify_pack_blob_oid |
282+
sort >observed &&
283+
284+
test_cmp expected observed
285+
'
286+
287+
test_expect_success 'verify big limit and small limit results in small limit' '
288+
git -C r2 ls-files -s large.1000 >ls_files_result &&
289+
test_parse_ls_files_stage_oids <ls_files_result |
290+
sort >expected &&
291+
292+
git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 \
293+
--filter=blob:limit=1001 >filter.pack <<-EOF &&
294+
HEAD
295+
EOF
296+
git -C r2 index-pack ../filter.pack &&
297+
298+
git -C r2 verify-pack -v ../filter.pack >verify_result &&
299+
grep blob verify_result |
300+
parse_verify_pack_blob_oid |
301+
sort >observed &&
302+
303+
test_cmp expected observed
304+
'
305+
267306
# Test sparse:path=<path> filter.
268307
# !!!!
269308
# NOTE: sparse:path filter support has been dropped for security reasons,
@@ -289,8 +328,9 @@ test_expect_success 'setup r3' '
289328
'
290329

291330
test_expect_success 'verify blob count in normal packfile' '
292-
git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 |
293-
test_parse_ls_files_stage_oids |
331+
git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
332+
>ls_files_result &&
333+
test_parse_ls_files_stage_oids <ls_files_result |
294334
sort >expected &&
295335
296336
git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
@@ -341,8 +381,9 @@ test_expect_success 'setup r4' '
341381
'
342382

343383
test_expect_success 'verify blob count in normal packfile' '
344-
git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 |
345-
test_parse_ls_files_stage_oids |
384+
git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
385+
>ls_files_result &&
386+
test_parse_ls_files_stage_oids <ls_files_result |
346387
sort >expected &&
347388
348389
git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
@@ -359,8 +400,8 @@ test_expect_success 'verify blob count in normal packfile' '
359400
'
360401

361402
test_expect_success 'verify sparse:oid=OID' '
362-
git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 |
363-
test_parse_ls_files_stage_oids |
403+
git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
404+
test_parse_ls_files_stage_oids <ls_files_result |
364405
sort >expected &&
365406
366407
git -C r4 ls-files -s pattern >staged &&
@@ -379,8 +420,8 @@ test_expect_success 'verify sparse:oid=OID' '
379420
'
380421

381422
test_expect_success 'verify sparse:oid=oid-ish' '
382-
git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 |
383-
test_parse_ls_files_stage_oids |
423+
git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
424+
test_parse_ls_files_stage_oids <ls_files_result |
384425
sort >expected &&
385426
386427
git -C r4 pack-objects --revs --stdout --filter=sparse:oid=main:pattern >filter.pack <<-EOF &&
@@ -400,8 +441,9 @@ test_expect_success 'verify sparse:oid=oid-ish' '
400441
# This models previously omitted objects that we did not receive.
401442

402443
test_expect_success 'setup r1 - delete loose blobs' '
403-
git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 |
404-
test_parse_ls_files_stage_oids |
444+
git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
445+
>ls_files_result &&
446+
test_parse_ls_files_stage_oids <ls_files_result |
405447
sort >expected &&
406448
407449
for id in `cat expected | sed "s|..|&/|"`

0 commit comments

Comments
 (0)