From: Junio C Hamano Date: Fri, 13 May 2011 17:59:57 +0000 (-0700) Subject: Merge branch 'cn/log-parse-opt' X-Git-Tag: v1.7.6-rc0~80 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2f3e3f573d635c26ce26ff61f8f6c97ce88da79c;p=git.git Merge branch 'cn/log-parse-opt' * cn/log-parse-opt: log: convert to parse-options --- 2f3e3f573d635c26ce26ff61f8f6c97ce88da79c diff --cc builtin/log.c index d43ad3a61,ca353402a..f6219909a --- a/builtin/log.c +++ b/builtin/log.c @@@ -49,36 -52,61 +52,64 @@@ static int parse_decoration_style(cons return -1; } + static int decorate_callback(const struct option *opt, const char *arg, int unset) + { + if (unset) + decoration_style = 0; + else if (arg) + decoration_style = parse_decoration_style("command line", arg); + else + decoration_style = DECORATE_SHORT_REFS; + + if (decoration_style < 0) + die("invalid --decorate option: %s", arg); + + decoration_given = 1; + + return 0; + } + -static void cmd_log_init(int argc, const char **argv, const char *prefix, +static void cmd_log_init_defaults(struct rev_info *rev) +{ + rev->abbrev = DEFAULT_ABBREV; + rev->commit_format = CMIT_FMT_DEFAULT; + if (fmt_pretty) + get_commit_format(fmt_pretty, rev); + rev->verbose_header = 1; + DIFF_OPT_SET(&rev->diffopt, RECURSIVE); + rev->show_root_diff = default_show_root; + rev->subject_prefix = fmt_patch_subject_prefix; + DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV); + + if (default_date_mode) + rev->date_mode = parse_date_format(default_date_mode); +} + +static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, struct rev_info *rev, struct setup_revision_opt *opt) { - int i; - int decoration_given = 0; struct userformat_want w; - /* - * Check for -h before setup_revisions(), or "git log -h" will - * fail when run without a git directory. - */ - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(builtin_log_usage); + int quiet = 0, source = 0; + + const struct option builtin_log_options[] = { + OPT_BOOLEAN(0, "quiet", &quiet, "supress diff output"), + OPT_BOOLEAN(0, "source", &source, "show source"), + { OPTION_CALLBACK, 0, "decorate", NULL, NULL, "decorate options", + PARSE_OPT_OPTARG, decorate_callback}, + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, + builtin_log_options, builtin_log_usage, + PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN | + PARSE_OPT_KEEP_DASHDASH); + - rev->abbrev = DEFAULT_ABBREV; - rev->commit_format = CMIT_FMT_DEFAULT; - if (fmt_pretty) - get_commit_format(fmt_pretty, rev); - rev->verbose_header = 1; - DIFF_OPT_SET(&rev->diffopt, RECURSIVE); - rev->show_root_diff = default_show_root; - rev->subject_prefix = fmt_patch_subject_prefix; - DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV); - - if (default_date_mode) - rev->date_mode = parse_date_format(default_date_mode); - argc = setup_revisions(argc, argv, rev, opt); + /* Any arguments at this point are not recognized */ + if (argc > 1) + die("unrecognized argument: %s", argv[1]); + memset(&w, 0, sizeof(w)); userformat_find_requirements(NULL, &w); @@@ -91,29 -119,12 +122,12 @@@ rev->always_show_header = 0; if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) { rev->always_show_header = 0; - if (rev->diffopt.nr_paths != 1) + if (rev->diffopt.pathspec.nr != 1) usage("git logs can only follow renames on one pathname at a time"); } - for (i = 1; i < argc; i++) { - const char *arg = argv[i]; - if (!strcmp(arg, "--decorate")) { - decoration_style = DECORATE_SHORT_REFS; - decoration_given = 1; - } else if (!prefixcmp(arg, "--decorate=")) { - const char *v = skip_prefix(arg, "--decorate="); - decoration_style = parse_decoration_style(arg, v); - if (decoration_style < 0) - die(_("invalid --decorate option: %s"), arg); - decoration_given = 1; - } else if (!strcmp(arg, "--no-decorate")) { - decoration_style = 0; - } else if (!strcmp(arg, "--source")) { - rev->show_source = 1; - } else if (!strcmp(arg, "-h")) { - usage(builtin_log_usage); - } else - die(_("unrecognized argument: %s"), arg); - } + + if (source) + rev->show_source = 1; /* * defeat log.decorate configuration interacting with --pretty=raw