/** Parse the command-line options taken from git */ static void parse_opts(struct opts *o, int argc, char *argv[]) { struct args_info args = ARGS_INFO_INIT; for (args.pos = 1; args.pos < argc; ++args.pos) { char *a = argv[args.pos]; if (a[0] != '-') { if (o->rev != NULL) usage("Only one rev should be provided", NULL); else o->rev = a; } else if (!strcmp(a, "-t")) o->action = SHOW_TYPE; else if (!strcmp(a, "-s")) o->action = SHOW_SIZE; else if (!strcmp(a, "-e")) o->action = SHOW_NONE; else if (!strcmp(a, "-p")) o->action = SHOW_PRETTY; else if (!strcmp(a, "-q")) o->verbose = 0; else if (!strcmp(a, "-v")) o->verbose = 1; else if (!strcmp(a, "--help") || !strcmp(a, "-h")) usage(NULL, NULL); else if (!match_str_arg(&o->dir, &args, "--git-dir")) usage("Unknown option", a); } if (!o->action || !o->rev) usage(NULL, NULL); }
/** Parse command line arguments and choose action to run when done */ static void parse_options(tag_action *action, tag_options *opts, int argc, char **argv) { args_info args = ARGS_INFO_INIT; *action = &action_list_tags; for (args.pos = 1; args.pos < argc; ++args.pos) { const char *curr = argv[args.pos]; if (curr[0] != '-') { if (!opts->tag_name) opts->tag_name = curr; else if (!opts->target) opts->target = curr; else print_usage(); if (*action != &action_create_tag) *action = &action_create_lighweight_tag; } else if (!strcmp(curr, "-n")) { opts->num_lines = 1; *action = &action_list_tags; } else if (!strcmp(curr, "-a")) { *action = &action_create_tag; } else if (!strcmp(curr, "-f")) { opts->force = 1; } else if (match_int_arg(&opts->num_lines, &args, "-n", 0)) { *action = &action_list_tags; } else if (match_str_arg(&opts->pattern, &args, "-l")) { *action = &action_list_tags; } else if (match_str_arg(&opts->tag_name, &args, "-d")) { *action = &action_delete_tag; } else if (match_str_arg(&opts->message, &args, "-m")) { *action = &action_create_tag; } } }
/** Parse command line arguments */ static void parse_options(describe_options *opts, int argc, char **argv) { args_info args = ARGS_INFO_INIT; for (args.pos = 1; args.pos < argc; ++args.pos) { const char *curr = argv[args.pos]; if (curr[0] != '-') { opts->commits = (const char **)realloc((void *)opts->commits, ++opts->commit_count); opts->commits[opts->commit_count - 1] = curr; } else if (!strcmp(curr, "--all")) { opts->describe_options.describe_strategy = GIT_DESCRIBE_ALL; } else if (!strcmp(curr, "--tags")) { opts->describe_options.describe_strategy = GIT_DESCRIBE_TAGS; } else if (!strcmp(curr, "--exact-match")) { opts->describe_options.max_candidates_tags = 0; } else if (!strcmp(curr, "--long")) { opts->format_options.always_use_long_format = 1; } else if (!strcmp(curr, "--always")) { opts->describe_options.show_commit_oid_as_fallback = 1; } else if (!strcmp(curr, "--first-parent")) { opts->describe_options.only_follow_first_parent = 1; } else if (optional_str_arg(&opts->format_options.dirty_suffix, &args, "--dirty", "-dirty")) { } else if (match_int_arg((int *)&opts->format_options.abbreviated_size, &args, "--abbrev", 0)) { } else if (match_int_arg((int *)&opts->describe_options.max_candidates_tags, &args, "--candidates", 0)) { } else if (match_str_arg(&opts->describe_options.pattern, &args, "--match")) { } } if (opts->commit_count > 0) { if (opts->format_options.dirty_suffix) fatal("--dirty is incompatible with commit-ishes", NULL); } else { if (!opts->format_options.dirty_suffix || !opts->format_options.dirty_suffix[0]) { opts->commits = (const char **)malloc(++opts->commit_count); opts->commits[0] = "HEAD"; } } }
/** Parse arguments as copied from git-diff. */ static void parse_opts(struct opts *o, int argc, char *argv[]) { struct args_info args = ARGS_INFO_INIT; for (args.pos = 1; args.pos < argc; ++args.pos) { const char *a = argv[args.pos]; if (a[0] != '-') { if (o->treeish1 == NULL) o->treeish1 = a; else if (o->treeish2 == NULL) o->treeish2 = a; else usage("Only one or two tree identifiers can be provided", NULL); } else if (!strcmp(a, "-p") || !strcmp(a, "-u") || !strcmp(a, "--patch")) { o->output |= OUTPUT_DIFF; o->format = GIT_DIFF_FORMAT_PATCH; } else if (!strcmp(a, "--cached")) o->cache = CACHE_ONLY; else if (!strcmp(a, "--nocache")) o->cache = CACHE_NONE; else if (!strcmp(a, "--name-only") || !strcmp(a, "--format=name")) o->format = GIT_DIFF_FORMAT_NAME_ONLY; else if (!strcmp(a, "--name-status") || !strcmp(a, "--format=name-status")) o->format = GIT_DIFF_FORMAT_NAME_STATUS; else if (!strcmp(a, "--raw") || !strcmp(a, "--format=raw")) o->format = GIT_DIFF_FORMAT_RAW; else if (!strcmp(a, "--format=diff-index")) { o->format = GIT_DIFF_FORMAT_RAW; o->diffopts.id_abbrev = 40; } else if (!strcmp(a, "--color")) o->color = 0; else if (!strcmp(a, "--no-color")) o->color = -1; else if (!strcmp(a, "-R")) o->diffopts.flags |= GIT_DIFF_REVERSE; else if (!strcmp(a, "-a") || !strcmp(a, "--text")) o->diffopts.flags |= GIT_DIFF_FORCE_TEXT; else if (!strcmp(a, "--ignore-space-at-eol")) o->diffopts.flags |= GIT_DIFF_IGNORE_WHITESPACE_EOL; else if (!strcmp(a, "-b") || !strcmp(a, "--ignore-space-change")) o->diffopts.flags |= GIT_DIFF_IGNORE_WHITESPACE_CHANGE; else if (!strcmp(a, "-w") || !strcmp(a, "--ignore-all-space")) o->diffopts.flags |= GIT_DIFF_IGNORE_WHITESPACE; else if (!strcmp(a, "--ignored")) o->diffopts.flags |= GIT_DIFF_INCLUDE_IGNORED; else if (!strcmp(a, "--untracked")) o->diffopts.flags |= GIT_DIFF_INCLUDE_UNTRACKED; else if (!strcmp(a, "--patience")) o->diffopts.flags |= GIT_DIFF_PATIENCE; else if (!strcmp(a, "--minimal")) o->diffopts.flags |= GIT_DIFF_MINIMAL; else if (!strcmp(a, "--stat")) o->output |= OUTPUT_STAT; else if (!strcmp(a, "--numstat")) o->output |= OUTPUT_NUMSTAT; else if (!strcmp(a, "--shortstat")) o->output |= OUTPUT_SHORTSTAT; else if (!strcmp(a, "--summary")) o->output |= OUTPUT_SUMMARY; else if (match_uint16_arg( &o->findopts.rename_threshold, &args, "-M") || match_uint16_arg( &o->findopts.rename_threshold, &args, "--find-renames")) o->findopts.flags |= GIT_DIFF_FIND_RENAMES; else if (match_uint16_arg( &o->findopts.copy_threshold, &args, "-C") || match_uint16_arg( &o->findopts.copy_threshold, &args, "--find-copies")) o->findopts.flags |= GIT_DIFF_FIND_COPIES; else if (!strcmp(a, "--find-copies-harder")) o->findopts.flags |= GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED; else if (is_prefixed(a, "-B") || is_prefixed(a, "--break-rewrites")) /* TODO: parse thresholds */ o->findopts.flags |= GIT_DIFF_FIND_REWRITES; else if (!match_uint32_arg( &o->diffopts.context_lines, &args, "-U") && !match_uint32_arg( &o->diffopts.context_lines, &args, "--unified") && !match_uint32_arg( &o->diffopts.interhunk_lines, &args, "--inter-hunk-context") && !match_uint16_arg( &o->diffopts.id_abbrev, &args, "--abbrev") && !match_str_arg(&o->diffopts.old_prefix, &args, "--src-prefix") && !match_str_arg(&o->diffopts.new_prefix, &args, "--dst-prefix") && !match_str_arg(&o->dir, &args, "--git-dir")) usage("Unknown command line argument", a); } }