emacs_value egit_tag_list(emacs_env *env, emacs_value _repo, emacs_value _pattern) { EGIT_ASSERT_REPOSITORY(_repo); EM_ASSERT_STRING_OR_NIL(_pattern); git_repository *repo = EGIT_EXTRACT(_repo); char *pattern = EM_EXTRACT_STRING_OR_NULL(_pattern); git_strarray out = {NULL, 0}; int retval = pattern ? git_tag_list_match(&out, pattern, repo) : git_tag_list(&out, repo); free(pattern); EGIT_CHECK_ERROR(retval); EGIT_RET_STRARRAY(out); }
static void action_list_tags(tag_state *state) { const char *pattern = state->opts->pattern; git_strarray tag_names = {0}; size_t i; check_lg2(git_tag_list_match(&tag_names, pattern ? pattern : "*", state->repo), "Unable to get list of tags", NULL); for(i = 0; i < tag_names.count; i++) { each_tag(tag_names.strings[i], state); } git_strarray_free(&tag_names); }
// Helpers static void ensure_tag_pattern_match(git_repository *repo, const char *pattern, const size_t expected_matches) { git_strarray tag_list; int error = 0; if ((error = git_tag_list_match(&tag_list, pattern, repo)) < 0) goto exit; if (tag_list.count != expected_matches) error = GIT_ERROR; exit: git_strarray_free(&tag_list); cl_git_pass(error); }
static VALUE each_tag(int argc, VALUE *argv, VALUE self, int tag_names_only) { git_repository *repo; git_strarray tags; size_t i; int error, exception = 0; VALUE rb_repo = rugged_owner(self), rb_pattern; const char *pattern = NULL; rb_scan_args(argc, argv, "01", &rb_pattern); if (!rb_block_given_p()) { VALUE symbol = tag_names_only ? CSTR2SYM("each_name") : CSTR2SYM("each"); return rb_funcall(self, rb_intern("to_enum"), 2, symbol, rb_pattern); } if (!NIL_P(rb_pattern)) { Check_Type(rb_pattern, T_STRING); pattern = StringValueCStr(rb_pattern); } rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); error = git_tag_list_match(&tags, pattern ? pattern : "", repo); rugged_exception_check(error); if (tag_names_only) { for (i = 0; !exception && i < tags.count; ++i) rb_protect(rb_yield, rb_str_new_utf8(tags.strings[i]), &exception); } else { for (i = 0; !exception && i < tags.count; ++i) { rb_protect(rb_yield, rb_git_tag_collection_aref(self, rb_str_new_utf8(tags.strings[i])), &exception); } } git_strarray_free(&tags); if (exception) rb_jump_tag(exception); return Qnil; }
// Helpers static void ensure_tag_pattern_match(git_repository *repo, const struct pattern_match_t* data) { int already_found[MAX_USED_TAGS] = { 0 }; git_strarray tag_list; int error = 0; size_t sucessfully_found = 0; size_t i, j; cl_assert(data->expected_matches <= MAX_USED_TAGS); if ((error = git_tag_list_match(&tag_list, data->pattern, repo)) < 0) goto exit; if (tag_list.count != data->expected_matches) { error = GIT_ERROR; goto exit; } // we have to be prepared that tags come in any order. for (i = 0; i < tag_list.count; i++) { for (j = 0; j < data->expected_matches; j++) { if (!already_found[j] && !strcmp(data->expected_results[j], tag_list.strings[i])) { already_found[j] = 1; sucessfully_found++; break; } } } cl_assert_equal_i((int)sucessfully_found, (int)data->expected_matches); exit: git_strarray_free(&tag_list); cl_git_pass(error); }
int git_tag_list(git_strarray *tag_names, git_repository *repo) { return git_tag_list_match(tag_names, "", repo); }