parse-options: Don't call parse_options_check() so much
parse_options_check() is being called for each invocation of parse_options_step which can be quite a bit for some commands. The commit introducing this function cb9d398 (parse-options: add parse_options_check to validate option specs., 2009-06-09) had the correct motivation and explicitly states that parse_options_check() should be called from parse_options_start(). However, the implementation differs from the motivation. Fix it. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stephen Boyd committed
Dec 5, 2010 at 23:57 UTC
9ca1169fd92c71ebbef92ff18aa5d91a2157d1bd
4 files changed
+8
-9
builtin/blame.c
+2
-2
@@ -2298,8 +2298,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2298
save_commit_buffer = 0;
2299
dashdash_pos = 0;
2300
2301
- parse_options_start(&ctx, argc, argv, prefix, PARSE_OPT_KEEP_DASHDASH |
2302
- PARSE_OPT_KEEP_ARGV0);
2301
+ parse_options_start(&ctx, argc, argv, prefix, options,
2302
+ PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
2303
for (;;) {
2304
switch (parse_options_step(&ctx, options, blame_opt_usage)) {
2305
case PARSE_OPT_HELP:
builtin/shortlog.c
+2
-2
@@ -268,8 +268,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
268
git_config(git_default_config, NULL);
269
shortlog_init(&log);
270
init_revisions(&rev, prefix);
271
- parse_options_start(&ctx, argc, argv, prefix, PARSE_OPT_KEEP_DASHDASH |
272
- PARSE_OPT_KEEP_ARGV0);
271
+ parse_options_start(&ctx, argc, argv, prefix, options,
272
+ PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
273
274
for (;;) {
275
switch (parse_options_step(&ctx, options, shortlog_usage)) {
parse-options.c
+3
-4
@@ -338,7 +338,7 @@ static void parse_options_check(const struct option *opts)
338
339
void parse_options_start(struct parse_opt_ctx_t *ctx,
340
int argc, const char **argv, const char *prefix,
341
- int flags)
341
+ const struct option *options, int flags)
342
{
343
memset(ctx, 0, sizeof(*ctx));
344
ctx->argc = argc - 1;
@@ -350,6 +350,7 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
350
if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&
351
(flags & PARSE_OPT_STOP_AT_NON_OPTION))
352
die("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
353
+ parse_options_check(options);
354
}
355
356
static int usage_with_options_internal(struct parse_opt_ctx_t *,
@@ -362,8 +363,6 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
363
{
364
int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP);
365
365
- parse_options_check(options);
366
-
366
/* we must reset ->opt, unknown short option leave it dangling */
367
ctx->opt = NULL;
368
@@ -452,7 +451,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
451
{
452
struct parse_opt_ctx_t ctx;
453
455
- parse_options_start(&ctx, argc, argv, prefix, flags);
454
+ parse_options_start(&ctx, argc, argv, prefix, options, flags);
455
switch (parse_options_step(&ctx, options, usagestr)) {
456
case PARSE_OPT_HELP:
457
exit(129);
parse-options.h
+1
-1
@@ -180,7 +180,7 @@ struct parse_opt_ctx_t {
180
181
extern void parse_options_start(struct parse_opt_ctx_t *ctx,
182
int argc, const char **argv, const char *prefix,
183
- int flags);
183
+ const struct option *options, int flags);
184
185
extern int parse_options_step(struct parse_opt_ctx_t *ctx,
186
const struct option *options,