refspec: add git_refspec__free, remove git_refspec_parse The latter shouldn't be exposed and isn't used, git_refspec__parse supersedes it. Fix a leak in the refspec tests while we're at it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
diff --git a/include/git2/refspec.h b/include/git2/refspec.h
index 9e84aad..1100e90 100644
--- a/include/git2/refspec.h
+++ b/include/git2/refspec.h
@@ -20,14 +20,6 @@
GIT_BEGIN_DECL
/**
- * Parse a refspec string and create a refspec object
- *
- * @param refspec pointer to the refspec structure to be used
- * @param str the refspec as a string
- */
-GIT_EXTERN(int) git_refspec_parse(git_refspec *refspec, const char *str);
-
-/**
* Get the source specifier
*
* @param refspec the refspec
diff --git a/src/refspec.c b/src/refspec.c
index 1265c56..cd3a528 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -125,35 +125,10 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
return -1;
}
-int git_refspec_parse(git_refspec *refspec, const char *str)
+void git_refspec__free(git_refspec *refspec)
{
- char *delim;
-
- memset(refspec, 0x0, sizeof(git_refspec));
-
- if (*str == '+') {
- refspec->force = 1;
- str++;
- }
-
- delim = strchr(str, ':');
- if (delim == NULL) {
- refspec->src = git__strdup(str);
- GITERR_CHECK_ALLOC(refspec->src);
- return 0;
- }
-
- refspec->src = git__strndup(str, delim - str);
- GITERR_CHECK_ALLOC(refspec->src);
-
- refspec->dst = git__strdup(delim + 1);
- if (refspec->dst == NULL) {
- git__free(refspec->src);
- refspec->src = NULL;
- return -1;
- }
-
- return 0;
+ git__free(refspec->src);
+ git__free(refspec->dst);
}
const char *git_refspec_src(const git_refspec *refspec)
diff --git a/src/refspec.h b/src/refspec.h
index 2f46b3e..8307815 100644
--- a/src/refspec.h
+++ b/src/refspec.h
@@ -25,6 +25,8 @@ int git_refspec__parse(
const char *str,
bool is_fetch);
+void git_refspec__free(git_refspec *refspec);
+
/**
* Transform a reference to its target following the refspec's rules,
* and writes the results into a git_buf.
diff --git a/src/remote.c b/src/remote.c
index 7bc631d..0ae47c3 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -536,10 +536,8 @@ void git_remote_free(git_remote *remote)
git_vector_free(&remote->refs);
- git__free(remote->fetch.src);
- git__free(remote->fetch.dst);
- git__free(remote->push.src);
- git__free(remote->push.dst);
+ git_refspec__free(&remote->fetch);
+ git_refspec__free(&remote->push);
git__free(remote->url);
git__free(remote->pushurl);
git__free(remote->name);
diff --git a/tests-clar/network/refspecs.c b/tests-clar/network/refspecs.c
index bfe0af4..3b12817 100644
--- a/tests-clar/network/refspecs.c
+++ b/tests-clar/network/refspecs.c
@@ -8,6 +8,7 @@ static void assert_refspec(unsigned int direction, const char *input, bool is_ex
int error;
error = git_refspec__parse(&refspec, input, direction == GIT_DIR_FETCH);
+ git_refspec__free(&refspec);
if (is_expected_to_be_valid)
cl_assert_equal_i(0, error);