aboutsummaryrefslogtreecommitdiffstats
path: root/utils/merkletrie/difftree.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 /utils/merkletrie/difftree.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 'utils/merkletrie/difftree.go')
-rw-r--r--utils/merkletrie/difftree.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/utils/merkletrie/difftree.go b/utils/merkletrie/difftree.go
index 2294096..d57ed13 100644
--- a/utils/merkletrie/difftree.go
+++ b/utils/merkletrie/difftree.go
@@ -248,15 +248,30 @@ package merkletrie
// h: else of i
import (
+ "context"
+ "errors"
"fmt"
"gopkg.in/src-d/go-git.v4/utils/merkletrie/noder"
)
+var (
+ ErrCanceled = errors.New("operation canceled")
+)
+
// DiffTree calculates the list of changes between two merkletries. It
// uses the provided hashEqual callback to compare noders.
func DiffTree(fromTree, toTree noder.Noder,
hashEqual noder.Equal) (Changes, error) {
+ return DiffTreeContext(context.Background(), fromTree, toTree, hashEqual)
+}
+
+// DiffTree calculates the list of changes between two merkletries. It
+// uses the provided hashEqual callback to compare noders.
+// Error will be returned if context expires
+// Provided context must be non nil
+func DiffTreeContext(ctx context.Context, fromTree, toTree noder.Noder,
+ hashEqual noder.Equal) (Changes, error) {
ret := NewChanges()
ii, err := newDoubleIter(fromTree, toTree, hashEqual)
@@ -265,6 +280,12 @@ func DiffTree(fromTree, toTree noder.Noder,
}
for {
+ select {
+ case <-ctx.Done():
+ return nil, ErrCanceled
+ default:
+ }
+
from := ii.from.current
to := ii.to.current