diff options
author | Russ Cox <rsc@golang.org> | 2010-01-26 17:49:33 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-01-26 17:49:33 -0800 |
commit | 529a6a2acdb3300a45f9287d4b26893aa31d0d97 (patch) | |
tree | 72605665a3a4ba9c892d4ef9a9462d369e2c7f76 | |
parent | b9c826a64c403cb550624006a6345b379637670b (diff) | |
download | golang-529a6a2acdb3300a45f9287d4b26893aa31d0d97.tar.gz |
patch: handle text diffs from git
R=r
CC=golang-dev
http://codereview.appspot.com/194094
-rw-r--r-- | src/pkg/patch/patch.go | 5 | ||||
-rw-r--r-- | src/pkg/patch/patch_test.go | 11 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/pkg/patch/patch.go b/src/pkg/patch/patch.go index 04ecd9d24..9d9aa1b48 100644 --- a/src/pkg/patch/patch.go +++ b/src/pkg/patch/patch.go @@ -207,7 +207,7 @@ func Parse(text []byte) (*Set, os.Error) { p.Diff = diff break } - if hasPrefix(l, "index ") || hasPrefix(l, "GIT binary patch") { + if hasPrefix(l, "GIT binary patch") || (hasPrefix(l, "index ") && !hasPrefix(raw, "--- ")) { diff, err := ParseGitBinary(oldraw) if err != nil { return nil, err @@ -215,6 +215,9 @@ func Parse(text []byte) (*Set, os.Error) { p.Diff = diff break } + if hasPrefix(l, "index ") { + continue + } return nil, SyntaxError("unexpected patch header line: " + string(l)) } if p.Diff == nil { diff --git a/src/pkg/patch/patch_test.go b/src/pkg/patch/patch_test.go index 5b3d48315..49a5c76d4 100644 --- a/src/pkg/patch/patch_test.go +++ b/src/pkg/patch/patch_test.go @@ -53,6 +53,17 @@ var tests = []Test{ Test{ "hello, world\n", "goodbye, world\n", + "Index: a\n" + + "index cb34d9b1743b7c410fa750be8a58eb355987110b..0a01764bc1b2fd29da317f72208f462ad342400f\n" + + "--- a/a\n" + + "+++ b/b\n" + + "@@ -1 +1 @@\n" + + "-hello, world\n" + + "+goodbye, world\n", + }, + Test{ + "hello, world\n", + "goodbye, world\n", "diff a/a b/b\n" + "--- a/a\n" + "+++ b/b\n" + |