1 #include "git-compat-util.h"
2 #include "parse-options.h"
6 #include "string-list.h"
8 /*----- some often used options -----*/
10 int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
15 v = unset ? 0 : DEFAULT_ABBREV;
17 v = strtol(arg, (char **)&arg, 10);
19 return opterror(opt, "expects a numerical value", 0);
20 if (v && v < MINIMUM_ABBREV)
25 *(int *)(opt->value) = v;
29 int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
32 *(unsigned long *)(opt->value) = approxidate(arg);
36 int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
42 arg = unset ? "never" : (const char *)opt->defval;
43 value = git_config_colorbool(NULL, arg);
46 "expects \"always\", \"auto\", or \"never\"", 0);
47 *(int *)opt->value = value;
51 int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
54 int *target = opt->value;
57 /* --no-quiet, --no-verbose */
59 else if (opt->short_name == 'v') {
73 int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)
75 unsigned char sha1[20];
76 struct commit *commit;
80 if (get_sha1(arg, sha1))
81 return error("malformed object name %s", arg);
82 commit = lookup_commit_reference(sha1);
84 return error("no such commit %s", arg);
85 commit_list_insert(commit, opt->value);
89 int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
91 int *target = opt->value;
92 *target = unset ? 2 : 1;
96 int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)
100 for (i = 0; i < dst_size; i++)
101 if (dst[i].type == OPTION_END)
103 for (j = 0; i < dst_size; i++, j++) {
105 if (src[j].type == OPTION_END)
111 int parse_opt_string_list(const struct option *opt, const char *arg, int unset)
113 struct string_list *v = opt->value;
116 string_list_clear(v, 0);
123 string_list_append(v, xstrdup(arg));