@@ -27,56 +27,70 @@ func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader)
27
27
pgpsig := false
28
28
29
29
scanner := bufio .NewScanner (reader )
30
+ // Split by '\n' but include the '\n'
31
+ scanner .Split (func (data []byte , atEOF bool ) (advance int , token []byte , err error ) {
32
+ if atEOF && len (data ) == 0 {
33
+ return 0 , nil , nil
34
+ }
35
+ if i := bytes .IndexByte (data , '\n' ); i >= 0 {
36
+ // We have a full newline-terminated line.
37
+ return i + 1 , data [0 : i + 1 ], nil
38
+ }
39
+ // If we're at EOF, we have a final, non-terminated line. Return it.
40
+ if atEOF {
41
+ return len (data ), data , nil
42
+ }
43
+ // Request more data.
44
+ return 0 , nil , nil
45
+ })
46
+
30
47
for scanner .Scan () {
31
48
line := scanner .Bytes ()
32
49
if pgpsig {
33
50
if len (line ) > 0 && line [0 ] == ' ' {
34
- line = bytes .TrimLeft (line , " " )
35
- _ , _ = signatureSB .Write (line )
36
- _ = signatureSB .WriteByte ('\n' )
51
+ _ , _ = signatureSB .Write (line [1 :])
37
52
continue
38
53
} else {
39
54
pgpsig = false
40
55
}
41
56
}
42
57
43
58
if ! message {
59
+ // This is probably not correct but is copied from go-gits interpretation...
44
60
trimmed := bytes .TrimSpace (line )
45
61
if len (trimmed ) == 0 {
46
62
message = true
47
- _ , _ = payloadSB .WriteString ( " \n " )
63
+ _ , _ = payloadSB .Write ( line )
48
64
continue
49
65
}
50
66
51
67
split := bytes .SplitN (trimmed , []byte {' ' }, 2 )
68
+ var data []byte
69
+ if len (split ) > 1 {
70
+ data = split [1 ]
71
+ }
52
72
53
73
switch string (split [0 ]) {
54
74
case "tree" :
55
- commit .Tree = * NewTree (gitRepo , plumbing .NewHash (string (split [ 1 ] )))
75
+ commit .Tree = * NewTree (gitRepo , plumbing .NewHash (string (data )))
56
76
_ , _ = payloadSB .Write (line )
57
- _ = payloadSB .WriteByte ('\n' )
58
77
case "parent" :
59
- commit .Parents = append (commit .Parents , plumbing .NewHash (string (split [ 1 ] )))
78
+ commit .Parents = append (commit .Parents , plumbing .NewHash (string (data )))
60
79
_ , _ = payloadSB .Write (line )
61
- _ = payloadSB .WriteByte ('\n' )
62
80
case "author" :
63
81
commit .Author = & Signature {}
64
- commit .Author .Decode (split [ 1 ] )
82
+ commit .Author .Decode (data )
65
83
_ , _ = payloadSB .Write (line )
66
- _ = payloadSB .WriteByte ('\n' )
67
84
case "committer" :
68
85
commit .Committer = & Signature {}
69
- commit .Committer .Decode (split [ 1 ] )
86
+ commit .Committer .Decode (data )
70
87
_ , _ = payloadSB .Write (line )
71
- _ = payloadSB .WriteByte ('\n' )
72
88
case "gpgsig" :
73
- _ , _ = signatureSB .Write (split [1 ])
74
- _ = signatureSB .WriteByte ('\n' )
89
+ _ , _ = signatureSB .Write (data )
75
90
pgpsig = true
76
91
}
77
92
} else {
78
93
_ , _ = messageSB .Write (line )
79
- _ = messageSB .WriteByte ('\n' )
80
94
}
81
95
}
82
96
commit .CommitMessage = messageSB .String ()
0 commit comments