diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-07-10 11:34:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-10 11:34:51 +0200 |
commit | 3bd5e82b2512d85becae9677fa06b5a973fd4cfb (patch) | |
tree | 7b5aa42ef1b86540f0e30ab6e79aa0772e5986a7 /plumbing/object/change.go | |
parent | 8ad72db0b7e1c03d9fad343890e469d5c3ed757b (diff) | |
parent | 9251ea764df3de13518f974635e76315b2b89e3e (diff) | |
download | go-git-3bd5e82b2512d85becae9677fa06b5a973fd4cfb.tar.gz |
Merge pull request #874 from smola/patchcontextv4.5.0
plumbing: add context to allow cancel on diff/patch computing
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...) } |