1 #include "git-compat-util.h"
2 #include "parse-options.h"
6 #include "string-list.h"
7 #include "sha1-array.h"
9 /*----- some often used options -----*/
11 int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
16 v = unset ? 0 : DEFAULT_ABBREV;
18 v = strtol(arg, (char **)&arg, 10);
20 return opterror(opt, "expects a numerical value", 0);
21 if (v && v < MINIMUM_ABBREV)
26 *(int *)(opt->value) = v;
30 int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
33 *(unsigned long *)(opt->value) = approxidate(arg);
37 int parse_opt_expiry_date_cb(const struct option *opt, const char *arg,
40 return parse_expiry_date(arg, (unsigned long *)opt->value);
43 int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
49 arg = unset ? "never" : (const char *)opt->defval;
50 value = git_config_colorbool(NULL, arg);
53 "expects \"always\", \"auto\", or \"never\"", 0);
54 *(int *)opt->value = value;
58 int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
61 int *target = opt->value;
64 /* --no-quiet, --no-verbose */
66 else if (opt->short_name == 'v') {
80 int parse_opt_commits(const struct option *opt, const char *arg, int unset)
82 unsigned char sha1[20];
83 struct commit *commit;
87 if (get_sha1(arg, sha1))
88 return error("malformed object name %s", arg);
89 commit = lookup_commit_reference(sha1);
91 return error("no such commit %s", arg);
92 commit_list_insert(commit, opt->value);
96 int parse_opt_object_name(const struct option *opt, const char *arg, int unset)
98 unsigned char sha1[20];
101 sha1_array_clear(opt->value);
106 if (get_sha1(arg, sha1))
107 return error(_("malformed object name '%s'"), arg);
108 sha1_array_append(opt->value, sha1);
112 int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
114 int *target = opt->value;
115 *target = unset ? 2 : 1;
119 int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)
123 for (i = 0; i < dst_size; i++)
124 if (dst[i].type == OPTION_END)
126 for (j = 0; i < dst_size; i++, j++) {
128 if (src[j].type == OPTION_END)
134 int parse_opt_string_list(const struct option *opt, const char *arg, int unset)
136 struct string_list *v = opt->value;
139 string_list_clear(v, 0);
146 string_list_append(v, xstrdup(arg));
150 int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)