int git_reference_foreach_name( git_repository *repo, git_reference_foreach_name_cb callback, void *payload) { git_reference_iterator *iter; const char *refname; int error; if ((error = git_reference_iterator_new(&iter, repo)) < 0) return error; while (!(error = git_reference_next_name(&refname, iter))) { if ((error = callback(refname, payload)) != 0) { giterr_set_after_callback(error); break; } } if (error == GIT_ITEROVER) error = 0; git_reference_iterator_free(iter); return error; }
int git_reference_foreach_name( git_repository *repo, git_reference_foreach_name_cb callback, void *payload) { git_reference_iterator *iter; const char *refname; int error; if (git_reference_iterator_new(&iter, repo) < 0) return -1; while ((error = git_reference_next_name(&refname, iter)) == 0) { if (callback(refname, payload)) { error = GIT_EUSER; goto out; } } if (error == GIT_ITEROVER) error = 0; out: git_reference_iterator_free(iter); return error; }
static void *iterate_refs(void *arg) { struct th_data *data = (struct th_data *) arg; git_reference_iterator *i; git_reference *ref; int count = 0, error; git_repository *repo; cl_git_thread_pass(data, git_repository_open(&repo, data->path)); do { error = git_reference_iterator_new(&i, repo); } while (error == GIT_ELOCKED); cl_git_thread_pass(data, error); for (count = 0; !git_reference_next(&ref, i); ++count) { cl_assert(ref != NULL); git_reference_free(ref); } if (g_expected > 0) cl_assert_equal_i(g_expected, count); git_reference_iterator_free(i); git_repository_free(repo); git_error_clear(); return arg; }
// normal from glob and just names int luagi_reference_iterator( lua_State *L ) { git_repository **repo = checkrepo( L, 1 ); const char *glob = luaL_optstring( L, 2, NULL ); git_reference_iterator **iter = lua_newuserdata( L, sizeof( git_reference_iterator * ) ); int ret = 0; if( glob == NULL ) { ret = git_reference_iterator_new( iter, *repo ); } else { ret = git_reference_iterator_glob_new ( iter, *repo, glob ); } if( ret ) { ltk_error_abort( L ); return 0; } luaL_getmetatable(L, LUAGI_REFERENCE_ITER_FUNCS); lua_setmetatable(L, -2); lua_pushcclosure( L, reference_iter, 1 ); return 1; }
int git_branch_foreach( git_repository *repo, unsigned int list_flags, git_branch_foreach_cb callback, void *payload) { git_reference_iterator *iter; git_reference *ref; int error = 0; if (git_reference_iterator_new(&iter, repo) < 0) return -1; while ((error = git_reference_next(&ref, iter)) == 0) { if (list_flags & GIT_BRANCH_LOCAL && git__prefixcmp(ref->name, GIT_REFS_HEADS_DIR) == 0) { if (callback(ref->name + strlen(GIT_REFS_HEADS_DIR), GIT_BRANCH_LOCAL, payload)) { error = GIT_EUSER; } } if (list_flags & GIT_BRANCH_REMOTE && git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR) == 0) { if (callback(ref->name + strlen(GIT_REFS_REMOTES_DIR), GIT_BRANCH_REMOTE, payload)) { error = GIT_EUSER; } } git_reference_free(ref); /* check if the callback has cancelled iteration */ if (error == GIT_EUSER) break; } if (error == GIT_ITEROVER) error = 0; git_reference_iterator_free(iter); return error; }
int git_branch_iterator_new( git_branch_iterator **out, git_repository *repo, git_branch_t list_flags) { branch_iter *iter; iter = git__calloc(1, sizeof(branch_iter)); GITERR_CHECK_ALLOC(iter); iter->flags = list_flags; if (git_reference_iterator_new(&iter->iter, repo) < 0) { git__free(iter); return -1; } *out = (git_branch_iterator *) iter; return 0; }
static void *iterate_refs(void *arg) { git_reference_iterator *i; git_reference *ref; int count = 0; cl_git_pass(git_reference_iterator_new(&i, g_repo)); for (count = 0; !git_reference_next(&ref, i); ++count) { cl_assert(ref != NULL); git_reference_free(ref); } if (g_expected > 0) cl_assert_equal_i(g_expected, count); git_reference_iterator_free(i); giterr_clear(); return arg; }