-
Notifications
You must be signed in to change notification settings - Fork 540
Support cancellation of long-running repository operations (with context.Context) #483
Comments
@JoshuaSjoding great to having you back.
Make sense, is something that is very interesting.
Sound like a plan, are you interested on taking care of this?
This is already implemented, is dependent of the storage, but works with the built-in ones.
I opened an issue in dep a long time ago, golang/dep#424, maybe we can re-open it.
About the interface, I am not sure, maybe we can added it to the *Options structs. @smola? |
Just chiming in to say that I'm happy to reopen that issue and look at this again, once the requirements @JoshuaSjoding outlined are met 😄 |
Thank you! This project has come a long way since I last contributed; nicely done!
Yep, I would be happy to work on a PR for this.
Excellent. For storage implementations that support Transactioner we can just do a Rollback when we receive a cancellation then.
I was wondering about that as well. Adding it to Reasons to add it to
Reasons to add a
|
The proposal looks good. Some considerations about API and
|
@JoshuaSjoding I prefer not release a v5 during a long time and evolve v4 (we were making API changes during 1year) , so will be great if we can implement a very first version of the API having ctx, in all the Remote and Repository methods, where networking or long time running tasks. And then release a v4. After release the v4 we can keep working on the implementation. |
I was taking a look, and looks extremely easy add cancellation support for all the HTTP request, this looks a good starting point. @JoshuaSjoding you already started? or maybe you want me to bootstrap this? |
@mcuadros I have not started yet; by all means go ahead. I won't have time to work on this until next week. |
If you don't see any PR, in the next days, is that I couldn't do it. The only thing I want to do if I have time is make the first approach in order to be able to review the API. |
After some tests and integration, I consider "enough" implemented to close this issue. |
Right now all of the
Repository
andRemote
operations includingClone
,Fetch
,Pull
andPush
run until completion or until an error occurs. I propose adding acontext.Context
argument to each operation that could be long-running, so that these operations can be cancelled if the caller deems it necessary.Here are some circumstances that such a change would allow the caller to deal with:
go-git
causes an operation to stall and not make progressAdding a new argument to these operations is a breaking change, so this would be a
v5
feature.Adding a simple
Timeout
field toCloneOptions
,FetchOptions
,PullOptions
andPushOptions
would be insufficient. The caller may want to allow a long-running operation that is slowly making progress to continue, even though it exceeds an absolute timeout. The addition ofcontext.Context
, in combination with the existingOptions.Progress
, allows the caller to handle such cases.The superficial changes to
Repository
are not difficult, but fully implementingcontext.Context
throughout theplumbing
andinternal
packages will take some effort. I propose making these changes in an iterative process with a series of pull requests, starting with the superficial changes toRepository
and propagatingcontext.Context
throughout the library one step at a time.If a
context.Context
is cancelled,go-git
should make every effort to leavestorage.Storage
in a functional and uncorrupted state. I expect that this will be the most difficult part of these changes and require the most thought.This work is a prerequisite for using
go-git
internally in the new dep tool.Here's what the
Remote
methods would look like:Here's what the
Repository
methods would look like:The text was updated successfully, but these errors were encountered: