summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlga Telezhnaya <olyatelezhnaya@gmail.com>2018-02-12 08:08:54 +0000
committerJunio C Hamano <gitster@pobox.com>2018-02-12 15:03:58 -0800
commit74a6b623adb1b034d48923a62bf84217c8dd5cfb (patch)
tree7534cfea494a564c93b3046f8f39305a032eebd4
parenta0b51ef9fa95cb3ed7f2c894c5b0d685488f267a (diff)
downloadgit-74a6b623adb1b034d48923a62bf84217c8dd5cfb.tar.gz
ref-filter: make valid_atom general again
Stop using valid_cat_file_atom, making the code more general. Further commits will contain some tests, docs and support of new features. 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.c34
1 files changed, 9 insertions, 25 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 6293d8a6ea..92c2e0179e 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -358,8 +358,8 @@ static struct valid_atom {
void (*parser)(const struct ref_format *format, struct used_atom *atom, const char *arg);
} valid_atom[] = {
{ "refname" , FIELD_STR, refname_atom_parser },
- { "objecttype" },
- { "objectsize", FIELD_ULONG },
+ { "objecttype", FIELD_STR, objecttype_atom_parser },
+ { "objectsize", FIELD_ULONG, objectsize_atom_parser },
{ "objectname", FIELD_STR, objectname_atom_parser },
{ "tree" },
{ "parent" },
@@ -396,12 +396,6 @@ static struct valid_atom {
{ "if", FIELD_STR, if_atom_parser },
{ "then" },
{ "else" },
-};
-
-static struct valid_atom valid_cat_file_atom[] = {
- { "objectname" },
- { "objecttype", FIELD_STR, objecttype_atom_parser },
- { "objectsize", FIELD_ULONG, objectsize_atom_parser },
{ "rest" },
{ "deltabase", FIELD_STR, deltabase_atom_parser },
};
@@ -431,7 +425,6 @@ 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;
@@ -461,13 +454,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 < n_atoms; i++) {
+ for (i = 0; i < ARRAY_SIZE(valid_atom); i++) {
int len = strlen(valid_atom[i].name);
if (len == atom_len && !memcmp(valid_atom[i].name, sp, len))
break;
}
- if (n_atoms <= i)
+ if (ARRAY_SIZE(valid_atom) <= i)
die(_("unknown field name: %.*s"), (int)(ep-atom), atom);
/* Add it in, including the deref prefix */
@@ -761,15 +754,9 @@ int verify_ref_format(struct ref_format *format)
return error(_("malformed format string %s"), sp);
/* sp points at "%(" and ep points at the closing ")" */
- if (cat_file_info.is_cat_file)
- at = parse_ref_filter_atom(format, valid_cat_file_atom,
- ARRAY_SIZE(valid_cat_file_atom), sp + 2, ep);
- else {
- at = parse_ref_filter_atom(format, valid_atom,
- ARRAY_SIZE(valid_atom), sp + 2, ep);
- if (skip_prefix(used_atom[at].name, "color:", &color))
- format->need_color_reset_at_eol = !!strcmp(color, "reset");
- }
+ at = parse_ref_filter_atom(format, sp + 2, ep);
+ if (skip_prefix(used_atom[at].name, "color:", &color))
+ format->need_color_reset_at_eol = !!strcmp(color, "reset");
cp = ep + 1;
}
@@ -2232,9 +2219,7 @@ 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, valid_atom,
- ARRAY_SIZE(valid_atom),
- sp + 2, ep),
+ parse_ref_filter_atom(format, sp + 2, ep),
&atomv))
return -1;
atomv->handler(atomv, &state);
@@ -2287,8 +2272,7 @@ 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, valid_atom,
- ARRAY_SIZE(valid_atom), atom, end);
+ return parse_ref_filter_atom(&dummy, atom, end);
}
/* If no sorting option is given, use refname to sort as default */