Skip to content

Commit c3fbc01

Browse files
committed
adding patchheader to files
1 parent f23f745 commit c3fbc01

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

gitdiff/parser.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import (
77
"bufio"
88
"fmt"
99
"io"
10+
"strings"
1011
)
1112

13+
const commitPrefix = "commit"
14+
1215
// Parse parses a patch with changes to one or more files. Any content before
1316
// the first file is returned as the second value. If an error occurs while
1417
// parsing, it returns all files parsed before the error.
@@ -24,11 +27,17 @@ func Parse(r io.Reader) ([]*File, string, error) {
2427

2528
var preamble string
2629
var files []*File
30+
var ph *PatchHeader
2731
for {
2832
file, pre, err := p.ParseNextFileHeader()
2933
if err != nil {
3034
return files, preamble, err
3135
}
36+
37+
if strings.Contains(pre, commitPrefix) {
38+
ph, _ = ParsePatchHeader(pre)
39+
}
40+
3241
if file == nil {
3342
break
3443
}
@@ -46,6 +55,7 @@ func Parse(r io.Reader) ([]*File, string, error) {
4655
}
4756
}
4857

58+
file.PatchHeader = ph
4959
if len(files) == 0 {
5060
preamble = pre
5161
}

0 commit comments

Comments
 (0)