diff options
author | Jeff King <peff@peff.net> | 2019-03-20 21:22:15 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-03-21 04:03:35 +0100 |
commit | 95be717cd5a5d4956a5152210176e598cf49ec75 (patch) | |
tree | 31818e4c171801707212006b7856a0d6a089de76 /ref-filter.h | |
parent | pretty: drop unused strbuf from parse_padding_placeholder() (diff) | |
download | git-95be717cd5a5d4956a5152210176e598cf49ec75.tar.xz git-95be717cd5a5d4956a5152210176e598cf49ec75.zip |
parse_opt_ref_sorting: always use with NONEG flag
The "--sort" parameter of for-each-ref, etc, does not handle negation,
and instead returns an error to the parse-options code. But neither
piece of code prints anything for the user, which may leave them
confused:
$ git for-each-ref --no-sort
$ echo $?
129
As the comment in the callback function notes, this probably should
clear the list, which would make it consistent with other list-like
options (i.e., anything that uses OPT_STRING_LIST currently).
Unfortunately that's a bit tricky due to the way the ref-filter code
works. But in the meantime, let's at least make the error a little less
confusing:
- switch to using PARSE_OPT_NONEG in the option definition, which will
cause the options code to produce a useful message
- since this was cut-and-pasted to four different spots, let's define
a single OPT_REF_SORT() macro that we can use everywhere
- the callback can use BUG_ON_OPT_NEG() to make sure the correct flags
are used (incidentally, this also satisfies -Wunused-parameters,
since we're now looking at "unset")
- expand the comment into a NEEDSWORK to make it clear that the
direction is right, but the details need to be worked out
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.h')
-rw-r--r-- | ref-filter.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/ref-filter.h b/ref-filter.h index 85c8ebc3b9..f1dcff4c6e 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -96,6 +96,11 @@ struct ref_format { #define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h) #define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h) +#define OPT_REF_SORT(var) \ + OPT_CALLBACK_F(0, "sort", (var), \ + N_("key"), N_("field name to sort on"), \ + PARSE_OPT_NONEG, parse_opt_ref_sorting) + /* * API for filtering a set of refs. Based on the type of refs the user * has requested, we iterate through those refs and apply filters |