aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/tree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-07-10 11:34:51 +0200
committerGitHub <noreply@github.com>2018-07-10 11:34:51 +0200
commit3bd5e82b2512d85becae9677fa06b5a973fd4cfb (patch)
tree7b5aa42ef1b86540f0e30ab6e79aa0772e5986a7 /plumbing/object/tree.go
parent8ad72db0b7e1c03d9fad343890e469d5c3ed757b (diff)
parent9251ea764df3de13518f974635e76315b2b89e3e (diff)
downloadgo-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/tree.go')
-rw-r--r--plumbing/object/tree.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/plumbing/object/tree.go b/plumbing/object/tree.go
index 30bbcb0..86d19c0 100644
--- a/plumbing/object/tree.go
+++ b/plumbing/object/tree.go
@@ -2,6 +2,7 @@ package object
import (
"bufio"
+ "context"
"errors"
"fmt"
"io"
@@ -295,15 +296,30 @@ func (from *Tree) Diff(to *Tree) (Changes, error) {
return DiffTree(from, to)
}
+// Diff returns a list of changes between this tree and the provided one
+// Error will be returned if context expires
+// Provided context must be non nil
+func (from *Tree) DiffContext(ctx context.Context, to *Tree) (Changes, error) {
+ return DiffTreeContext(ctx, from, to)
+}
+
// Patch returns a slice of Patch objects with all the changes between trees
// in chunks. This representation can be used to create several diff outputs.
func (from *Tree) Patch(to *Tree) (*Patch, error) {
- changes, err := DiffTree(from, to)
+ return from.PatchContext(context.Background(), to)
+}
+
+// Patch returns a slice of Patch objects with all the changes between trees
+// in chunks. This representation can be used to create several diff outputs.
+// If context expires, an error will be returned
+// Provided context must be non-nil
+func (from *Tree) PatchContext(ctx context.Context, to *Tree) (*Patch, error) {
+ changes, err := DiffTreeContext(ctx, from, to)
if err != nil {
return nil, err
}
- return changes.Patch()
+ return changes.PatchContext(ctx)
}
// treeEntryIter facilitates iterating through the TreeEntry objects in a Tree.