static int handle_grep_syntax(git_object **out, git_repository *repo, const git_oid *spec_oid, const char *pattern) { regex_t preg; git_revwalk *walk = NULL; int error; if ((error = build_regex(&preg, pattern)) < 0) return error; if ((error = git_revwalk_new(&walk, repo)) < 0) goto cleanup; git_revwalk_sorting(walk, GIT_SORT_TIME); if (spec_oid == NULL) { if ((error = git_revwalk_push_glob(walk, "refs/*")) < 0) goto cleanup; } else if ((error = git_revwalk_push(walk, spec_oid)) < 0) goto cleanup; error = walk_and_search(out, walk, &preg); cleanup: regfree(&preg); git_revwalk_free(walk); return error; }
static int handle_grep_syntax(git_object **out, git_repository *repo, const git_oid *spec_oid, const char *pattern) { regex_t preg; git_revwalk *walk = NULL; int error = -1; if (build_regex(&preg, pattern) < 0) return -1; if (git_revwalk_new(&walk, repo) < 0) goto cleanup; git_revwalk_sorting(walk, GIT_SORT_TIME); if (spec_oid == NULL) { // TODO: @carlosmn: The glob should be refs/* but this makes git_revwalk_next() fails if (git_revwalk_push_glob(walk, "refs/heads/*") < 0) goto cleanup; } else if (git_revwalk_push(walk, spec_oid) < 0) goto cleanup; error = walk_and_search(out, walk, &preg); cleanup: regfree(&preg); git_revwalk_free(walk); return error; }
void test_revwalk_basic__glob_heads(void) { int i = 0; git_oid oid; cl_git_pass(git_revwalk_push_glob(_walk, "heads")); while (git_revwalk_next(&oid, _walk) == 0) { i++; } /* git log --branches --oneline | wc -l => 14 */ cl_assert(i == 14); }
void test_revwalk_basic__glob_heads_with_invalid(void) { int i; git_oid oid; revwalk_basic_setup_walk("testrepo"); cl_git_mkfile("testrepo/.git/refs/heads/garbage", "not-a-ref"); cl_git_pass(git_revwalk_push_glob(_walk, "heads")); for (i = 0; !git_revwalk_next(&oid, _walk); ++i) /* walking */; /* git log --branches --oneline | wc -l => 16 */ cl_assert_equal_i(17, i); }
void test_revwalk_basic__push_all(void) { git_oid oid; int i = 0; revwalk_basic_setup_walk(NULL); git_revwalk_reset(_walk); git_revwalk_sorting(_walk, 0); cl_git_pass(git_revwalk_push_glob(_walk, "*")); while (git_revwalk_next(&oid, _walk) == 0) { i++; } /* git rev-list --count --all #=> 15 */ cl_assert_equal_i(15, i); }
void test_revwalk_basic__push_mixed(void) { git_oid oid; int i = 0; revwalk_basic_setup_walk(NULL); git_revwalk_reset(_walk); git_revwalk_sorting(_walk, 0); cl_git_pass(git_revwalk_push_glob(_walk, "tags")); while (git_revwalk_next(&oid, _walk) == 0) { i++; } /* git rev-list --count --glob=tags #=> 9 */ cl_assert_equal_i(9, i); }