Re: [PATCH 03/18] Provide a function to parse fsck message IDs
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 10, 2014, 17:56 UTC
- Message-ID
- <xmqqsignie2k.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <e217caa9c30b72004eca9b15be3aa1c6674dc278.1418055173.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
Show 30 quoted lines
> This function will be used in the next commits to allow the user to
> ask fsck to handle specific problems differently, e.g. demoting certain
> errors to warnings. It has to handle partial strings because we would
> like to be able to parse, say, '--strict=missing-email=warn' command
> lines.
>
> To make the parsing robust, we generate strings from the enum keys, and we
> will match both lower-case, dash-separated values as well as camelCased
> ones (e.g. both "missing-email" and "missingEmail" will match the
> "MISSING_EMAIL" key).
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> fsck.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/fsck.c b/fsck.c
> index 3cea034..05b146c 100644
> --- a/fsck.c
> +++ b/fsck.c
> @@ -63,6 +63,38 @@ enum fsck_msg_id {
> FSCK_MSG_MAX
> };
>
> +#define STR(x) #x
> +#define MSG_ID_STR(x) STR(x),
> +static const char *msg_id_str[FSCK_MSG_MAX + 1] = {
> + FOREACH_MSG_ID(MSG_ID_STR)
> + NULL
> +};I wondered what the ugly macro was in the previous step, but as a way to keep these two lists in sync it makes sense.