@@ -586,7 +586,7 @@ static struct ref *get_ref_map(struct remote *remote,
struct refspec_item tag_refspec;
/* also fetch all tags */
- refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);
+ refspec_item_init_push(&tag_refspec, TAG_REFSPEC);
get_fetch_map(remote_refs, &tag_refspec, &tail, 0);
refspec_item_clear(&tag_refspec);
} else if (tags == TAGS_DEFAULT && *autotags) {
@@ -738,7 +738,7 @@ static const char *get_tracking_branch(const char *remote, const char *refspec)
const char *spec_src;
const char *merge_branch;
- if (!refspec_item_init(&spec, refspec, 1))
+ if (!refspec_item_init_fetch(&spec, refspec))
die(_("invalid refspec '%s'"), refspec);
spec_src = spec.src;
if (!*spec_src || !strcmp(spec_src, "HEAD"))
@@ -153,13 +153,24 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
return 1;
}
-int refspec_item_init(struct refspec_item *item, const char *refspec, int fetch)
+static int refspec_item_init(struct refspec_item *item, const char *refspec,
+ int fetch)
{
memset(item, 0, sizeof(*item));
item->raw = xstrdup(refspec);
return parse_refspec(item, refspec, fetch);
}
+int refspec_item_init_fetch(struct refspec_item *item, const char *refspec)
+{
+ return refspec_item_init(item, refspec, 1);
+}
+
+int refspec_item_init_push(struct refspec_item *item, const char *refspec)
+{
+ return refspec_item_init(item, refspec, 0);
+}
+
void refspec_item_clear(struct refspec_item *item)
{
FREE_AND_NULL(item->src);
@@ -186,8 +197,13 @@ void refspec_init_push(struct refspec *rs)
void refspec_append(struct refspec *rs, const char *refspec)
{
struct refspec_item item;
+ int ret;
- if (!refspec_item_init(&item, refspec, rs->fetch))
+ if (rs->fetch)
+ ret = refspec_item_init_fetch(&item, refspec);
+ else
+ ret = refspec_item_init_push(&item, refspec);
+ if (!ret)
die(_("invalid refspec '%s'"), refspec);
ALLOC_GROW(rs->items, rs->nr + 1, rs->alloc);
@@ -233,7 +249,7 @@ void refspec_clear(struct refspec *rs)
int valid_fetch_refspec(const char *fetch_refspec_str)
{
struct refspec_item refspec;
- int ret = refspec_item_init(&refspec, fetch_refspec_str, 1);
+ int ret = refspec_item_init_fetch(&refspec, fetch_refspec_str);
refspec_item_clear(&refspec);
return ret;
}
@@ -47,8 +47,8 @@ struct refspec {
unsigned fetch : 1;
};
-int refspec_item_init(struct refspec_item *item, const char *refspec,
- int fetch);
+int refspec_item_init_fetch(struct refspec_item *item, const char *refspec);
+int refspec_item_init_push(struct refspec_item *item, const char *refspec);
void refspec_item_clear(struct refspec_item *item);
void refspec_init_fetch(struct refspec *rs);
void refspec_init_push(struct refspec *rs);
For similar reasons as in the previous refactoring of `refspec_init()` into `refspec_init_fetch()` and `refspec_init_push()`, apply the same refactoring to `refspec_item_init()`. Signed-off-by: Taylor Blau <me@ttaylorr.com> --- builtin/fetch.c | 2 +- builtin/pull.c | 2 +- refspec.c | 22 +++++++++++++++++++--- refspec.h | 4 ++-- 4 files changed, 23 insertions(+), 7 deletions(-)