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
This commit is contained in:
commit
cb3d2e535a
@ -4149,21 +4149,6 @@ static int option_parse_cruft_expiration(const struct option *opt,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct po_filter_data {
|
|
||||||
unsigned have_revs:1;
|
|
||||||
struct rev_info revs;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct list_objects_filter_options *po_filter_revs_init(void *value)
|
|
||||||
{
|
|
||||||
struct po_filter_data *data = value;
|
|
||||||
|
|
||||||
repo_init_revisions(the_repository, &data->revs, NULL);
|
|
||||||
data->have_revs = 1;
|
|
||||||
|
|
||||||
return &data->revs.filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
int use_internal_rev_list = 0;
|
int use_internal_rev_list = 0;
|
||||||
@ -4174,7 +4159,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
|||||||
int rev_list_index = 0;
|
int rev_list_index = 0;
|
||||||
int stdin_packs = 0;
|
int stdin_packs = 0;
|
||||||
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
|
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
|
||||||
struct po_filter_data pfd = { .have_revs = 0 };
|
struct list_objects_filter_options filter_options =
|
||||||
|
LIST_OBJECTS_FILTER_INIT;
|
||||||
|
|
||||||
struct option pack_objects_options[] = {
|
struct option pack_objects_options[] = {
|
||||||
OPT_SET_INT('q', "quiet", &progress,
|
OPT_SET_INT('q', "quiet", &progress,
|
||||||
@ -4265,7 +4251,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
|||||||
&write_bitmap_index,
|
&write_bitmap_index,
|
||||||
N_("write a bitmap index if possible"),
|
N_("write a bitmap index if possible"),
|
||||||
WRITE_BITMAP_QUIET, PARSE_OPT_HIDDEN),
|
WRITE_BITMAP_QUIET, PARSE_OPT_HIDDEN),
|
||||||
OPT_PARSE_LIST_OBJECTS_FILTER_INIT(&pfd, po_filter_revs_init),
|
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
|
||||||
OPT_CALLBACK_F(0, "missing", NULL, N_("action"),
|
OPT_CALLBACK_F(0, "missing", NULL, N_("action"),
|
||||||
N_("handling for missing objects"), PARSE_OPT_NONEG,
|
N_("handling for missing objects"), PARSE_OPT_NONEG,
|
||||||
option_parse_missing_action),
|
option_parse_missing_action),
|
||||||
@ -4385,7 +4371,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
|||||||
if (!rev_list_all || !rev_list_reflog || !rev_list_index)
|
if (!rev_list_all || !rev_list_reflog || !rev_list_index)
|
||||||
unpack_unreachable_expiration = 0;
|
unpack_unreachable_expiration = 0;
|
||||||
|
|
||||||
if (pfd.have_revs && pfd.revs.filter.choice) {
|
if (filter_options.choice) {
|
||||||
if (!pack_to_stdout)
|
if (!pack_to_stdout)
|
||||||
die(_("cannot use --filter without --stdout"));
|
die(_("cannot use --filter without --stdout"));
|
||||||
if (stdin_packs)
|
if (stdin_packs)
|
||||||
@ -4472,13 +4458,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
|||||||
read_cruft_objects();
|
read_cruft_objects();
|
||||||
} else if (!use_internal_rev_list) {
|
} else if (!use_internal_rev_list) {
|
||||||
read_object_list_from_stdin();
|
read_object_list_from_stdin();
|
||||||
} else if (pfd.have_revs) {
|
|
||||||
get_object_list(&pfd.revs, rp.nr, rp.v);
|
|
||||||
release_revisions(&pfd.revs);
|
|
||||||
} else {
|
} else {
|
||||||
struct rev_info revs;
|
struct rev_info revs;
|
||||||
|
|
||||||
repo_init_revisions(the_repository, &revs, NULL);
|
repo_init_revisions(the_repository, &revs, NULL);
|
||||||
|
list_objects_filter_copy(&revs.filter, &filter_options);
|
||||||
get_object_list(&revs, rp.nr, rp.v);
|
get_object_list(&revs, rp.nr, rp.v);
|
||||||
release_revisions(&revs);
|
release_revisions(&revs);
|
||||||
}
|
}
|
||||||
@ -4513,6 +4497,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
|||||||
reuse_packfile_objects);
|
reuse_packfile_objects);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
list_objects_filter_release(&filter_options);
|
||||||
strvec_clear(&rp);
|
strvec_clear(&rp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -290,10 +290,6 @@ int opt_parse_list_objects_filter(const struct option *opt,
|
|||||||
const char *arg, int unset)
|
const char *arg, int unset)
|
||||||
{
|
{
|
||||||
struct list_objects_filter_options *filter_options = opt->value;
|
struct list_objects_filter_options *filter_options = opt->value;
|
||||||
opt_lof_init init = (opt_lof_init)opt->defval;
|
|
||||||
|
|
||||||
if (init)
|
|
||||||
filter_options = init(opt->value);
|
|
||||||
|
|
||||||
if (unset || !arg)
|
if (unset || !arg)
|
||||||
list_objects_filter_set_no_filter(filter_options);
|
list_objects_filter_set_no_filter(filter_options);
|
||||||
|
@ -111,27 +111,13 @@ void parse_list_objects_filter(
|
|||||||
* The opt->value to opt_parse_list_objects_filter() is either a
|
* The opt->value to opt_parse_list_objects_filter() is either a
|
||||||
* "struct list_objects_filter_option *" when using
|
* "struct list_objects_filter_option *" when using
|
||||||
* OPT_PARSE_LIST_OBJECTS_FILTER().
|
* OPT_PARSE_LIST_OBJECTS_FILTER().
|
||||||
*
|
|
||||||
* Or, if using no "struct option" field is used by the callback,
|
|
||||||
* except the "defval" which is expected to be an "opt_lof_init"
|
|
||||||
* function, which is called with the "opt->value" and must return a
|
|
||||||
* pointer to the ""struct list_objects_filter_option *" to be used.
|
|
||||||
*
|
|
||||||
* The OPT_PARSE_LIST_OBJECTS_FILTER_INIT() can be used e.g. the
|
|
||||||
* "struct list_objects_filter_option" is embedded in a "struct
|
|
||||||
* rev_info", which the "defval" could be tasked with lazily
|
|
||||||
* initializing. See cmd_pack_objects() for an example.
|
|
||||||
*/
|
*/
|
||||||
int opt_parse_list_objects_filter(const struct option *opt,
|
int opt_parse_list_objects_filter(const struct option *opt,
|
||||||
const char *arg, int unset);
|
const char *arg, int unset);
|
||||||
typedef struct list_objects_filter_options *(*opt_lof_init)(void *);
|
|
||||||
#define OPT_PARSE_LIST_OBJECTS_FILTER_INIT(fo, init) \
|
|
||||||
{ OPTION_CALLBACK, 0, "filter", (fo), N_("args"), \
|
|
||||||
N_("object filtering"), 0, opt_parse_list_objects_filter, \
|
|
||||||
(intptr_t)(init) }
|
|
||||||
|
|
||||||
#define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
|
#define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
|
||||||
OPT_PARSE_LIST_OBJECTS_FILTER_INIT((fo), NULL)
|
OPT_CALLBACK(0, "filter", (fo), N_("args"), \
|
||||||
|
N_("object filtering"), opt_parse_list_objects_filter)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Translates abbreviated numbers in the filter's filter_spec into their
|
* Translates abbreviated numbers in the filter's filter_spec into their
|
||||||
|
@ -24,8 +24,9 @@ parse_verify_pack_blob_oid () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_expect_success 'verify blob count in normal packfile' '
|
test_expect_success 'verify blob count in normal packfile' '
|
||||||
git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 |
|
git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
|
||||||
test_parse_ls_files_stage_oids |
|
>ls_files_result &&
|
||||||
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
git -C r1 pack-objects --revs --stdout >all.pack <<-EOF &&
|
git -C r1 pack-objects --revs --stdout >all.pack <<-EOF &&
|
||||||
@ -123,8 +124,8 @@ test_expect_success 'setup r2' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'verify blob count in normal packfile' '
|
test_expect_success 'verify blob count in normal packfile' '
|
||||||
git -C r2 ls-files -s large.1000 large.10000 |
|
git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
|
||||||
test_parse_ls_files_stage_oids |
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
git -C r2 pack-objects --revs --stdout >all.pack <<-EOF &&
|
git -C r2 pack-objects --revs --stdout >all.pack <<-EOF &&
|
||||||
@ -161,8 +162,8 @@ test_expect_success 'verify blob:limit=1000' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'verify blob:limit=1001' '
|
test_expect_success 'verify blob:limit=1001' '
|
||||||
git -C r2 ls-files -s large.1000 |
|
git -C r2 ls-files -s large.1000 >ls_files_result &&
|
||||||
test_parse_ls_files_stage_oids |
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
|
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' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'verify blob:limit=10001' '
|
test_expect_success 'verify blob:limit=10001' '
|
||||||
git -C r2 ls-files -s large.1000 large.10000 |
|
git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
|
||||||
test_parse_ls_files_stage_oids |
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
|
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' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'verify blob:limit=1k' '
|
test_expect_success 'verify blob:limit=1k' '
|
||||||
git -C r2 ls-files -s large.1000 |
|
git -C r2 ls-files -s large.1000 >ls_files_result &&
|
||||||
test_parse_ls_files_stage_oids |
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
|
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' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'verify explicitly specifying oversized blob in input' '
|
test_expect_success 'verify explicitly specifying oversized blob in input' '
|
||||||
git -C r2 ls-files -s large.1000 large.10000 |
|
git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
|
||||||
test_parse_ls_files_stage_oids |
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
echo HEAD >objects &&
|
echo HEAD >objects &&
|
||||||
@ -233,8 +234,8 @@ test_expect_success 'verify explicitly specifying oversized blob in input' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'verify blob:limit=1m' '
|
test_expect_success 'verify blob:limit=1m' '
|
||||||
git -C r2 ls-files -s large.1000 large.10000 |
|
git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
|
||||||
test_parse_ls_files_stage_oids |
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
|
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
|
|||||||
test_cmp expected observed
|
test_cmp expected observed
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'verify small limit and big limit results in small limit' '
|
||||||
|
git -C r2 ls-files -s large.1000 >ls_files_result &&
|
||||||
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
|
sort >expected &&
|
||||||
|
|
||||||
|
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 \
|
||||||
|
--filter=blob:limit=10001 >filter.pack <<-EOF &&
|
||||||
|
HEAD
|
||||||
|
EOF
|
||||||
|
git -C r2 index-pack ../filter.pack &&
|
||||||
|
|
||||||
|
git -C r2 verify-pack -v ../filter.pack >verify_result &&
|
||||||
|
grep blob verify_result |
|
||||||
|
parse_verify_pack_blob_oid |
|
||||||
|
sort >observed &&
|
||||||
|
|
||||||
|
test_cmp expected observed
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'verify big limit and small limit results in small limit' '
|
||||||
|
git -C r2 ls-files -s large.1000 >ls_files_result &&
|
||||||
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
|
sort >expected &&
|
||||||
|
|
||||||
|
git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 \
|
||||||
|
--filter=blob:limit=1001 >filter.pack <<-EOF &&
|
||||||
|
HEAD
|
||||||
|
EOF
|
||||||
|
git -C r2 index-pack ../filter.pack &&
|
||||||
|
|
||||||
|
git -C r2 verify-pack -v ../filter.pack >verify_result &&
|
||||||
|
grep blob verify_result |
|
||||||
|
parse_verify_pack_blob_oid |
|
||||||
|
sort >observed &&
|
||||||
|
|
||||||
|
test_cmp expected observed
|
||||||
|
'
|
||||||
|
|
||||||
# Test sparse:path=<path> filter.
|
# Test sparse:path=<path> filter.
|
||||||
# !!!!
|
# !!!!
|
||||||
# NOTE: sparse:path filter support has been dropped for security reasons,
|
# NOTE: sparse:path filter support has been dropped for security reasons,
|
||||||
@ -289,8 +328,9 @@ test_expect_success 'setup r3' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'verify blob count in normal packfile' '
|
test_expect_success 'verify blob count in normal packfile' '
|
||||||
git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 |
|
git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
|
||||||
test_parse_ls_files_stage_oids |
|
>ls_files_result &&
|
||||||
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
|
git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
|
||||||
@ -341,8 +381,9 @@ test_expect_success 'setup r4' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'verify blob count in normal packfile' '
|
test_expect_success 'verify blob count in normal packfile' '
|
||||||
git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 |
|
git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
|
||||||
test_parse_ls_files_stage_oids |
|
>ls_files_result &&
|
||||||
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
|
git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
|
||||||
@ -359,8 +400,8 @@ test_expect_success 'verify blob count in normal packfile' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'verify sparse:oid=OID' '
|
test_expect_success 'verify sparse:oid=OID' '
|
||||||
git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 |
|
git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
|
||||||
test_parse_ls_files_stage_oids |
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
git -C r4 ls-files -s pattern >staged &&
|
git -C r4 ls-files -s pattern >staged &&
|
||||||
@ -379,8 +420,8 @@ test_expect_success 'verify sparse:oid=OID' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'verify sparse:oid=oid-ish' '
|
test_expect_success 'verify sparse:oid=oid-ish' '
|
||||||
git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 |
|
git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
|
||||||
test_parse_ls_files_stage_oids |
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
git -C r4 pack-objects --revs --stdout --filter=sparse:oid=main:pattern >filter.pack <<-EOF &&
|
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' '
|
|||||||
# This models previously omitted objects that we did not receive.
|
# This models previously omitted objects that we did not receive.
|
||||||
|
|
||||||
test_expect_success 'setup r1 - delete loose blobs' '
|
test_expect_success 'setup r1 - delete loose blobs' '
|
||||||
git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 |
|
git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
|
||||||
test_parse_ls_files_stage_oids |
|
>ls_files_result &&
|
||||||
|
test_parse_ls_files_stage_oids <ls_files_result |
|
||||||
sort >expected &&
|
sort >expected &&
|
||||||
|
|
||||||
for id in `cat expected | sed "s|..|&/|"`
|
for id in `cat expected | sed "s|..|&/|"`
|
||||||
|
Loading…
Reference in New Issue
Block a user