refspec: add back a refspec_item_init() function

Re-add the non-fatal version of refspec_item_init_or_die() renamed
away in an earlier change to get a more minimal diff. This should be
used by callers that have their own error handling.

This new function could be marked "static" since nothing outside of
refspec.c uses it, but expecting future use of it, let's make it
available to other users.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2018-06-05 19:54:39 +00:00 коммит произвёл Junio C Hamano
Родитель dc06422183
Коммит c495fd3d1b
2 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -122,12 +122,16 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
return 1; return 1;
} }
int refspec_item_init(struct refspec_item *item, const char *refspec, int fetch)
{
memset(item, 0, sizeof(*item));
return parse_refspec(item, refspec, fetch);
}
void refspec_item_init_or_die(struct refspec_item *item, const char *refspec, void refspec_item_init_or_die(struct refspec_item *item, const char *refspec,
int fetch) int fetch)
{ {
memset(item, 0, sizeof(*item)); if (!refspec_item_init(item, refspec, fetch))
if (!parse_refspec(item, refspec, fetch))
die("Invalid refspec '%s'", refspec); die("Invalid refspec '%s'", refspec);
} }

Просмотреть файл

@ -32,6 +32,8 @@ struct refspec {
int fetch; int fetch;
}; };
int refspec_item_init(struct refspec_item *item, const char *refspec,
int fetch);
void refspec_item_init_or_die(struct refspec_item *item, const char *refspec, void refspec_item_init_or_die(struct refspec_item *item, const char *refspec,
int fetch); int fetch);
void refspec_item_clear(struct refspec_item *item); void refspec_item_clear(struct refspec_item *item);