Re: [RFC PATCH v2 4/7] parse: create new library for parsing strings and env values
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 10, 2023, 23:43 UTC
- Message-ID
- <xmqqy1iipip4.fsf@gitster.g>
- In-Reply-To
- <kl6ledka8owj.fsf@chooglen-macbookpro.roam.corp.google.com>
Glen Choo <chooglen@google.com> writes:
Show 26 quoted lines
> I think it's reasonable to have the string value parsing logic in
> git-std-lib, e.g. this parsing snippet from diff.c seems like a good
> thing to put into a library that wants to accept user input:
>
> static int parse_color_moved(const char *arg)
> {
> switch (git_parse_maybe_bool(arg)) {
> case 0:
> return COLOR_MOVED_NO;
> case 1:
> return COLOR_MOVED_DEFAULT;
> default:
> break;
> }
>
> if (!strcmp(arg, "no"))
> return COLOR_MOVED_NO;
> else if (!strcmp(arg, "plain"))
> return COLOR_MOVED_PLAIN;
> else if (!strcmp(arg, "blocks"))
> return COLOR_MOVED_BLOCKS;
> /* ... */
> }
>
> But, I don't see a why a non-Git caller would want environment value
> parsing in git-std-lib.It also is debatable why a non-Git caller wants to parse the value to the "--color-moved" option (or a configuration variable) to begin with. Its vocabulary is closely tied to what the diff machinery in Git can do, isn't it?