ref-filter: add objectsize to used_atom
When the support for "objectsize:disk" was bolted onto the existing support for "objectsize", it didn't follow the usual pattern for handling "atomtype:modifier", which reads the <modifier> part just once while parsing the format string, and store the parsed result in the union in the used_atom structure, so that the string form of it does not have to be parsed over and over at runtime (e.g. in grab_common_values()). Add a new member `objectsize` to the union `used_atom.u`, so that we can separate the check of <modifier> from the check of <atomtype>, this will bring scalability to atom `%(objectsize)`. Signed-off-by: ZheNing Hu <adlternative@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
df6c4f722c
commit
0caf20f228
11
ref-filter.c
11
ref-filter.c
@ -146,6 +146,9 @@ static struct used_atom {
|
|||||||
enum { O_FULL, O_LENGTH, O_SHORT } option;
|
enum { O_FULL, O_LENGTH, O_SHORT } option;
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
} oid;
|
} oid;
|
||||||
|
struct {
|
||||||
|
enum { O_SIZE, O_SIZE_DISK } option;
|
||||||
|
} objectsize;
|
||||||
struct email_option {
|
struct email_option {
|
||||||
enum { EO_RAW, EO_TRIM, EO_LOCALPART } option;
|
enum { EO_RAW, EO_TRIM, EO_LOCALPART } option;
|
||||||
} email_option;
|
} email_option;
|
||||||
@ -269,11 +272,13 @@ static int objectsize_atom_parser(const struct ref_format *format, struct used_a
|
|||||||
const char *arg, struct strbuf *err)
|
const char *arg, struct strbuf *err)
|
||||||
{
|
{
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
|
atom->u.objectsize.option = O_SIZE;
|
||||||
if (*atom->name == '*')
|
if (*atom->name == '*')
|
||||||
oi_deref.info.sizep = &oi_deref.size;
|
oi_deref.info.sizep = &oi_deref.size;
|
||||||
else
|
else
|
||||||
oi.info.sizep = &oi.size;
|
oi.info.sizep = &oi.size;
|
||||||
} else if (!strcmp(arg, "disk")) {
|
} else if (!strcmp(arg, "disk")) {
|
||||||
|
atom->u.objectsize.option = O_SIZE_DISK;
|
||||||
if (*atom->name == '*')
|
if (*atom->name == '*')
|
||||||
oi_deref.info.disk_sizep = &oi_deref.disk_size;
|
oi_deref.info.disk_sizep = &oi_deref.disk_size;
|
||||||
else
|
else
|
||||||
@ -967,12 +972,14 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_
|
|||||||
name++;
|
name++;
|
||||||
if (!strcmp(name, "objecttype"))
|
if (!strcmp(name, "objecttype"))
|
||||||
v->s = xstrdup(type_name(oi->type));
|
v->s = xstrdup(type_name(oi->type));
|
||||||
else if (!strcmp(name, "objectsize:disk")) {
|
else if (starts_with(name, "objectsize")) {
|
||||||
|
if (used_atom[i].u.objectsize.option == O_SIZE_DISK) {
|
||||||
v->value = oi->disk_size;
|
v->value = oi->disk_size;
|
||||||
v->s = xstrfmt("%"PRIuMAX, (uintmax_t)oi->disk_size);
|
v->s = xstrfmt("%"PRIuMAX, (uintmax_t)oi->disk_size);
|
||||||
} else if (!strcmp(name, "objectsize")) {
|
} else if (used_atom[i].u.objectsize.option == O_SIZE) {
|
||||||
v->value = oi->size;
|
v->value = oi->size;
|
||||||
v->s = xstrfmt("%"PRIuMAX , (uintmax_t)oi->size);
|
v->s = xstrfmt("%"PRIuMAX , (uintmax_t)oi->size);
|
||||||
|
}
|
||||||
} else if (!strcmp(name, "deltabase"))
|
} else if (!strcmp(name, "deltabase"))
|
||||||
v->s = xstrdup(oid_to_hex(&oi->delta_base_oid));
|
v->s = xstrdup(oid_to_hex(&oi->delta_base_oid));
|
||||||
else if (deref)
|
else if (deref)
|
||||||
|
Loading…
Reference in New Issue
Block a user