Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

tiennou
Copy link
Contributor

@tiennou tiennou commented Apr 29, 2019

This is #5056, in 3 commits:

  • add a helper to upgrade options structures if needed
  • update the git_remote_callback users to the autoupgrader
  • add a callback to git_remote_callbacks to change the URL before the connection is made.

@tiennou tiennou force-pushed the fix/ssh-url-substitution branch 2 times, most recently from b8e1b76 to bcac837 Compare April 30, 2019 11:58
@tiennou tiennou force-pushed the fix/ssh-url-substitution branch from bcac837 to f154cd3 Compare May 1, 2019 13:06
@tiennou
Copy link
Contributor Author

tiennou commented May 1, 2019

Rebased, with the unneeded ➰ allocator removed. Most of the code from #5056 has thus been restored.

If that's even possible, it would be nice to have this one in quickly: any new contribution that touches one of our structs is going to have to do something like this (and some are pesky). The sooner this happens, the easier it gets for contributors. Maybe. That's how I felt when I noticed the change in #5056.

I've tried to take into account some of the ideas from the other backward-compatibility PR (git_refdb_backend?), but this one is simpler, thus I don't think it's sufficient I'll try to revisit the other one, though, in case it's not). It's missing documentation which I'd like to add before this goes in, but a first review round seemed like a good idea.

@tiennou tiennou changed the title remote: add callback to resolve URLs before connecting Option struct updater & remote URL last-chance resolution May 1, 2019
@ethomson
Copy link
Member

ethomson commented May 1, 2019

I don't understand why you're incrementing the struct version here? You're adding a field, that's not an API breaking change?

*
* You need to be careful not to overflow url_resolved. If it's too small,
* returning a positive value equal to the size required will cause the
* resolution to be tried again with a buffer of the requested size.
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment accurate? I don't see this behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, a leftover from the old way, before I re-read buffer.h. Please disregard.

@tiennou
Copy link
Contributor Author

tiennou commented May 1, 2019

It's binary-breaking because if I get a old v1 struct without the member and try to access it as a new, we'll read some stack data. Hence the bump. I don't think there's a way around, is it?

@ethomson
Copy link
Member

ethomson commented May 1, 2019

Yes, this breaks ABI but not API. We've never tried to be ABI-consistent.

It's a noble goal that we should pursue but let's drop those two commits for now and get this merged so we can 🚢. We do need a strategy for coping with API breaking struct changes, which it seems like this aligns to as well. So let's split those two commits out into a new PR. I suspect that there's going to be a few subtle nuances to struct compatibility that we should spend some time to 🤔 about.

@tiennou tiennou force-pushed the fix/ssh-url-substitution branch from f154cd3 to 12d9940 Compare May 1, 2019 17:50
@tiennou tiennou changed the title Option struct updater & remote URL last-chance resolution Remote URL last-chance resolution May 1, 2019
@tiennou
Copy link
Contributor Author

tiennou commented May 1, 2019

Rebased, I've removed the updater and will refile as needed.

@tiennou tiennou force-pushed the fix/ssh-url-substitution branch from 12d9940 to c7bcb8b Compare May 2, 2019 09:30
@tiennou tiennou force-pushed the fix/ssh-url-substitution branch from c7bcb8b to 33e42d4 Compare May 2, 2019 11:01
* Resolve URL before connecting to remote.
* The returned URL will be used to connect to the remote instead.
*/
git_resolve_url_cb resolve_url;
Copy link
Member

Choose a reason for hiding this comment

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

I'd like this to be git_url_resolve_cb, since that sounds more like something that acts on (resolves) an object (url) instead of something that urls a resolve.

I'm otherwise 👍 on this, so I'm happy to make this change and merge it though to get this unblocked if you're busy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it sounds weird in any order, so I renamed. A few weeks later, I have the feeling it could be provided as some kind of "proxying" internal transport, but maybe that's too much (that would make this use case go through the already existing custom transport callback just above this one).

@tiennou tiennou force-pushed the fix/ssh-url-substitution branch from 33e42d4 to daa7883 Compare May 20, 2019 08:19
Copy link
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.

I'm happy with this PR, thanks! @ethomson, you good with this, too?

GIT_UNUSED(url_resolved);
GIT_UNUSED(url);
GIT_UNUSED(direction);
GIT_UNUSED(payload);
Copy link
Member

Choose a reason for hiding this comment

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

Sometimes I wish we'd be allowed to use variadic macros. Would make such unused blocks at least a tad less awful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've recently learnt that there's an __attribute__((unused)) that does the same thing, also available as __unused (for nicer declarations). These can go on parameters, and GCC and Clang looks to be fine with it. Just my 2¢.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I've used them in my own projects, too. I'm not sure whether I like those more, though.

@eaigner
Copy link

eaigner commented May 21, 2019

ping. merge?

@ethomson
Copy link
Member

Yep, this looks good to me. @tiennou can you remove that unused assignment to status and we can 🚢

@tiennou tiennou force-pushed the fix/ssh-url-substitution branch from daa7883 to f7d646a Compare May 21, 2019 11:31
Since libssh2 doesn't read host configuration from the config file,
this callback can be used to hand over URL resolving to the client
without touching the SSH implementation itself.
@tiennou tiennou force-pushed the fix/ssh-url-substitution branch from f7d646a to 59647e1 Compare May 21, 2019 12:11
@ethomson ethomson merged commit 954f535 into libgit2:master May 21, 2019
@ethomson
Copy link
Member

Thanks @eaigner and @tiennou!

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.

4 participants