]> git.ipfire.org Git - thirdparty/git.git/blobdiff - refspec.c
t5318: avoid unnecessary command substitutions
[thirdparty/git.git] / refspec.c
index c59a4ccf1e5d689b6f9cff00ee695a7ec4e40870..e8010dce0ce27472c2b3269e13b9c1de6a69f3cc 100644 (file)
--- a/refspec.c
+++ b/refspec.c
@@ -49,6 +49,8 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
                size_t rlen = strlen(++rhs);
                is_glob = (1 <= rlen && strchr(rhs, '*'));
                item->dst = xstrndup(rhs, rlen);
+       } else {
+               item->dst = NULL;
        }
 
        llen = (rhs ? (rhs - lhs - 1) : strlen(lhs));
@@ -122,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);
 }
 
@@ -150,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;
@@ -189,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;
 }
@@ -202,6 +209,8 @@ void refspec_ref_prefixes(const struct refspec *rs,
                const struct refspec_item *item = &rs->items[i];
                const char *prefix = NULL;
 
+               if (item->exact_sha1)
+                       continue;
                if (rs->fetch == REFSPEC_FETCH)
                        prefix = item->src;
                else if (item->dst)