refspec: convert valid_fetch_refspec to use parse_refspec

Convert 'valid_fetch_refspec()' to use the new 'parse_refspec()' function to only parse a single refspec and eliminate an allocation. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed May 16, 2018 at 15:57 UTC c8fa9efe3a8765f44eacc5b0e114053a0297dfff
2 files changed +10 -10
refspec.c
+8 -9
@@ -146,15 +146,6 @@ static struct refspec_item *parse_refspec_internal(int nr_refspec, const char **
146 die("Invalid refspec '%s'", refspec[i]);
147 }
148
149 -int valid_fetch_refspec(const char *fetch_refspec_str)
150 -{
151 - struct refspec_item *refspec;
152 -
153 - refspec = parse_refspec_internal(1, &fetch_refspec_str, 1, 1);
154 - free_refspec(1, refspec);
155 - return !!refspec;
156 -}
157 -
149 struct refspec_item *parse_fetch_refspec(int nr_refspec, const char **refspec)
150 {
151 return parse_refspec_internal(nr_refspec, refspec, 1, 0);
@@ -242,3 +233,11 @@ void refspec_clear(struct refspec *rs)
233
234 rs->fetch = 0;
235 }
236 +
237 +int valid_fetch_refspec(const char *fetch_refspec_str)
238 +{
239 + struct refspec_item refspec;
240 + int ret = parse_refspec(&refspec, fetch_refspec_str, REFSPEC_FETCH);
241 + refspec_item_clear(&refspec);
242 + return ret;
243 +}
refspec.h
+2 -1
@@ -14,7 +14,6 @@ struct refspec_item {
14 char *dst;
15 };
16
17 -int valid_fetch_refspec(const char *refspec);
17 struct refspec_item *parse_fetch_refspec(int nr_refspec, const char **refspec);
18 struct refspec_item *parse_push_refspec(int nr_refspec, const char **refspec);
19
@@ -45,4 +44,6 @@ void refspec_append(struct refspec *rs, const char *refspec);
44 void refspec_appendn(struct refspec *rs, const char **refspecs, int nr);
45 void refspec_clear(struct refspec *rs);
46
47 +int valid_fetch_refspec(const char *refspec);
48 +
49 #endif /* REFSPEC_H */