Commit 0836f069 by Eivind Fonn

revwalk: Allow changing hide_cb

Since git_revwalk objects are encouraged to be reused, a public
interface for changing hide_cb is desirable.
parent 9189a66a
......@@ -279,7 +279,7 @@ typedef int(*git_revwalk_hide_cb)(
void *payload);
/**
* Adds a callback function to hide a commit and its parents
* Adds, changes or removes a callback function to hide a commit and its parents
*
* @param walk the revision walker
* @param hide_cb callback function to hide a commit and its parents
......
......@@ -756,15 +756,11 @@ int git_revwalk_add_hide_cb(
if (walk->walking)
git_revwalk_reset(walk);
if (walk->hide_cb) {
/* There is already a callback added */
giterr_set(GITERR_INVALID, "there is already a callback added to hide commits in revwalk");
return -1;
}
walk->hide_cb = hide_cb;
walk->hide_cb_payload = payload;
walk->limited = 1;
if (hide_cb)
walk->limited = 1;
return 0;
}
......
......@@ -117,13 +117,40 @@ void test_revwalk_hidecb__hide_none_cb(void)
git_revwalk_free(walk);
}
void test_revwalk_hidecb__add_hide_cb_multiple_times(void)
void test_revwalk_hidecb__unset_cb_before_walk(void)
{
git_revwalk *walk;
git_oid id;
int i, error;
cl_git_pass(git_revwalk_new(&walk, _repo));
cl_git_pass(git_revwalk_add_hide_cb(walk, hide_every_commit_cb, NULL));
cl_git_pass(git_revwalk_add_hide_cb(walk, NULL, NULL));
cl_git_pass(git_revwalk_push(walk, &_head_id));
/* It should return all 6 commits */
i = 0;
while ((error = git_revwalk_next(&id, walk)) == 0)
i++;
cl_assert_equal_i(i, 6);
cl_assert_equal_i(error, GIT_ITEROVER);
git_revwalk_free(walk);
}
void test_revwalk_hidecb__change_cb_before_walk(void)
{
git_revwalk *walk;
git_oid id;
cl_git_pass(git_revwalk_new(&walk, _repo));
cl_git_pass(git_revwalk_add_hide_cb(walk, hide_none_cb, NULL));
cl_git_pass(git_revwalk_add_hide_cb(walk, hide_every_commit_cb, NULL));
cl_git_fail(git_revwalk_add_hide_cb(walk, hide_every_commit_cb, NULL));
cl_git_pass(git_revwalk_push(walk, &_head_id));
/* First call to git_revwalk_next should return GIT_ITEROVER */
cl_assert_equal_i(GIT_ITEROVER, git_revwalk_next(&id, walk));
git_revwalk_free(walk);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment