Skip to content

Commit a56eea2

Browse files
peffgitster
authored andcommitted
remote: drop free_refspecs() function
We already have free_refspec(), a public function which does the same thing as the static free_refspecs(). Let's just keep one. There are two minor differences between the functions: 1. free_refspecs() is a noop when the refspec argument is NULL. This probably doesn't matter in practice. The nr_refspec parameter would presumably be 0 in that case, skipping the loop. And free(NULL) is explicitly OK. But it doesn't hurt for us to port this extra safety to free_refspec(), as one of the callers passes a funny "i+1" count. 2. The order of arguments is reversed between the two functions. This patch uses the already-public order of free_refspec(), as it matches the argument order on the parsing side. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b06d364 commit a56eea2

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

remote.c

+6-22
Original file line numberDiff line numberDiff line change
@@ -477,26 +477,6 @@ static void read_config(void)
477477
alias_all_urls();
478478
}
479479

480-
/*
481-
* This function frees a refspec array.
482-
* Warning: code paths should be checked to ensure that the src
483-
* and dst pointers are always freeable pointers as well
484-
* as the refspec pointer itself.
485-
*/
486-
static void free_refspecs(struct refspec *refspec, int nr_refspec)
487-
{
488-
int i;
489-
490-
if (!refspec)
491-
return;
492-
493-
for (i = 0; i < nr_refspec; i++) {
494-
free(refspec[i].src);
495-
free(refspec[i].dst);
496-
}
497-
free(refspec);
498-
}
499-
500480
static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify)
501481
{
502482
int i;
@@ -610,7 +590,7 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
610590
* since it is only possible to reach this point from within
611591
* the for loop above.
612592
*/
613-
free_refspecs(rs, i+1);
593+
free_refspec(i+1, rs);
614594
return NULL;
615595
}
616596
die("Invalid refspec '%s'", refspec[i]);
@@ -621,7 +601,7 @@ int valid_fetch_refspec(const char *fetch_refspec_str)
621601
struct refspec *refspec;
622602

623603
refspec = parse_refspec_internal(1, &fetch_refspec_str, 1, 1);
624-
free_refspecs(refspec, 1);
604+
free_refspec(1, refspec);
625605
return !!refspec;
626606
}
627607

@@ -638,6 +618,10 @@ struct refspec *parse_push_refspec(int nr_refspec, const char **refspec)
638618
void free_refspec(int nr_refspec, struct refspec *refspec)
639619
{
640620
int i;
621+
622+
if (!refspec)
623+
return;
624+
641625
for (i = 0; i < nr_refspec; i++) {
642626
free(refspec[i].src);
643627
free(refspec[i].dst);

0 commit comments

Comments
 (0)