summaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2021-10-31 13:15:08 -0400
committerJunio C Hamano <gitster@pobox.com>2021-11-01 10:34:32 -0700
commit3c6eb4ec50d9a4a9017fb8c1f220d12dceb206b1 (patch)
tree629b7143891befaa5e4fe4863e2d3f3c2a9ae150 /pretty.c
parent9d530dc0024503ab4218fe6c4395b8a0aa245478 (diff)
downloadgit-3c6eb4ec50d9a4a9017fb8c1f220d12dceb206b1.tar.gz
pretty.c: rework describe options parsing for better extensibility
It contains option arguments only, not options. We would like to add option support here too, but to do that we need to distinguish between different types of options. Lay out the groundwork for distinguishing between bools, strings, etc. and move the central logic (validating values and pushing new arguments to *args) into the successful match, because that will be fairly conditional on what type of argument is being parsed. Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/pretty.c b/pretty.c
index 73b5ead509..6e945fdb18 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1216,28 +1216,39 @@ int format_set_trailers_options(struct process_trailer_options *opts,
static size_t parse_describe_args(const char *start, struct strvec *args)
{
- const char *options[] = { "match", "exclude" };
+ struct {
+ char *name;
+ enum {
+ DESCRIBE_ARG_STRING,
+ } type;
+ } option[] = {
+ { "exclude", DESCRIBE_ARG_STRING },
+ { "match", DESCRIBE_ARG_STRING },
+ };
const char *arg = start;
for (;;) {
- const char *matched = NULL;
+ int found = 0;
const char *argval;
size_t arglen = 0;
int i;
- for (i = 0; i < ARRAY_SIZE(options); i++) {
- if (match_placeholder_arg_value(arg, options[i], &arg,
- &argval, &arglen)) {
- matched = options[i];
+ for (i = 0; !found && i < ARRAY_SIZE(option); i++) {
+ switch (option[i].type) {
+ case DESCRIBE_ARG_STRING:
+ if (match_placeholder_arg_value(arg, option[i].name, &arg,
+ &argval, &arglen)) {
+ if (!arglen)
+ return 0;
+ strvec_pushf(args, "--%s=%.*s", option[i].name, (int)arglen, argval);
+ found = 1;
+ }
break;
}
}
- if (!matched)
+ if (!found)
break;
- if (!arglen)
- return 0;
- strvec_pushf(args, "--%s=%.*s", matched, (int)arglen, argval);
}
return arg - start;
}