mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-29 20:13:27 +00:00
Fix diff expansion is missing final line in a file (#16222)
* Fixed down offset. * Fixed wrong line count result.
This commit is contained in:
parent
71c5a8f7f8
commit
4cc63e9919
|
@ -34,7 +34,7 @@ func (b *Blob) GetBlobContent() (string, error) {
|
||||||
return string(buf), nil
|
return string(buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlobLineCount gets line count of lob as raw text
|
// GetBlobLineCount gets line count of the blob
|
||||||
func (b *Blob) GetBlobLineCount() (int, error) {
|
func (b *Blob) GetBlobLineCount() (int, error) {
|
||||||
reader, err := b.DataAsync()
|
reader, err := b.DataAsync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -42,10 +42,14 @@ func (b *Blob) GetBlobLineCount() (int, error) {
|
||||||
}
|
}
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
buf := make([]byte, 32*1024)
|
buf := make([]byte, 32*1024)
|
||||||
count := 0
|
count := 1
|
||||||
lineSep := []byte{'\n'}
|
lineSep := []byte{'\n'}
|
||||||
|
|
||||||
|
c, err := reader.Read(buf)
|
||||||
|
if c == 0 && err == io.EOF {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
c, err := reader.Read(buf)
|
|
||||||
count += bytes.Count(buf[:c], lineSep)
|
count += bytes.Count(buf[:c], lineSep)
|
||||||
switch {
|
switch {
|
||||||
case err == io.EOF:
|
case err == io.EOF:
|
||||||
|
@ -53,6 +57,7 @@ func (b *Blob) GetBlobLineCount() (int, error) {
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
|
c, err = reader.Read(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -714,7 +714,11 @@ func ExcerptBlob(ctx *context.Context) {
|
||||||
lastLeft += chunkSize
|
lastLeft += chunkSize
|
||||||
lastRight += chunkSize
|
lastRight += chunkSize
|
||||||
} else {
|
} else {
|
||||||
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight-1)
|
offset := -1
|
||||||
|
if direction == "down" {
|
||||||
|
offset = 0
|
||||||
|
}
|
||||||
|
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset)
|
||||||
leftHunkSize = 0
|
leftHunkSize = 0
|
||||||
rightHunkSize = 0
|
rightHunkSize = 0
|
||||||
idxLeft = lastLeft
|
idxLeft = lastLeft
|
||||||
|
|
Loading…
Reference in a new issue