Git fork

refspec: remove refspec_item_init_or_die()

There are two callers of this function, which ensures that a dispatched
call to refspec_item_init() does not fail.

In the following commit, we're going to add fetch/push-specific variants
of refspec_item_init(), which will turn one function into two. To avoid
introducing yet another pair of new functions (such as
refspec_item_init_push_or_die() and refspec_item_init_fetch_or_die()),
let's remove the thin wrapper entirely.

This duplicates a single line of code among two callers, but thins the
refspec.h API by one function, and prevents introducing two more in the
following commit.

Note that we still have a trailing Boolean argument in the function
`refspec_item_init()`. The following commit will address this.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Acked-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Taylor Blau and committed by
Junio C Hamano
ec6829e4 0baad1f3

+4 -11
+2 -1
builtin/pull.c
··· 738 const char *spec_src; 739 const char *merge_branch; 740 741 - refspec_item_init_or_die(&spec, refspec, 1); 742 spec_src = spec.src; 743 if (!*spec_src || !strcmp(spec_src, "HEAD")) 744 spec_src = "HEAD";
··· 738 const char *spec_src; 739 const char *merge_branch; 740 741 + if (!refspec_item_init(&spec, refspec, 1)) 742 + die(_("invalid refspec '%s'"), refspec); 743 spec_src = spec.src; 744 if (!*spec_src || !strcmp(spec_src, "HEAD")) 745 spec_src = "HEAD";
+2 -8
refspec.c
··· 160 return parse_refspec(item, refspec, fetch); 161 } 162 163 - void refspec_item_init_or_die(struct refspec_item *item, const char *refspec, 164 - int fetch) 165 - { 166 - if (!refspec_item_init(item, refspec, fetch)) 167 - die(_("invalid refspec '%s'"), refspec); 168 - } 169 - 170 void refspec_item_clear(struct refspec_item *item) 171 { 172 FREE_AND_NULL(item->src); ··· 194 { 195 struct refspec_item item; 196 197 - refspec_item_init_or_die(&item, refspec, rs->fetch); 198 199 ALLOC_GROW(rs->items, rs->nr + 1, rs->alloc); 200 rs->items[rs->nr] = item;
··· 160 return parse_refspec(item, refspec, fetch); 161 } 162 163 void refspec_item_clear(struct refspec_item *item) 164 { 165 FREE_AND_NULL(item->src); ··· 187 { 188 struct refspec_item item; 189 190 + if (!refspec_item_init(&item, refspec, rs->fetch)) 191 + die(_("invalid refspec '%s'"), refspec); 192 193 ALLOC_GROW(rs->items, rs->nr + 1, rs->alloc); 194 rs->items[rs->nr] = item;
-2
refspec.h
··· 49 50 int refspec_item_init(struct refspec_item *item, const char *refspec, 51 int fetch); 52 - void refspec_item_init_or_die(struct refspec_item *item, const char *refspec, 53 - int fetch); 54 void refspec_item_clear(struct refspec_item *item); 55 void refspec_init_fetch(struct refspec *rs); 56 void refspec_init_push(struct refspec *rs);
··· 49 50 int refspec_item_init(struct refspec_item *item, const char *refspec, 51 int fetch); 52 void refspec_item_clear(struct refspec_item *item); 53 void refspec_init_fetch(struct refspec *rs); 54 void refspec_init_push(struct refspec *rs);