diff options
author | Marc Barussaud <marc.barussaud@orange.com> | 2018-06-26 15:23:19 +0200 |
---|---|---|
committer | Santiago M. Mola <santi@mola.io> | 2018-07-02 15:11:59 +0200 |
commit | 9251ea764df3de13518f974635e76315b2b89e3e (patch) | |
tree | 9db44a52be37dd58e21b97861a9b3e1683449b24 /plumbing/object/change.go | |
parent | 662e2c226e9b8352a90cd1951233fab30a4e5042 (diff) | |
download | go-git-9251ea764df3de13518f974635e76315b2b89e3e.tar.gz |
plumbing: add context to allow cancel on diff/patch computing
Signed-off-by: Marc Barussaud <marc.barussaud@orange.com>
Diffstat (limited to 'plumbing/object/change.go')
-rw-r--r-- | plumbing/object/change.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/plumbing/object/change.go b/plumbing/object/change.go index 729ff5a..a1b4c27 100644 --- a/plumbing/object/change.go +++ b/plumbing/object/change.go @@ -2,6 +2,7 @@ package object import ( "bytes" + "context" "fmt" "strings" @@ -81,7 +82,15 @@ func (c *Change) String() string { // Patch returns a Patch with all the file changes in chunks. This // representation can be used to create several diff outputs. func (c *Change) Patch() (*Patch, error) { - return getPatch("", c) + return c.PatchContext(context.Background()) +} + +// Patch returns a Patch with all the file changes in chunks. This +// representation can be used to create several diff outputs. +// If context expires, an non-nil error will be returned +// Provided context must be non-nil +func (c *Change) PatchContext(ctx context.Context) (*Patch, error) { + return getPatchContext(ctx, "", c) } func (c *Change) name() string { @@ -136,5 +145,13 @@ func (c Changes) String() string { // Patch returns a Patch with all the changes in chunks. This // representation can be used to create several diff outputs. func (c Changes) Patch() (*Patch, error) { - return getPatch("", c...) + return c.PatchContext(context.Background()) +} + +// Patch returns a Patch with all the changes in chunks. This +// representation can be used to create several diff outputs. +// If context expires, an non-nil error will be returned +// Provided context must be non-nil +func (c Changes) PatchContext(ctx context.Context) (*Patch, error) { + return getPatchContext(ctx, "", c...) } |