Skip to content

Commit

Permalink
list-objects-filter-options: always supply *errbuf
Browse files Browse the repository at this point in the history
Making errbuf an optional argument complicates error reporting. Fix this
by making all callers supply an errbuf, even if they may ignore it. This
will be important in follow-up patches where the filter-spec parsing has
more pitfalls and possible errors.

Signed-off-by: Matthew DeVore <matvore@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
matvore authored and gitster committed Jun 18, 2019
1 parent 65cee9a commit e1ac4a4
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions list-objects-filter-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ static int gently_parse_list_objects_filter(
const char *v0;

if (filter_options->choice) {
if (errbuf) {
strbuf_addstr(
errbuf,
_("multiple filter-specs cannot be combined"));
}
strbuf_addstr(
errbuf, _("multiple filter-specs cannot be combined"));
return 1;
}

Expand All @@ -52,11 +49,7 @@ static int gently_parse_list_objects_filter(

} else if (skip_prefix(arg, "tree:", &v0)) {
if (!git_parse_ulong(v0, &filter_options->tree_exclude_depth)) {
if (errbuf) {
strbuf_addstr(
errbuf,
_("expected 'tree:<depth>'"));
}
strbuf_addstr(errbuf, _("expected 'tree:<depth>'"));
return 1;
}
filter_options->choice = LOFC_TREE_DEPTH;
Expand Down Expand Up @@ -90,8 +83,7 @@ static int gently_parse_list_objects_filter(
* add new filters
*/

if (errbuf)
strbuf_addf(errbuf, "invalid filter-spec '%s'", arg);
strbuf_addf(errbuf, "invalid filter-spec '%s'", arg);

memset(filter_options, 0, sizeof(*filter_options));
return 1;
Expand Down Expand Up @@ -175,12 +167,15 @@ void partial_clone_register(
void partial_clone_get_default_filter_spec(
struct list_objects_filter_options *filter_options)
{
struct strbuf errbuf = STRBUF_INIT;

/*
* Parse default value, but silently ignore it if it is invalid.
*/
if (!core_partial_clone_filter_default)
return;
gently_parse_list_objects_filter(filter_options,
core_partial_clone_filter_default,
NULL);
&errbuf);
strbuf_release(&errbuf);
}

0 comments on commit e1ac4a4

Please sign in to comment.