diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-06-28 22:53:29 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-06-28 22:53:29 +0300 |
commit | a9097269036141876c586ddeee561a37b686c8e5 (patch) | |
tree | 7f496e3fd3a4c8aca1fe95c0978744e28e860e28 | |
parent | ed843436dd4924c10669820cc73daf50f0b4dabd (diff) | |
parent | 7865d157a5e8d86f46e626d933bda5c18eab196a (diff) |
Merge branch 'ab/refspec-init-fix'
Make refspec parsing codepath more robust.
* ab/refspec-init-fix:
refspec: initalize `refspec_item` in `valid_fetch_refspec()`
refspec: add back a refspec_item_init() function
refspec: s/refspec_item_init/&_or_die/g
-rw-r--r-- | builtin/clone.c | 2 | ||||
-rw-r--r-- | builtin/pull.c | 2 | ||||
-rw-r--r-- | refspec.c | 13 | ||||
-rw-r--r-- | refspec.h | 5 |
4 files changed, 15 insertions, 7 deletions
diff --git a/builtin/clone.c b/builtin/clone.c index 99e73dae859..74a804f2e81 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1077,7 +1077,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (option_required_reference.nr || option_optional_reference.nr) setup_reference(); - refspec_item_init(&refspec, value.buf, REFSPEC_FETCH); + refspec_item_init_or_die(&refspec, value.buf, REFSPEC_FETCH); strbuf_reset(&value); diff --git a/builtin/pull.c b/builtin/pull.c index 49cc3beb4c4..fe002a72f8a 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -684,7 +684,7 @@ static const char *get_tracking_branch(const char *remote, const char *refspec) const char *spec_src; const char *merge_branch; - refspec_item_init(&spec, refspec, REFSPEC_FETCH); + refspec_item_init_or_die(&spec, refspec, REFSPEC_FETCH); spec_src = spec.src; if (!*spec_src || !strcmp(spec_src, "HEAD")) spec_src = "HEAD"; diff --git a/refspec.c b/refspec.c index 78edc48ae8e..e8010dce0ce 100644 --- a/refspec.c +++ b/refspec.c @@ -124,11 +124,16 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet return 1; } -void refspec_item_init(struct refspec_item *item, const char *refspec, int fetch) +int refspec_item_init(struct refspec_item *item, const char *refspec, int fetch) { memset(item, 0, sizeof(*item)); + return parse_refspec(item, refspec, fetch); +} - if (!parse_refspec(item, refspec, fetch)) +void refspec_item_init_or_die(struct refspec_item *item, const char *refspec, + int fetch) +{ + if (!refspec_item_init(item, refspec, fetch)) die("Invalid refspec '%s'", refspec); } @@ -152,7 +157,7 @@ void refspec_append(struct refspec *rs, const char *refspec) { struct refspec_item item; - refspec_item_init(&item, refspec, rs->fetch); + refspec_item_init_or_die(&item, refspec, rs->fetch); ALLOC_GROW(rs->items, rs->nr + 1, rs->alloc); rs->items[rs->nr++] = item; @@ -191,7 +196,7 @@ void refspec_clear(struct refspec *rs) int valid_fetch_refspec(const char *fetch_refspec_str) { struct refspec_item refspec; - int ret = parse_refspec(&refspec, fetch_refspec_str, REFSPEC_FETCH); + int ret = refspec_item_init(&refspec, fetch_refspec_str, REFSPEC_FETCH); refspec_item_clear(&refspec); return ret; } diff --git a/refspec.h b/refspec.h index 3a9363887c4..9b6e64a824e 100644 --- a/refspec.h +++ b/refspec.h @@ -32,7 +32,10 @@ struct refspec { int fetch; }; -void refspec_item_init(struct refspec_item *item, const char *refspec, 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, + int fetch); void refspec_item_clear(struct refspec_item *item); void refspec_init(struct refspec *rs, int fetch); void refspec_append(struct refspec *rs, const char *refspec); |