diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-08-27 08:55:04 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-08-27 08:55:04 +0300 |
commit | bfd91b41341cb922aa1ba6e7c01ccd5ebb81cf41 (patch) | |
tree | 8309adc9af63683b18c6c30c8ee4a4d74fc567dc /builtin | |
parent | 0b9635847944f97079fc6c2283063cd3a0ed0271 (diff) | |
parent | c88bf5436d84762a474048a0a57409a8f2fa2c6b (diff) |
Merge branch 'pb/trailers-from-command-line'
"git interpret-trailers" learned to take the trailer specifications
from the command line that overrides the configured values.
* pb/trailers-from-command-line:
interpret-trailers: fix documentation typo
interpret-trailers: add options for actions
trailers: introduce struct new_trailer_item
trailers: export action enums and corresponding lookup functions
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/interpret-trailers.c | 73 |
1 files changed, 69 insertions, 4 deletions
diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 175f14797b..d7cbaf60f9 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -16,17 +16,82 @@ static const char * const git_interpret_trailers_usage[] = { NULL }; +static enum trailer_where where; +static enum trailer_if_exists if_exists; +static enum trailer_if_missing if_missing; + +static int option_parse_where(const struct option *opt, + const char *arg, int unset) +{ + return trailer_set_where(&where, arg); +} + +static int option_parse_if_exists(const struct option *opt, + const char *arg, int unset) +{ + return trailer_set_if_exists(&if_exists, arg); +} + +static int option_parse_if_missing(const struct option *opt, + const char *arg, int unset) +{ + return trailer_set_if_missing(&if_missing, arg); +} + +static void new_trailers_clear(struct list_head *trailers) +{ + struct list_head *pos, *tmp; + struct new_trailer_item *item; + + list_for_each_safe(pos, tmp, trailers) { + item = list_entry(pos, struct new_trailer_item, list); + list_del(pos); + free(item); + } +} + +static int option_parse_trailer(const struct option *opt, + const char *arg, int unset) +{ + struct list_head *trailers = opt->value; + struct new_trailer_item *item; + + if (unset) { + new_trailers_clear(trailers); + return 0; + } + + if (!arg) + return -1; + + item = xmalloc(sizeof(*item)); + item->text = arg; + item->where = where; + item->if_exists = if_exists; + item->if_missing = if_missing; + list_add_tail(&item->list, trailers); + return 0; +} + int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) { int in_place = 0; int trim_empty = 0; - struct string_list trailers = STRING_LIST_INIT_NODUP; + LIST_HEAD(trailers); struct option options[] = { OPT_BOOL(0, "in-place", &in_place, N_("edit files in place")), OPT_BOOL(0, "trim-empty", &trim_empty, N_("trim empty trailers")), - OPT_STRING_LIST(0, "trailer", &trailers, N_("trailer"), - N_("trailer(s) to add")), + + OPT_CALLBACK(0, "where", NULL, N_("action"), + N_("where to place the new trailer"), option_parse_where), + OPT_CALLBACK(0, "if-exists", NULL, N_("action"), + N_("action if trailer already exists"), option_parse_if_exists), + OPT_CALLBACK(0, "if-missing", NULL, N_("action"), + N_("action if trailer is missing"), option_parse_if_missing), + + OPT_CALLBACK(0, "trailer", &trailers, N_("trailer"), + N_("trailer(s) to add"), option_parse_trailer), OPT_END() }; @@ -43,7 +108,7 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) process_trailers(NULL, in_place, trim_empty, &trailers); } - string_list_clear(&trailers, 0); + new_trailers_clear(&trailers); return 0; } |