Re: [PATCH v3 00/15] ref-filter: use parsing functions
On Fri, Jan 8, 2016 at 12:13 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 20 quoted lines
>
> So it appears to me that match_atom_name() is a misguided helper
> function that you shouldn't have to use too often. If the signature
> of parse() functions is changed to take not just the atom but the
> pointer to its argument (could be NULL, if we are seeing
> "%(contents)", for example) that is already available as "formatp"
> in the function, then contents_atom_parser() could become more like:
>
> contents_atom_parser(struct used_atom *atom, const char *arg)
> {
> if (args)
> atom->u.contents.option = C_BARE;
> else if (!strcmp(arg, "body"))
> atom->u.contents.option = C_BODY;
> ...
> }
>
> and there is no reason for this caller to even look at atom->name or
> worry about that it might have the dereferencing asterisk in front.
>So we something like this for the parsing function:
int parse_ref_filter_atom(const char *atom, const char *ep)
{
const char *sp;
+ char *arg;
int i, at; sp = atom;
@@ -141,6 +143,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
const char *formatp = strchr(sp, ':');
if (!formatp || ep < formatp)
formatp = ep;
+ arg = (char *)formatp;
if (len == formatp - sp && !memcmp(valid_atom[i].name, sp, len))
break;
}
@@ -154,6 +157,13 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
REALLOC_ARRAY(used_atom, used_atom_cnt);
used_atom[at].name = xmemdupz(atom, ep - atom);
used_atom[at].type = valid_atom[i].cmp_type;
+ if (arg != ep)
+ arg = xstrndup(arg + 1, ep - arg - 1);
+ else
+ arg = NULL;
+ if (valid_atom[i].parser)
+ valid_atom[i].parser(&used_atom[at], arg);
+ free(arg);
if (*atom == '*')
need_tagged = 1;
if (!strcmp(used_atom[at].name, "symref"))
--
Regards,
Karthik Nayak