Merge branch 'ks/ref-filter-sort-numerically'
"git for-each-ref --sort='contents:size'" sorts the refs according to size numerically, giving a ref that points at a blob twelve-byte (12) long before showing a blob hundred-byte (100) long. * ks/ref-filter-sort-numerically: ref-filter: sort numerically when ":size" is usedmaint
commit
6a4e7440fb
21
ref-filter.c
21
ref-filter.c
|
@ -583,9 +583,10 @@ static int contents_atom_parser(struct ref_format *format, struct used_atom *ato
|
||||||
atom->u.contents.option = C_BARE;
|
atom->u.contents.option = C_BARE;
|
||||||
else if (!strcmp(arg, "body"))
|
else if (!strcmp(arg, "body"))
|
||||||
atom->u.contents.option = C_BODY;
|
atom->u.contents.option = C_BODY;
|
||||||
else if (!strcmp(arg, "size"))
|
else if (!strcmp(arg, "size")) {
|
||||||
|
atom->type = FIELD_ULONG;
|
||||||
atom->u.contents.option = C_LENGTH;
|
atom->u.contents.option = C_LENGTH;
|
||||||
else if (!strcmp(arg, "signature"))
|
} else if (!strcmp(arg, "signature"))
|
||||||
atom->u.contents.option = C_SIG;
|
atom->u.contents.option = C_SIG;
|
||||||
else if (!strcmp(arg, "subject"))
|
else if (!strcmp(arg, "subject"))
|
||||||
atom->u.contents.option = C_SUB;
|
atom->u.contents.option = C_SUB;
|
||||||
|
@ -691,9 +692,10 @@ static int raw_atom_parser(struct ref_format *format UNUSED,
|
||||||
{
|
{
|
||||||
if (!arg)
|
if (!arg)
|
||||||
atom->u.raw_data.option = RAW_BARE;
|
atom->u.raw_data.option = RAW_BARE;
|
||||||
else if (!strcmp(arg, "size"))
|
else if (!strcmp(arg, "size")) {
|
||||||
|
atom->type = FIELD_ULONG;
|
||||||
atom->u.raw_data.option = RAW_LENGTH;
|
atom->u.raw_data.option = RAW_LENGTH;
|
||||||
else
|
} else
|
||||||
return err_bad_arg(err, "raw", arg);
|
return err_bad_arg(err, "raw", arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1859,7 +1861,8 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct exp
|
||||||
v->s = xmemdupz(buf, buf_size);
|
v->s = xmemdupz(buf, buf_size);
|
||||||
v->s_size = buf_size;
|
v->s_size = buf_size;
|
||||||
} else if (atom->u.raw_data.option == RAW_LENGTH) {
|
} else if (atom->u.raw_data.option == RAW_LENGTH) {
|
||||||
v->s = xstrfmt("%"PRIuMAX, (uintmax_t)buf_size);
|
v->value = buf_size;
|
||||||
|
v->s = xstrfmt("%"PRIuMAX, v->value);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1885,9 +1888,10 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct exp
|
||||||
v->s = strbuf_detach(&sb, NULL);
|
v->s = strbuf_detach(&sb, NULL);
|
||||||
} else if (atom->u.contents.option == C_BODY_DEP)
|
} else if (atom->u.contents.option == C_BODY_DEP)
|
||||||
v->s = xmemdupz(bodypos, bodylen);
|
v->s = xmemdupz(bodypos, bodylen);
|
||||||
else if (atom->u.contents.option == C_LENGTH)
|
else if (atom->u.contents.option == C_LENGTH) {
|
||||||
v->s = xstrfmt("%"PRIuMAX, (uintmax_t)strlen(subpos));
|
v->value = strlen(subpos);
|
||||||
else if (atom->u.contents.option == C_BODY)
|
v->s = xstrfmt("%"PRIuMAX, v->value);
|
||||||
|
} else if (atom->u.contents.option == C_BODY)
|
||||||
v->s = xmemdupz(bodypos, nonsiglen);
|
v->s = xmemdupz(bodypos, nonsiglen);
|
||||||
else if (atom->u.contents.option == C_SIG)
|
else if (atom->u.contents.option == C_SIG)
|
||||||
v->s = xmemdupz(sigpos, siglen);
|
v->s = xmemdupz(sigpos, siglen);
|
||||||
|
@ -2267,6 +2271,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
|
||||||
|
|
||||||
v->s_size = ATOM_SIZE_UNSPECIFIED;
|
v->s_size = ATOM_SIZE_UNSPECIFIED;
|
||||||
v->handler = append_atom;
|
v->handler = append_atom;
|
||||||
|
v->value = 0;
|
||||||
v->atom = atom;
|
v->atom = atom;
|
||||||
|
|
||||||
if (*name == '*') {
|
if (*name == '*') {
|
||||||
|
|
|
@ -1017,16 +1017,16 @@ test_expect_success 'Verify sorts with raw' '
|
||||||
test_expect_success 'Verify sorts with raw:size' '
|
test_expect_success 'Verify sorts with raw:size' '
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
refs/myblobs/blob8
|
refs/myblobs/blob8
|
||||||
refs/myblobs/first
|
|
||||||
refs/myblobs/blob7
|
refs/myblobs/blob7
|
||||||
refs/heads/main
|
|
||||||
refs/myblobs/blob4
|
refs/myblobs/blob4
|
||||||
refs/myblobs/blob1
|
refs/myblobs/blob1
|
||||||
refs/myblobs/blob2
|
refs/myblobs/blob2
|
||||||
refs/myblobs/blob3
|
refs/myblobs/blob3
|
||||||
refs/myblobs/blob5
|
refs/myblobs/blob5
|
||||||
refs/myblobs/blob6
|
refs/myblobs/blob6
|
||||||
|
refs/myblobs/first
|
||||||
refs/mytrees/first
|
refs/mytrees/first
|
||||||
|
refs/heads/main
|
||||||
EOF
|
EOF
|
||||||
git for-each-ref --format="%(refname)" --sort=raw:size \
|
git for-each-ref --format="%(refname)" --sort=raw:size \
|
||||||
refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
|
refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
|
||||||
|
@ -1138,6 +1138,17 @@ test_expect_success 'for-each-ref --format compare with cat-file --batch' '
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'verify sorts with contents:size' '
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
refs/heads/main
|
||||||
|
refs/heads/newtag
|
||||||
|
refs/heads/ambiguous
|
||||||
|
EOF
|
||||||
|
git for-each-ref --format="%(refname)" \
|
||||||
|
--sort=contents:size refs/heads/ >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'set up multiple-sort tags' '
|
test_expect_success 'set up multiple-sort tags' '
|
||||||
for when in 100000 200000
|
for when in 100000 200000
|
||||||
do
|
do
|
||||||
|
|
Loading…
Reference in New Issue