From: Junio C Hamano Date: Mon, 4 Jun 2018 12:39:50 +0000 (+0900) Subject: Merge branch 'bw/refspec-api' X-Git-Tag: v2.18.0-rc1~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/01cbd9eab5710a409e2e760fa20aeb701fa5e799?ds=inline;hp=-c Merge branch 'bw/refspec-api' Hotfix. * bw/refspec-api: refspec-api: avoid uninitialized field in refspec item --- 01cbd9eab5710a409e2e760fa20aeb701fa5e799 diff --combined refspec.c index ada7854f7a,6e45365a23..78edc48ae8 --- a/refspec.c +++ b/refspec.c @@@ -1,5 -1,4 +1,5 @@@ #include "cache.h" +#include "argv-array.h" #include "refs.h" #include "refspec.h" @@@ -49,6 -48,8 +49,8 @@@ static int parse_refspec(struct refspec 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)); @@@ -193,33 -194,3 +195,33 @@@ int valid_fetch_refspec(const char *fet 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); + } + } + } +}