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

Add binding for git_repository_open_ext #126

Merged
merged 2 commits into from
Apr 3, 2016
Merged

Add binding for git_repository_open_ext #126

merged 2 commits into from
Apr 3, 2016

Conversation

joshtriplett
Copy link
Member

This addresses part of #123.

@joshtriplett
Copy link
Member Author

I intentionally didn't include the version bumps for libgit2-sys or git2 in this pull request, because I think it makes sense to wait until libgit2/libgit2#3711 and then the rest of #123 get merged, and then bump both to 0.5.0 given the new APIs.

/// Find and open a repository, with additional options.
pub fn open_ext<P: AsRef<Path>>(path: P,
flags: RepositoryOpenFlags,
ceiling_dirs: Option<&str>)
Copy link
Member

Choose a reason for hiding this comment

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

I believe that this is actually a naturally-separated list of directories, so perhaps this could be an iterator of T: AsRef<OsStr>? I think there's some other APIs for consuming an iterator like that elsewhere as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's iter2cstrs, but that just constructs a git_strarray. git_repository_open_ext takes a single string of paths separated by GIT_PATH_LIST_SEPARATOR.

Also, if the caller already has this parameter in the form libgit2 expects, it seems unfortunate to have to split it just to have git2-rs re-join it.

I think it makes more sense for the caller to call std::env::join_paths themselves, rather than having open_ext do it for them; that way, if you already have a pre-joined path in the form you'd get it from $GIT_CEILING_DIRECTORIES, you can just pass that.

@alexcrichton
Copy link
Member

That all sounds good to me, thanks @joshtriplett!

@joshtriplett
Copy link
Member Author

I expanded the documentation for git::Repository::open_ext, including documentation for all the flags, documentation for ceiling_dirs, and a reference to std::env for function to construct a path list for ceiling_dirs.

/// list separator) that the search through parent directories will stop
/// before entering. Use the functions in std::env to construct or
/// manipulate such a path list.
pub fn open_ext<P: AsRef<Path>>(path: P,
Copy link
Member

Choose a reason for hiding this comment

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

I actually tend to use the bound IntoCString in this repo nad that should help elide the .as_ref() below as well

Copy link
Member Author

Choose a reason for hiding this comment

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

For the path? Sure, I can do that. I'd modeled this after other functions in git::Repository, which also took AsRef<Path>, but IntoCString seems easy enough to switch to.

Copy link
Member

Choose a reason for hiding this comment

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

Oh weird, I should probably change those to IntoCString at some point. In that case feel free to leave this :)

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, will do.

@joshtriplett
Copy link
Member Author

OK, the version I just pushed uses an IntoIterator, where the Item is an AsRef<OsStr>.

I didn't manage to get an IntoIterator over IntoCString to work (specifically, the conversion to the types join_paths wanted). Please feel free to generalize if you'd like.

I also find it unfortunate that, in the common case of not passing ceiling_dirs, I still had to say &[] as &[&OsStr], because &[] didn't provide enough information for type inference to work.

@alexcrichton
Copy link
Member

Oh yeah AsRef<OsStr> is fine if we're calling join_paths. That is pretty unfortunate about calling this with an empty slice, but in theory that won't happen most of the time as this is just a "power user" function over one of the more ergonomic variants?

Gonna go ahead and merge for now, thanks @joshtriplett!

@alexcrichton alexcrichton reopened this Apr 3, 2016
@alexcrichton alexcrichton merged commit 8fbe14b into rust-lang:master Apr 3, 2016
@alexcrichton
Copy link
Member

oops

@joshtriplett joshtriplett deleted the git_repository_open_ext branch April 25, 2016 02:13
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.

2 participants