Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move checkout to CFFI and add a target directory option #390

Merged
merged 2 commits into from
Jul 11, 2014

Conversation

carlosmn
Copy link
Member

Having it at the python level should also make it easer to extend with more options in the future as needed.

# pygit2's default is SAFE_CREATE
copts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE
# and go through the arguments to see what the user wanted
for k, v in kwargs.iteritems():
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to iterate? You can do it with 2 if statements:

if 'strategy' in kwargs:
  copts.checkout_strategy = kwargs['strategy']

if 'directory' in kwargs:
  target_dir = ffi.new('char[]', to_str(kwargs['directory']))
  refs.append(target_dir)
  copts.target_directory = target_dir

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a leftover from working with less abstract constructions; but it's a guess as to how many parameters will actually be passed versus how many we will be looking at. I'm not a fan of looking up the same key twice, but it can be reduced.

Copy link
Member Author

Choose a reason for hiding this comment

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

I remember now why I wanted to iterate over the inputs instead of checking for the known keys: if the programmer using this method makes a typo, we will ignore that option instead of complaining, which can cause subtle bugs, as there is no indication that we're ignoring an argument that was passed. I didn't end up doing it as we just have the two things, but when this gets extended, we should raise an exception if we get something we don't recognise as an option.

Copy link
Member

Choose a reason for hiding this comment

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

Just changed this static method so it is shorter and fails on unexpected arguments.

As part of this, make the strategy part of **kwargs, in preparation for
supporting more options.
@jdavid jdavid merged commit 763b571 into libgit2:master Jul 11, 2014
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.

None yet

3 participants