diff options
| author | Carlos Martín Nieto <cmn@dwim.me> | 2013-04-20 18:49:11 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <cmn@dwim.me> | 2013-04-20 19:45:40 +0200 |
| commit | bc6374eac485ab9ad9cfd7165b6d071c3dcb673a (patch) | |
| tree | 8ba82d9d64953384895afb1e26a33c3c7d5c6832 /src/remote.c | |
| parent | 4330ab26b53c0e1bf8cbb5e65704f65e3d116eba (diff) | |
| download | libgit2-bc6374eac485ab9ad9cfd7165b6d071c3dcb673a.tar.gz | |
remote: allow querying for refspecs
Introduce git_remote_{fetch,push}_refspecs() to get a list of refspecs
from the remote and rename the refspec-adding functions to a less
silly name.
Use this instead of the vector index hacks in the tests.
Diffstat (limited to 'src/remote.c')
| -rw-r--r-- | src/remote.c | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/src/remote.c b/src/remote.c index 1c4b22bb9..8b7e66e53 100644 --- a/src/remote.c +++ b/src/remote.c @@ -1467,12 +1467,60 @@ void git_remote_clear_refspecs(git_remote *remote) git_vector_clear(&remote->refspec_strings); } -int git_remote_add_fetchspec(git_remote *remote, const char *refspec) +int git_remote_add_fetch(git_remote *remote, const char *refspec) { return add_refspec(remote, refspec, true); } -int git_remote_add_pushspec(git_remote *remote, const char *refspec) +int git_remote_add_push(git_remote *remote, const char *refspec) { return add_refspec(remote, refspec, false); } + +static int copy_refspecs(git_strarray *array, git_remote *remote, int push) +{ + size_t i; + git_vector refspecs; + git_refspec *spec; + char *dup; + + if (git_vector_init(&refspecs, remote->refspecs.length, NULL) < 0) + return -1; + + git_vector_foreach(&remote->refspecs, i, spec) { + if (spec->push != push) + continue; + + dup = git__strdup(git_vector_get(&remote->refspec_strings, i)); + if (!dup) { + goto on_error; + } + + if (git_vector_insert(&refspecs, dup) < 0) { + git__free(dup); + goto on_error; + } + } + + array->strings = (char **)refspecs.contents; + array->count = refspecs.length; + + return 0; + +on_error: + git_vector_foreach(&refspecs, i, dup) + git__free(dup); + git_vector_free(&refspecs); + + return -1; +} + +int git_remote_get_fetch_refspecs(git_strarray *array, git_remote *remote) +{ + return copy_refspecs(array, remote, false); +} + +int git_remote_get_push_refspecs(git_strarray *array, git_remote *remote) +{ + return copy_refspecs(array, remote, true); +} |
