Merge branch 'bw/refspec-api'
authorJunio C Hamano <gitster@pobox.com>
Mon, 4 Jun 2018 12:39:50 +0000 (21:39 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 4 Jun 2018 12:39:50 +0000 (21:39 +0900)
Hotfix.

* bw/refspec-api:
refspec-api: avoid uninitialized field in refspec item

1  2 
refspec.c
diff --combined refspec.c
index ada7854f7a6a55a783cf90574e1d759f5c3a661f,6e45365a23563b3cfd62f025fc74ec7980382ac7..78edc48ae8eebcfdbfd87172e7ef4ead6c3fff85
+++ 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);
 +                      }
 +              }
 +      }
 +}