-
Notifications
You must be signed in to change notification settings - Fork 413
Please support discovering repositories using the standard git environment variables #123
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
Conversation
Sounds like a good idea to me! I'm not actually sure how one detects when you cross filesystems, but respecting ceiling directories seems reasonable |
@alexcrichton You can detect if you've crossed filesystems by calling git2-rs doesn't need any special handling here; it just needs to provide a way to access that functionality in libgit2, and (when libgit2/libgit2#3711 goes in) provide |
Oh sorry I may have misunderstood, is there an API we're not binding that exists today? |
@alexcrichton Yes: Also, as noted in I'd suggest adding a new API Separate from that, after libgit2/libgit2#3711 gets merged into libgit2, I'd suggest adding a (I'm not bothered by |
Gah I knew I shouldn't have defaulted those APIs at the time... But yeah if |
I'll send a pull request for both items, as soon as I finish with the libgit2 changes. |
Thanks! |
A question on the binding for Any suggestions for a binding that won't require a typecast for the most common kind of call? At the moment, the only idea I've come up with involves having two separate functions, one taking no argument and one taking an |
Hm... How often would the API be called with |
@alexcrichton Far more often than it'll be called with Some. Calling the underlying function with NULL will be the common case. |
Hm did you mean to say that it'd be more often called with None? I'd actually expect that if this is a "power user" API you'd probably only reach for it if you had the extra info to pass? Or maybe this is a more ergonomic API for other situations? |
Yes. You asked how often the API would be called with
Not in this case. This is a function to autodetect all the right parameters from environment variables, and the parameter is for if you want to explicitly specify a repository path (overriding |
Oh oops I didn't see the word "than" so I misinterpreted, sorry about that! Hm so alternatively, if it's possible, we could perhaps switch this all to being a builder anyway. I'm not sure if all the various open-a-repository methods could be consolidated into one builder, but that'd at least solve this problem perhaps? |
Might be workable, though it'd take some careful design to make sure it always had a call it could map onto; the calls in libgit2 are somewhat orthogonal, and don't go strictly from less general to more general. I like the idea though. See https://internals.rust-lang.org/t/default-types-for-generics-to-improve-type-inference/3336 for another alternative: |
Hm seems odd that there's no "truly general" API to call here, I figured everything would be a shim around one another... Maybe something could be exposed or added to upstream libgit2 though? |
After some iteration, libgit2 now supports a To use this implementation, the caller will normally want to call Given that, I'm inclined to add the two new flags, leave |
I just turned this into a pull request, adding the two new flags and the new |
It looks like updating libgit2-sys to use current libgit2 from Git breaks several tests in the test suite, unrelated to this change. That'll need fixing before this can go in. |
/// variables. This acts like `open_ext` with the | ||
/// `REPOSITORY_OPEN_FROM_ENV` flag, but additionally respects `$GIT_DIR`. | ||
/// With `$GIT_DIR` unset, this will search for a repository starting in | ||
/// the current directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this elaborate a bit on what "respecting git environment variables" means in the documentation as well? It's not entirely obvious to me at first glance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can elaborate a bit. I'd rather not duplicate the entire libgit2 documentation for this, though.
(Not least of which because git2-rs uses a different license than libgit2, so I can't just copy/paste from libgit2. Though I suppose I could in this case, since I wrote the documentation in question. :) But in the general case, that doesn't work.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that quite a few docs are copy/pasted from libgit2 (I think it's good to be exhaustive here as not everyone will jump to libgit2 docs), but if there's license shenanigans that should likely be mentioned in the README or something like that.
Looks good to me, thanks! This may have to do with the fact that some of the FFI definitions have broken as evidenced by the systest suite I believe (bottom of the travis logs). If it gets too hard trying to fix I can also help out as well to get this landed. |
Update libgit2 to a version with support for these flags.
…_open_ext Repository::open_ext can't fully support the GIT_REPOSITORY_OPEN_FROM_ENV flag of git_repository_open_ext, because it doesn't allow passing a NULL path. Add a new binding Repository::open_from_env to handle this case. This also makes the common case (opening a repository exactly as git would) much simpler.
Updated for current libgit2. |
Oh dear sorry I forgot about this! |
Not a problem; this PR needed updating before merging anyway. Thanks for doing the work to update the version of libgit2! |
git::Repository::discover
passes specific default arguments to the underlyinggit_repository_discover
function, which prevents respecting$GIT_DISCOVERY_ACROSS_FILESYSTEM
or$GIT_CEILING_DIRECTORIES
. Please consider providing a binding that allows passing these values explicitly (as a bool and a &str), and please consider making the default binding respect the default values.In addition, please also consider providing a function
discover_default
or similar, which doesn't take a path parameter, and which defaults to$GIT_DIR
(or "." if that doesn't exist).Also see libgit2/libgit2#3711 in libgit2, which requests a new underlying C API for that case. However, it should be easy for git2-rs to support this with or without the underlying function.