Skip to content

Commit c8fa9ef

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6d4c057 commit c8fa9ef

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

refspec.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,6 @@ static struct refspec_item *parse_refspec_internal(int nr_refspec, const char **
146146
die("Invalid refspec '%s'", refspec[i]);
147147
}
148148

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-
158149
struct refspec_item *parse_fetch_refspec(int nr_refspec, const char **refspec)
159150
{
160151
return parse_refspec_internal(nr_refspec, refspec, 1, 0);
@@ -242,3 +233,11 @@ void refspec_clear(struct refspec *rs)
242233

243234
rs->fetch = 0;
244235
}
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ struct refspec_item {
1414
char *dst;
1515
};
1616
17-
int valid_fetch_refspec(const char *refspec);
1817
struct refspec_item *parse_fetch_refspec(int nr_refspec, const char **refspec);
1918
struct refspec_item *parse_push_refspec(int nr_refspec, const char **refspec);
2019
@@ -45,4 +44,6 @@ void refspec_append(struct refspec *rs, const char *refspec);
4544
void refspec_appendn(struct refspec *rs, const char **refspecs, int nr);
4645
void refspec_clear(struct refspec *rs);
4746
47+
int valid_fetch_refspec(const char *refspec);
48+
4849
#endif /* REFSPEC_H */

0 commit comments

Comments
 (0)