1
0
mirror of https://github.com/golang/go synced 2024-11-24 08:10:09 -07:00

patch: handle text diffs from git

R=r
CC=golang-dev
https://golang.org/cl/194094
This commit is contained in:
Russ Cox 2010-01-26 17:49:33 -08:00
parent dd97923d82
commit 3e0ee6b594
2 changed files with 15 additions and 1 deletions

View File

@ -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 {

View File

@ -50,6 +50,17 @@ var tests = []Test{
"-hello, 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{
"hello, world\n",
"goodbye, world\n",