diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-04-12 15:52:34 -0700 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-04-12 15:55:51 -0700 |
| commit | def3fef19733b8258f21799e1ff4603e75ced467 (patch) | |
| tree | cb145038b5830c33a6b7ebcf4c676ce6f1df438a /src | |
| parent | fdd0cc9e8948bb65c9a461c58e5094a3613bd975 (diff) | |
| download | libgit2-def3fef19733b8258f21799e1ff4603e75ced467.tar.gz | |
Add `git_tag_list`
Lists all the tag references in a repository using a custom callback.
Includes unit tests courtesy of Emeric Fermas <3
Diffstat (limited to 'src')
| -rw-r--r-- | src/tag.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -377,3 +377,29 @@ int git_tag__parse(git_tag *tag, git_odb_object *obj) return parse_tag_buffer(tag, obj->raw.data, (char *)obj->raw.data + obj->raw.len); } +static int tag_list_cb(const char *tag_name, void *payload) +{ + if (git__prefixcmp(tag_name, GIT_REFS_TAGS_DIR) == 0) + return git_vector_insert((git_vector *)payload, git__strdup(tag_name)); + + return GIT_SUCCESS; +} + +int git_tag_list(git_strarray *tag_names, git_repository *repo) +{ + int error; + git_vector taglist; + + if (git_vector_init(&taglist, 8, NULL) < GIT_SUCCESS) + return GIT_ENOMEM; + + error = git_reference_listcb(repo, GIT_REF_OID|GIT_REF_PACKED, &tag_list_cb, (void *)&taglist); + if (error < GIT_SUCCESS) { + git_vector_free(&taglist); + return error; + } + + tag_names->strings = (char **)taglist.contents; + tag_names->count = taglist.length; + return GIT_SUCCESS; +} |
