Skip to content

Commit 892aa80

Browse files
committed
Callback to hide commits in revision walker.
1 parent f57cc63 commit 892aa80

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

include/git2/revwalk.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,30 @@ GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk);
261261
*/
262262
GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk);
263263

264+
/**
265+
* This is a callback function that user can provide to hide a
266+
* commit and its parents. If the callback function returns true,
267+
* then this commit and its parents will be hidden.
268+
*
269+
* @param commit_id oid of Commit
270+
* @param payload User-specified pointer to data to be passed as data payload
271+
*/
272+
typedef int(*git_revwalk_hide_cb)(
273+
const git_oid *commit_id,
274+
void *payload);
275+
276+
/**
277+
* Adds a callback function to hide a commit
278+
*
279+
* @param walk the revision walker
280+
* @param hide_cb callback function to hide a commit and its parents
281+
* @param payload data payload to be passed to callback function
282+
*/
283+
GIT_EXTERN(int) git_revwalk_add_hide_cb(
284+
git_revwalk *walk,
285+
git_revwalk_hide_cb hide_cb,
286+
void *payload);
287+
264288
/** @} */
265289
GIT_END_DECL
266290
#endif

src/revwalk.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ static int process_commit(git_revwalk *walk, git_commit_list_node *commit, int h
8181
{
8282
int error;
8383

84+
if (!hide && walk->hide_cb)
85+
{
86+
hide = walk->hide_cb(&commit->oid, walk->hide_cb_payload);
87+
}
88+
8489
if (hide && mark_uninteresting(commit) < 0)
8590
return -1;
8691

@@ -575,3 +580,26 @@ void git_revwalk_reset(git_revwalk *walk)
575580
git_vector_clear(&walk->twos);
576581
}
577582

583+
int git_revwalk_add_hide_cb(
584+
git_revwalk *walk,
585+
git_revwalk_hide_cb hide_cb,
586+
void *payload)
587+
{
588+
assert(walk);
589+
590+
if (walk->walking)
591+
git_revwalk_reset(walk);
592+
593+
if (walk->hide_cb)
594+
{
595+
/* There is already a callback added */
596+
giterr_set(GITERR_INVALID, "There is already a callback added to hide commits in revision walker.");
597+
return -1;
598+
}
599+
600+
walk->hide_cb = hide_cb;
601+
walk->hide_cb_payload = payload;
602+
603+
return 0;
604+
}
605+

src/revwalk.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ struct git_revwalk {
3939
/* merge base calculation */
4040
git_commit_list_node *one;
4141
git_vector twos;
42+
43+
/* hide callback */
44+
git_revwalk_hide_cb hide_cb;
45+
void *hide_cb_payload;
4246
};
4347

4448
git_commit_list_node *git_revwalk__commit_lookup(git_revwalk *walk, const git_oid *oid);

0 commit comments

Comments
 (0)