From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-2.7 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 914FB1FADF for ; Wed, 10 Jan 2018 09:38:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964947AbeAJJin (ORCPT ); Wed, 10 Jan 2018 04:38:43 -0500 Received: from a7-11.smtp-out.eu-west-1.amazonses.com ([54.240.7.11]:48796 "EHLO a7-11.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755656AbeAJJgm (ORCPT ); Wed, 10 Jan 2018 04:36:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=shh3fegwg5fppqsuzphvschd53n6ihuv; d=amazonses.com; t=1515577001; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=e26EezBeQGBuptJJ1CK3mWMx4qJfS5wQojnXKjbffOc=; b=LKUSELq9C8gCDHtVY7s2ctjrjjzPBkGG19uP1kRD+0yhQebRjHrPYkxKb683BTF9 m2R+UJfEcg+VCtQlkjZfApnanxwwh5QZ6lZoBbihjgMVdCCzKcnJmfIlui/y453mZNR y38Pj3MkfKwzbYrgBf6rCjqnvDw51dGWAJSZxLi8= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <01020160df6dc529-fae54bd6-e595-44fa-9f9a-c44cb3a5a1a8-000000@eu-west-1.amazonses.com> In-Reply-To: <01020160df6dc499-0e6d11ec-1dcd-4a71-997b-ea231f33fae4-000000@eu-west-1.amazonses.com> References: <01020160df6dc499-0e6d11ec-1dcd-4a71-997b-ea231f33fae4-000000@eu-west-1.amazonses.com> Subject: [PATCH v2 03/18] ref-filter: make valid_atom as function parameter MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 10 Jan 2018 09:36:41 +0000 X-SES-Outgoing: 2018.01.10-54.240.7.11 Feedback-ID: 1.eu-west-1.YYPRFFOog89kHDDPKvTu4MK67j4wW0z7cAgZtFqQH58=:AmazonSES Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 Mentored-by: Christian Couder Mentored by: Jeff King --- ref-filter.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 3f9161707e66b..32b7e918bca75 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)) @@ -2139,7 +2141,9 @@ void format_ref_array_item(struct ref_array_item *info, if (cp < sp) append_literal(cp, sp, &state); 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); atomv->handler(atomv, &state); } @@ -2187,7 +2191,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 */ -- https://github.com/git/git/pull/450