Code

Merge branch 'jn/gitweb-unspecified-action' into maint-1.7.8
[git.git] / parse-options.c
index 73bd28ad90986af1618d82176076133186d045de..f0098eb8ea7eed27d8a67952481f043ce7c75d4a 100644 (file)
@@ -11,14 +11,14 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
-static int optbug(const struct option *opt, const char *reason)
+int optbug(const struct option *opt, const char *reason)
 {
        if (opt->long_name)
                return error("BUG: option '%s' %s", opt->long_name, reason);
        return error("BUG: switch '%c' %s", opt->short_name, reason);
 }
 
-static int opterror(const struct option *opt, const char *reason, int flags)
+int opterror(const struct option *opt, const char *reason, int flags)
 {
        if (flags & OPT_SHORT)
                return error("switch `%c' %s", opt->short_name, reason);
@@ -83,7 +83,7 @@ static int get_value(struct parse_opt_ctx_t *p,
                        *(int *)opt->value &= ~opt->defval;
                return 0;
 
-       case OPTION_BOOLEAN:
+       case OPTION_COUNTUP:
                *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;
                return 0;
 
@@ -319,7 +319,7 @@ static void parse_options_check(const struct option *opts)
                        err |= optbug(opts, "uses feature "
                                        "not supported for dashless options");
                switch (opts->type) {
-               case OPTION_BOOLEAN:
+               case OPTION_COUNTUP:
                case OPTION_BIT:
                case OPTION_NEGBIT:
                case OPTION_SET_INT:
@@ -583,107 +583,3 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,
        return usage_with_options_internal(ctx, usagestr, opts, 0, err);
 }
 
-
-/*----- some often used options -----*/
-#include "cache.h"
-
-int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
-{
-       int v;
-
-       if (!arg) {
-               v = unset ? 0 : DEFAULT_ABBREV;
-       } else {
-               v = strtol(arg, (char **)&arg, 10);
-               if (*arg)
-                       return opterror(opt, "expects a numerical value", 0);
-               if (v && v < MINIMUM_ABBREV)
-                       v = MINIMUM_ABBREV;
-               else if (v > 40)
-                       v = 40;
-       }
-       *(int *)(opt->value) = v;
-       return 0;
-}
-
-int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
-                            int unset)
-{
-       *(unsigned long *)(opt->value) = approxidate(arg);
-       return 0;
-}
-
-int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
-                           int unset)
-{
-       int value;
-
-       if (!arg)
-               arg = unset ? "never" : (const char *)opt->defval;
-       value = git_config_colorbool(NULL, arg, -1);
-       if (value < 0)
-               return opterror(opt,
-                       "expects \"always\", \"auto\", or \"never\"", 0);
-       *(int *)opt->value = value;
-       return 0;
-}
-
-int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
-                          int unset)
-{
-       int *target = opt->value;
-
-       if (unset)
-               /* --no-quiet, --no-verbose */
-               *target = 0;
-       else if (opt->short_name == 'v') {
-               if (*target >= 0)
-                       (*target)++;
-               else
-                       *target = 1;
-       } else {
-               if (*target <= 0)
-                       (*target)--;
-               else
-                       *target = -1;
-       }
-       return 0;
-}
-
-int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)
-{
-       unsigned char sha1[20];
-       struct commit *commit;
-
-       if (!arg)
-               return -1;
-       if (get_sha1(arg, sha1))
-               return error("malformed object name %s", arg);
-       commit = lookup_commit_reference(sha1);
-       if (!commit)
-               return error("no such commit %s", arg);
-       commit_list_insert(commit, opt->value);
-       return 0;
-}
-
-int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
-{
-       int *target = opt->value;
-       *target = unset ? 2 : 1;
-       return 0;
-}
-
-int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)
-{
-       int i, j;
-
-       for (i = 0; i < dst_size; i++)
-               if (dst[i].type == OPTION_END)
-                       break;
-       for (j = 0; i < dst_size; i++, j++) {
-               dst[i] = src[j];
-               if (src[j].type == OPTION_END)
-                       return 0;
-       }
-       return -1;
-}