git-rebase.txt: address confusion between --no-ff vs --force-rebase
[gitweb.git] / refspec.c
index 97e76e8b1d953c9f2d7b99c906aef17fd375d7f5..78edc48ae8eebcfdbfd87172e7ef4ead6c3fff85 100644 (file)
--- a/refspec.c
+++ b/refspec.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "argv-array.h"
 #include "refs.h"
 #include "refspec.h"
 
@@ -48,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));
@@ -192,3 +195,33 @@ int valid_fetch_refspec(const char *fetch_refspec_str)
        refspec_item_clear(&refspec);
        return ret;
 }
+
+void refspec_ref_prefixes(const struct refspec *rs,
+                         struct argv_array *ref_prefixes)
+{
+       int i;
+       for (i = 0; i < rs->nr; i++) {
+               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)
+                       prefix = item->dst;
+               else if (item->src && !item->exact_sha1)
+                       prefix = item->src;
+
+               if (prefix) {
+                       if (item->pattern) {
+                               const char *glob = strchr(prefix, '*');
+                               argv_array_pushf(ref_prefixes, "%.*s",
+                                                (int)(glob - prefix),
+                                                prefix);
+                       } else {
+                               expand_ref_prefix(ref_prefixes, prefix);
+                       }
+               }
+       }
+}