Commit 3e0ee6b5 authored by Russ Cox's avatar Russ Cox

patch: handle text diffs from git

R=r
CC=golang-dev
https://golang.org/cl/194094
parent dd97923d
...@@ -207,7 +207,7 @@ func Parse(text []byte) (*Set, os.Error) { ...@@ -207,7 +207,7 @@ func Parse(text []byte) (*Set, os.Error) {
p.Diff = diff p.Diff = diff
break 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) diff, err := ParseGitBinary(oldraw)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -215,6 +215,9 @@ func Parse(text []byte) (*Set, os.Error) { ...@@ -215,6 +215,9 @@ func Parse(text []byte) (*Set, os.Error) {
p.Diff = diff p.Diff = diff
break break
} }
if hasPrefix(l, "index ") {
continue
}
return nil, SyntaxError("unexpected patch header line: " + string(l)) return nil, SyntaxError("unexpected patch header line: " + string(l))
} }
if p.Diff == nil { if p.Diff == nil {
......
...@@ -50,6 +50,17 @@ var tests = []Test{ ...@@ -50,6 +50,17 @@ var tests = []Test{
"-hello, world\n" + "-hello, world\n" +
"+goodbye, world\n", "+goodbye, world\n",
}, },
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{ Test{
"hello, world\n", "hello, world\n",
"goodbye, world\n", "goodbye, world\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment