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>
ZheNing Hu committed
May 13, 2021 at 15:15 UTC
0caf20f22806dfd478ab3ac26b5f3682f383d3b4
1 file changed
+13
-6
ref-filter.c
+13
-6
@@ -146,6 +146,9 @@ static struct used_atom {
146
enum { O_FULL, O_LENGTH, O_SHORT } option;
147
unsigned int length;
148
} oid;
149
+ struct {
150
+ enum { O_SIZE, O_SIZE_DISK } option;
151
+ } objectsize;
152
struct email_option {
153
enum { EO_RAW, EO_TRIM, EO_LOCALPART } option;
154
} email_option;
@@ -269,11 +272,13 @@ static int objectsize_atom_parser(const struct ref_format *format, struct used_a
272
const char *arg, struct strbuf *err)
273
{
274
if (!arg) {
275
+ atom->u.objectsize.option = O_SIZE;
276
if (*atom->name == '*')
277
oi_deref.info.sizep = &oi_deref.size;
278
else
279
oi.info.sizep = &oi.size;
280
} else if (!strcmp(arg, "disk")) {
281
+ atom->u.objectsize.option = O_SIZE_DISK;
282
if (*atom->name == '*')
283
oi_deref.info.disk_sizep = &oi_deref.disk_size;
284
else
@@ -967,12 +972,14 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_
972
name++;
973
if (!strcmp(name, "objecttype"))
974
v->s = xstrdup(type_name(oi->type));
970
- else if (!strcmp(name, "objectsize:disk")) {
971
- v->value = oi->disk_size;
972
- v->s = xstrfmt("%"PRIuMAX, (uintmax_t)oi->disk_size);
973
- } else if (!strcmp(name, "objectsize")) {
974
- v->value = oi->size;
975
- v->s = xstrfmt("%"PRIuMAX , (uintmax_t)oi->size);
975
+ else if (starts_with(name, "objectsize")) {
976
+ if (used_atom[i].u.objectsize.option == O_SIZE_DISK) {
977
+ v->value = oi->disk_size;
978
+ v->s = xstrfmt("%"PRIuMAX, (uintmax_t)oi->disk_size);
979
+ } else if (used_atom[i].u.objectsize.option == O_SIZE) {
980
+ v->value = oi->size;
981
+ v->s = xstrfmt("%"PRIuMAX , (uintmax_t)oi->size);
982
+ }
983
} else if (!strcmp(name, "deltabase"))
984
v->s = xstrdup(oid_to_hex(&oi->delta_base_oid));
985
else if (deref)