diff options
author | Olga Telezhnaya <olyatelezhnaya@gmail.com> | 2018-02-12 08:08:54 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-02-12 15:03:56 -0800 |
commit | eaf6423e4b375e64172d6ff60138890564ce9f13 (patch) | |
tree | 8d3c0771fb4e142ce811eb0bdd0fa50db745ee94 | |
parent | 1c83c98990356d14ab58bbd432c603e0281f5687 (diff) | |
download | git-eaf6423e4b375e64172d6ff60138890564ce9f13.tar.gz |
ref-filter: make valid_atom as function parameter
Make valid_atom as a function parameter,
there could be another variable further.
Need that for further reusing of formatting logic in cat-file.c.
We do not need to allow users to pass their own valid_atom variable in
global functions like verify_ref_format() because in the end we want to
have same set of valid atoms for all commands. But, as a first step
of migrating, I create further another version of valid_atom
for cat-file.
Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | ref-filter.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/ref-filter.c b/ref-filter.c index ef2d49e5d3..545208bb8f 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -325,7 +325,7 @@ static void head_atom_parser(const struct ref_format *format, struct used_atom * atom->u.head = resolve_refdup("HEAD", RESOLVE_REF_READING, NULL, NULL); } -static struct { +static struct valid_atom { const char *name; cmp_type cmp_type; void (*parser)(const struct ref_format *format, struct used_atom *atom, const char *arg); @@ -396,6 +396,7 @@ struct atom_value { * Used to parse format string and sort specifiers */ static int parse_ref_filter_atom(const struct ref_format *format, + const struct valid_atom *valid_atom, int n_atoms, const char *atom, const char *ep) { const char *sp; @@ -425,13 +426,13 @@ static int parse_ref_filter_atom(const struct ref_format *format, atom_len = (arg ? arg : ep) - sp; /* Is the atom a valid one? */ - for (i = 0; i < ARRAY_SIZE(valid_atom); i++) { + for (i = 0; i < n_atoms; i++) { int len = strlen(valid_atom[i].name); if (len == atom_len && !memcmp(valid_atom[i].name, sp, len)) break; } - if (ARRAY_SIZE(valid_atom) <= i) + if (n_atoms <= i) die(_("unknown field name: %.*s"), (int)(ep-atom), atom); /* Add it in, including the deref prefix */ @@ -708,7 +709,8 @@ int verify_ref_format(struct ref_format *format) if (!ep) return error(_("malformed format string %s"), sp); /* sp points at "%(" and ep points at the closing ")" */ - at = parse_ref_filter_atom(format, sp + 2, ep); + at = parse_ref_filter_atom(format, valid_atom, + ARRAY_SIZE(valid_atom), sp + 2, ep); cp = ep + 1; if (skip_prefix(used_atom[at].name, "color:", &color)) @@ -2146,7 +2148,9 @@ int format_ref_array_item(struct ref_array_item *info, if (cp < sp) append_literal(cp, sp, &state); if (get_ref_atom_value(info, - parse_ref_filter_atom(format, sp + 2, ep), + parse_ref_filter_atom(format, valid_atom, + ARRAY_SIZE(valid_atom), + sp + 2, ep), &atomv)) return -1; atomv->handler(atomv, &state); @@ -2199,7 +2203,8 @@ static int parse_sorting_atom(const char *atom) */ struct ref_format dummy = REF_FORMAT_INIT; const char *end = atom + strlen(atom); - return parse_ref_filter_atom(&dummy, atom, end); + return parse_ref_filter_atom(&dummy, valid_atom, + ARRAY_SIZE(valid_atom), atom, end); } /* If no sorting option is given, use refname to sort as default */ |