]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refspec: remove refspec_item_init_or_die()
authorTaylor Blau <me@ttaylorr.com>
Tue, 18 Mar 2025 22:50:24 +0000 (18:50 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Mar 2025 08:45:16 +0000 (01:45 -0700)
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>
builtin/pull.c
refspec.c
refspec.h

index 8bbfcce7295911e779274090ba24b1c125ba01e7..a68a9955de5ad2db96e99f2a92c609a2b65a63f0 100644 (file)
@@ -738,7 +738,8 @@ static const char *get_tracking_branch(const char *remote, const char *refspec)
        const char *spec_src;
        const char *merge_branch;
 
-       refspec_item_init_or_die(&spec, refspec, 1);
+       if (!refspec_item_init(&spec, refspec, 1))
+               die(_("invalid refspec '%s'"), refspec);
        spec_src = spec.src;
        if (!*spec_src || !strcmp(spec_src, "HEAD"))
                spec_src = "HEAD";
index f6be0c54d76c9d18f39984bb9862567258b1e453..3aeb6975058b06c0ccebd57edcdc59109bfd2ace 100644 (file)
--- a/refspec.c
+++ b/refspec.c
@@ -160,13 +160,6 @@ int refspec_item_init(struct refspec_item *item, const char *refspec, int fetch)
        return 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);
-}
-
 void refspec_item_clear(struct refspec_item *item)
 {
        FREE_AND_NULL(item->src);
@@ -194,7 +187,8 @@ void refspec_append(struct refspec *rs, const char *refspec)
 {
        struct refspec_item item;
 
-       refspec_item_init_or_die(&item, refspec, rs->fetch);
+       if (!refspec_item_init(&item, refspec, rs->fetch))
+               die(_("invalid refspec '%s'"), refspec);
 
        ALLOC_GROW(rs->items, rs->nr + 1, rs->alloc);
        rs->items[rs->nr] = item;
index 7db68e56c8366fad449e8eed8c6157fd94690c2e..614f34554e8a4f486344e31b4348b86dfeee61c0 100644 (file)
--- a/refspec.h
+++ b/refspec.h
@@ -49,8 +49,6 @@ struct refspec {
 
 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_fetch(struct refspec *rs);
 void refspec_init_push(struct refspec *rs);