summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-05-31 00:27:47 -0400
committerJunio C Hamano <gitster@pobox.com>2017-06-01 09:59:00 +0900
commita56eea28c45a8f76e4167c4e6baa87e89b7be3bc (patch)
treeec7d632c2fc3c136147aae12ce14d270d1931c5a /remote.c
parentb06d3643105c8758ed019125a4399cb7efdcce2c (diff)
downloadgit-a56eea28c45a8f76e4167c4e6baa87e89b7be3bc.tar.gz
remote: drop free_refspecs() functionjk/drop-free-refspecs
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/remote.c b/remote.c
index 801137c72e..fbb405660a 100644
--- a/remote.c
+++ b/remote.c
@@ -477,26 +477,6 @@ static void read_config(void)
alias_all_urls();
}
-/*
- * This function frees a refspec array.
- * Warning: code paths should be checked to ensure that the src
- * and dst pointers are always freeable pointers as well
- * as the refspec pointer itself.
- */
-static void free_refspecs(struct refspec *refspec, int nr_refspec)
-{
- int i;
-
- if (!refspec)
- return;
-
- for (i = 0; i < nr_refspec; i++) {
- free(refspec[i].src);
- free(refspec[i].dst);
- }
- free(refspec);
-}
-
static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify)
{
int i;
@@ -610,7 +590,7 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
* since it is only possible to reach this point from within
* the for loop above.
*/
- free_refspecs(rs, i+1);
+ free_refspec(i+1, rs);
return NULL;
}
die("Invalid refspec '%s'", refspec[i]);
@@ -621,7 +601,7 @@ int valid_fetch_refspec(const char *fetch_refspec_str)
struct refspec *refspec;
refspec = parse_refspec_internal(1, &fetch_refspec_str, 1, 1);
- free_refspecs(refspec, 1);
+ free_refspec(1, refspec);
return !!refspec;
}
@@ -638,6 +618,10 @@ struct refspec *parse_push_refspec(int nr_refspec, const char **refspec)
void free_refspec(int nr_refspec, struct refspec *refspec)
{
int i;
+
+ if (!refspec)
+ return;
+
for (i = 0; i < nr_refspec; i++) {
free(refspec[i].src);
free(refspec[i].dst);