Commit 892aa808 by Anurag Gupta

Callback to hide commits in revision walker.

parent f57cc638
......@@ -261,6 +261,30 @@ GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk);
*/
GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk);
/**
* This is a callback function that user can provide to hide a
* commit and its parents. If the callback function returns true,
* then this commit and its parents will be hidden.
*
* @param commit_id oid of Commit
* @param payload User-specified pointer to data to be passed as data payload
*/
typedef int(*git_revwalk_hide_cb)(
const git_oid *commit_id,
void *payload);
/**
* Adds a callback function to hide a commit
*
* @param walk the revision walker
* @param hide_cb callback function to hide a commit and its parents
* @param payload data payload to be passed to callback function
*/
GIT_EXTERN(int) git_revwalk_add_hide_cb(
git_revwalk *walk,
git_revwalk_hide_cb hide_cb,
void *payload);
/** @} */
GIT_END_DECL
#endif
......@@ -81,6 +81,11 @@ static int process_commit(git_revwalk *walk, git_commit_list_node *commit, int h
{
int error;
if (!hide && walk->hide_cb)
{
hide = walk->hide_cb(&commit->oid, walk->hide_cb_payload);
}
if (hide && mark_uninteresting(commit) < 0)
return -1;
......@@ -575,3 +580,26 @@ void git_revwalk_reset(git_revwalk *walk)
git_vector_clear(&walk->twos);
}
int git_revwalk_add_hide_cb(
git_revwalk *walk,
git_revwalk_hide_cb hide_cb,
void *payload)
{
assert(walk);
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 revision walker.");
return -1;
}
walk->hide_cb = hide_cb;
walk->hide_cb_payload = payload;
return 0;
}
......@@ -39,6 +39,10 @@ struct git_revwalk {
/* merge base calculation */
git_commit_list_node *one;
git_vector twos;
/* hide callback */
git_revwalk_hide_cb hide_cb;
void *hide_cb_payload;
};
git_commit_list_node *git_revwalk__commit_lookup(git_revwalk *walk, const git_oid *oid);
......
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