Skip to content

Provide a convenience function git_remote_push() - #2608

Merged
ethomson merged 3 commits into
masterfrom
cmn/remote-push
Nov 18, 2014
Merged

Provide a convenience function git_remote_push()#2608
ethomson merged 3 commits into
masterfrom
cmn/remote-push

Conversation

@carlosmn

Copy link
Copy Markdown
Member

This function takes all the steps necessary to perform a push and does them for you. This is also an opportunity to provide a single callback structure instead of them being spread out between the structure and two different functions on the push object.

AFAICT basically all the bindings already provide this function themselves, so let's have an implementation in libgit2 directly.

@arthurschreiber

Copy link
Copy Markdown
Member

👍

Comment thread include/git2/remote.h Outdated

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.

Is refspecs optional here? Because I'd expect to be able to pass no refspecs here and use the default push specs as set in the config for a remote. That's how it works in the current Remote#push implementation. I know that by default, no push spec is set up, but I'd still like this to mirror the behavior of git_remote_fetch.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's not optional, but if you pass in an empty one, then nothing will be added to the push object. I'll need to check more closely what the different behaviours are, and which of the git behaviours makes more sense here.

@carlosmn
carlosmn force-pushed the cmn/remote-push branch 5 times, most recently from a3678fc to 099bbcb Compare October 11, 2014 11:36
@carlosmn

Copy link
Copy Markdown
Member Author

I've kept a no-op as valid (that is, not passing any refspecs and a remote not having any configured), since there's already a test that wants the git_push version to do that.

I'm not sure whether return an error in that case would make more sense or not, tbh.

@arthurschreiber

Copy link
Copy Markdown
Member

@carlosmn Returning an error would be fine - same for git_remote_fetch. That's what the git CLI is doing, too. I know that the requirements behind the git CLI and libgit2 might be quite different, but I think in this case reflecting the CLI would be ok.

@arthurschreiber

Copy link
Copy Markdown
Member

See libgit2/rugged@d32647a63b1b^...9a5f1c9 for the rugged bindings for this. Allowed me to delete quite a bit of the old Remote#push code.

@nulltoken

Copy link
Copy Markdown
Member

/cc @jamill should we shamelessly steal get some inspiration from this? ^^

@jamill

jamill commented Oct 13, 2014

Copy link
Copy Markdown
Member

/cc @jamill should we shamelessly steal get some inspiration from this? ^^

Sounds goo - I would be for pushing more logic down into lg2. As we move forward, it seems the direction is to put more of these convenience functions into lg2? For instance, would a convenience function for Pull be another candidate to put into lg2 at some point as well?

@swisspol

swisspol commented Nov 1, 2014

Copy link
Copy Markdown
Contributor

Are the new callbacks also called if you use directly the low-level push APIs?

@carlosmn

carlosmn commented Nov 2, 2014

Copy link
Copy Markdown
Member Author

New callbacks? Do you mean the copy that's in the git_remote_callbacks structure? Not atm, but I suppose we could make them default to whatever is in the remote when they're created.

@swisspol

swisspol commented Nov 2, 2014

Copy link
Copy Markdown
Contributor

I mean that with the current git_remote implementation, update_tips is called both when fetching and pushing but sideband_progress and transfer_progress only appear to be called when fetching. Why is this the case anyway?

I noticed in this PR that you are adding 3 new callbacks: pack_progress, push_transfer_progress and push_update_reference and I was wondering if these would be called to report progress when using the lower-level git_push_... APIs vs the new git_remote_push() one.

@carlosmn

carlosmn commented Nov 2, 2014

Copy link
Copy Markdown
Member Author

sideband_progress and transfer_progress only appear to be called when fetching. Why is this the case anyway?

Because they're only relevant for fetching. We only receive data and messages from the server when we fetch.

I noticed in this PR that you are adding 3 new callbacks: pack_progress, push_transfer_progress and push_update_reference

Those are the copies. The last one is simply what you set for git_remote_push() to know what to give to the push object as a callback for update_tips.

There is nothing new here, it's just wrapping the existing code inside a single function to have an equivalent api to fetch.

@swisspol

swisspol commented Nov 2, 2014

Copy link
Copy Markdown
Contributor

Because they're only relevant for fetching. We only receive data and messages from the server when we fetch.

But when I do git push from the command line, it does show progress and packing information?

@carlosmn

carlosmn commented Nov 2, 2014

Copy link
Copy Markdown
Member Author

None of that information comes from the server. The client is the one packing and transferring, which is why the push object has these two callbacks to give you this information.

@swisspol

swisspol commented Nov 2, 2014

Copy link
Copy Markdown
Contributor

Ah sorry I missed there was a separate set of callbacks on the push object!

@carlosmn carlosmn added this to the libgit2 v0.22 milestone Nov 7, 2014
This function, similar in style to git_remote_fetch(), performs all the
steps required for a push, with a similar interface.

The remote callbacks struct has learnt about the push callbacks, letting
us set the callbacks a single time instead of setting some in the remote
and some in the push operation.
We have the step-by-step method in the initialization function as we
want to remove references based on the list of references which are
already there, and we can use the convenience function for testing the
main push.
If the user does not pass any refspecs to push, try to use those
configured via the configuration or via add_push().
@carlosmn

Copy link
Copy Markdown
Member Author

@jamill for things were you want to do the same simple thing 90% of the time, a lot of logic can go into libgit2. Pull is something I'm still not eager to get into the library since it's a very overloaded concept. Maybe something with a better name that won't make people think it's the git-pull.sh script, thought that likely would need its own thread of discussion.

ethomson added a commit that referenced this pull request Nov 18, 2014
Provide a convenience function `git_remote_push()`
@ethomson
ethomson merged commit 45301cc into master Nov 18, 2014
@carlosmn carlosmn mentioned this pull request Nov 18, 2014
@carlosmn
carlosmn deleted the cmn/remote-push branch November 21, 2014 18:20
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.

6 participants