Remove mark_atom_in_object_info() and create same logic in terms of ref-filter style. Signed-off-by: Olga Telezhnaia <olyatelezhnaya@xxxxxxxxx> Mentored-by: Christian Couder <christian.couder@xxxxxxxxx> Mentored by: Jeff King <peff@xxxxxxxx> --- ref-filter.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 3f92a27d98b6c..34a54db168265 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -255,13 +255,29 @@ static void objectname_atom_parser(const struct ref_format *format, struct used_ static void objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg) { if (!arg) - ; /* default to normal object size */ + cat_file_info->info.sizep = &cat_file_info->size; else if (!strcmp(arg, "disk")) cat_file_info->info.disk_sizep = &cat_file_info->disk_size; else die(_("urecognized %%(objectsize) argument: %s"), arg); } +static void objecttype_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg) +{ + if (!arg) + cat_file_info->info.typep = &cat_file_info->type; + else + die(_("urecognized %%(objecttype) argument: %s"), arg); +} + +static void deltabase_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg) +{ + if (!arg) + cat_file_info->info.delta_base_sha1 = cat_file_info->delta_base_oid.hash; + else + die(_("urecognized %%(deltabase) argument: %s"), arg); +} + static void refname_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg) { refname_atom_parser_internal(&atom->u.refname, arg, atom->name); @@ -384,10 +400,10 @@ static struct valid_atom { static struct valid_atom valid_cat_file_atom[] = { { "objectname" }, - { "objecttype" }, + { "objecttype", FIELD_STR, objecttype_atom_parser }, { "objectsize", FIELD_ULONG, objectsize_atom_parser }, { "rest" }, - { "deltabase" }, + { "deltabase", FIELD_STR, deltabase_atom_parser }, }; #define REF_FORMATTING_STATE_INIT { 0, NULL } @@ -411,25 +427,6 @@ struct atom_value { struct used_atom *atom; }; -static int is_atom(const char *atom, const char *s, int slen) -{ - int alen = strlen(atom); - return alen == slen && !memcmp(atom, s, alen); -} - -static void mark_atom_in_object_info(const char *atom, int len, - struct expand_data *data) -{ - if (is_atom("objecttype", atom, len)) - data->info.typep = &data->type; - else if (is_atom("objectsize", atom, len)) - data->info.sizep = &data->size; - else if (is_atom("rest", atom, len)) - data->split_on_whitespace = 1; - else if (is_atom("deltabase", atom, len)) - data->info.delta_base_sha1 = data->delta_base_oid.hash; -} - /* * Used to parse format string and sort specifiers */ @@ -496,8 +493,8 @@ static int parse_ref_filter_atom(const struct ref_format *format, need_tagged = 1; if (!strcmp(valid_atom[i].name, "symref")) need_symref = 1; - if (cat_file_info) - mark_atom_in_object_info(atom, atom_len, cat_file_info); + if (cat_file_info && !strcmp(valid_atom[i].name, "rest")) + cat_file_info->split_on_whitespace = 1; return at; } -- https://github.com/git/git/pull/452