Skip to content

Commit ec6829e

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Acked-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0baad1f commit ec6829e

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

builtin/pull.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ static const char *get_tracking_branch(const char *remote, const char *refspec)
738738
const char *spec_src;
739739
const char *merge_branch;
740740

741-
refspec_item_init_or_die(&spec, refspec, 1);
741+
if (!refspec_item_init(&spec, refspec, 1))
742+
die(_("invalid refspec '%s'"), refspec);
742743
spec_src = spec.src;
743744
if (!*spec_src || !strcmp(spec_src, "HEAD"))
744745
spec_src = "HEAD";

refspec.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,6 @@ int refspec_item_init(struct refspec_item *item, const char *refspec, int fetch)
160160
return parse_refspec(item, refspec, fetch);
161161
}
162162

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-
170163
void refspec_item_clear(struct refspec_item *item)
171164
{
172165
FREE_AND_NULL(item->src);
@@ -194,7 +187,8 @@ void refspec_append(struct refspec *rs, const char *refspec)
194187
{
195188
struct refspec_item item;
196189

197-
refspec_item_init_or_die(&item, refspec, rs->fetch);
190+
if (!refspec_item_init(&item, refspec, rs->fetch))
191+
die(_("invalid refspec '%s'"), refspec);
198192

199193
ALLOC_GROW(rs->items, rs->nr + 1, rs->alloc);
200194
rs->items[rs->nr] = item;

refspec.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ struct refspec {
4949

5050
int refspec_item_init(struct refspec_item *item, const char *refspec,
5151
int fetch);
52-
void refspec_item_init_or_die(struct refspec_item *item, const char *refspec,
53-
int fetch);
5452
void refspec_item_clear(struct refspec_item *item);
5553
void refspec_init_fetch(struct refspec *rs);
5654
void refspec_init_push(struct refspec *rs);

0 commit comments

Comments
 (0)