Skip to content

Commit 0caf20f

Browse files
adlternativegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent df6c4f7 commit 0caf20f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

ref-filter.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ static struct used_atom {
146146
enum { O_FULL, O_LENGTH, O_SHORT } option;
147147
unsigned int length;
148148
} oid;
149+
struct {
150+
enum { O_SIZE, O_SIZE_DISK } option;
151+
} objectsize;
149152
struct email_option {
150153
enum { EO_RAW, EO_TRIM, EO_LOCALPART } option;
151154
} email_option;
@@ -269,11 +272,13 @@ static int objectsize_atom_parser(const struct ref_format *format, struct used_a
269272
const char *arg, struct strbuf *err)
270273
{
271274
if (!arg) {
275+
atom->u.objectsize.option = O_SIZE;
272276
if (*atom->name == '*')
273277
oi_deref.info.sizep = &oi_deref.size;
274278
else
275279
oi.info.sizep = &oi.size;
276280
} else if (!strcmp(arg, "disk")) {
281+
atom->u.objectsize.option = O_SIZE_DISK;
277282
if (*atom->name == '*')
278283
oi_deref.info.disk_sizep = &oi_deref.disk_size;
279284
else
@@ -967,12 +972,14 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_
967972
name++;
968973
if (!strcmp(name, "objecttype"))
969974
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+
}
976983
} else if (!strcmp(name, "deltabase"))
977984
v->s = xstrdup(oid_to_hex(&oi->delta_base_oid));
978985
else if (deref)

0 commit comments

Comments
 (0)