Skip to content

revwalk: Allow changing hide_cb#4888

Merged
pks-t merged 1 commit intolibgit2:masterfrom
TheBB:add-cb
Nov 29, 2018
Merged

revwalk: Allow changing hide_cb#4888
pks-t merged 1 commit intolibgit2:masterfrom
TheBB:add-cb

Conversation

@TheBB
Copy link
Copy Markdown
Contributor

@TheBB TheBB commented Nov 14, 2018

Remove the check for existing hide_cb and conditionally set the limited flag.

Fixes #4887

@neithernut
Copy link
Copy Markdown
Contributor

You may also want to test for git_revwalk_add_hide_cb(walk, NULL, NULL).

@TheBB
Copy link
Copy Markdown
Contributor Author

TheBB commented Nov 14, 2018

Sure, added a test for it.

Comment thread tests/revwalk/hidecb.c
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_add_hide_cb(walk, hide_every_commit_cb, NULL));
cl_git_pass(git_revwalk_add_hide_cb(walk, NULL, NULL));
Copy link
Copy Markdown
Contributor

@neithernut neithernut Nov 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. But you don't verify that the revwalk actually works (e.g. by calling git_revwalk_next()) for this special case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, gotcha. Updated again.

Copy link
Copy Markdown
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your pull request! Two small things that require change, but otherwise this looks good to me.

Comment thread src/revwalk.c
walk->limited = 1;

if (hide_cb)
walk->limited = 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh. We don't zero out the struct members, so you'd probably also have to unlimit the revwalk in case there is no hide_cb. So:

walk_limited = !!hide_cb;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure about that, the limited flag is set in a few other places, for example in git_revwalk_sorting. There, like here, it's only ever set, never unset. I can't find anywhere that explains what it means precisely, so if you say that's correct I'll believe you.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, you're right. I somehow mistook this change for applying to git_revwalk_reset, but we obviously already set the flag to 0 there. So yeah, your change is indeed perfectly fine: If we didn't limit the revwalk previous to unsetting the hide callback, then we know that we do not put an additional limit to the revwalk. Otherwise, we do.

Comment thread tests/revwalk/hidecb.c
Since git_revwalk objects are encouraged to be reused, a public
interface for changing hide_cb is desirable.
@pks-t
Copy link
Copy Markdown
Member

pks-t commented Nov 29, 2018

/rebuild

@libgit2-azure-pipelines
Copy link
Copy Markdown

Okay, @pks-t, I started to rebuild this pull request.

@pks-t pks-t merged commit e7873eb into libgit2:master Nov 29, 2018
@pks-t
Copy link
Copy Markdown
Member

pks-t commented Nov 29, 2018

Thanks a lot for this change, @TheBB!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants