This repository has been archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #874 from smola/patchcontext
plumbing: add context to allow cancel on diff/patch computing
- Loading branch information
Showing
9 changed files
with
297 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package object | |
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io" | ||
"strings" | ||
"time" | ||
|
@@ -132,6 +133,59 @@ Binary files /dev/null and b/binary.jpg differ | |
c.Assert(buf.String(), Equals, patch.String()) | ||
} | ||
|
||
func (s *SuiteCommit) TestPatchContext(c *C) { | ||
from := s.commit(c, plumbing.NewHash("918c48b83bd081e863dbe1b80f8998f058cd8294")) | ||
to := s.commit(c, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")) | ||
|
||
patch, err := from.PatchContext(context.Background(), to) | ||
c.Assert(err, IsNil) | ||
|
||
buf := bytes.NewBuffer(nil) | ||
err = patch.Encode(buf) | ||
c.Assert(err, IsNil) | ||
|
||
c.Assert(buf.String(), Equals, `diff --git a/vendor/foo.go b/vendor/foo.go | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..9dea2395f5403188298c1dabe8bdafe562c491e3 | ||
--- /dev/null | ||
+++ b/vendor/foo.go | ||
@@ -0,0 +1,7 @@ | ||
+package main | ||
+ | ||
+import "fmt" | ||
+ | ||
+func main() { | ||
+ fmt.Println("Hello, playground") | ||
+} | ||
`) | ||
c.Assert(buf.String(), Equals, patch.String()) | ||
|
||
from = s.commit(c, plumbing.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47")) | ||
to = s.commit(c, plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9")) | ||
|
||
patch, err = from.PatchContext(context.Background(), to) | ||
c.Assert(err, IsNil) | ||
|
||
buf.Reset() | ||
err = patch.Encode(buf) | ||
c.Assert(err, IsNil) | ||
|
||
c.Assert(buf.String(), Equals, `diff --git a/CHANGELOG b/CHANGELOG | ||
deleted file mode 100644 | ||
index d3ff53e0564a9f87d8e84b6e28e5060e517008aa..0000000000000000000000000000000000000000 | ||
--- a/CHANGELOG | ||
+++ /dev/null | ||
@@ -1 +0,0 @@ | ||
-Initial changelog | ||
diff --git a/binary.jpg b/binary.jpg | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..d5c0f4ab811897cadf03aec358ae60d21f91c50d | ||
Binary files /dev/null and b/binary.jpg differ | ||
`) | ||
|
||
c.Assert(buf.String(), Equals, patch.String()) | ||
} | ||
|
||
func (s *SuiteCommit) TestCommitEncodeDecodeIdempotent(c *C) { | ||
ts, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05-07:00") | ||
c.Assert(err, IsNil) | ||
|
@@ -363,3 +417,15 @@ sYyf9RfOnw/KUFAQbdtvLx3ikODQC+D3KBtuKI9ISHQfgw== | |
_, ok := e.Identities["Sunny <[email protected]>"] | ||
c.Assert(ok, Equals, true) | ||
} | ||
|
||
func (s *SuiteCommit) TestPatchCancel(c *C) { | ||
from := s.commit(c, plumbing.NewHash("918c48b83bd081e863dbe1b80f8998f058cd8294")) | ||
to := s.commit(c, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
cancel() | ||
patch, err := from.PatchContext(ctx, to) | ||
c.Assert(patch, IsNil) | ||
c.Assert(err, ErrorMatches, "operation canceled") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.