]> source.dussan.org Git - gitea.git/commitdiff
Fix incorrect diff expander for deletion of last lines in a file (#29501)
authorsilverwind <me@silverwind.io>
Fri, 1 Mar 2024 16:12:21 +0000 (17:12 +0100)
committerGitHub <noreply@github.com>
Fri, 1 Mar 2024 16:12:21 +0000 (16:12 +0000)
Fixes: https://github.com/go-gitea/gitea/issues/29498
I don't quite understand this code, but this change does seem to fix the
issue and I tested a number of diffs with it and saw no issue. The
function gets such value if last line is an addition:

```
  LastLeftIdx: (int) 0,
  LastRightIdx: (int) 47,
  LeftIdx: (int) 47,
  RightIdx: (int) 48,
```

If it's a deletion, it gets:

```
  LastLeftIdx: (int) 47,
  LastRightIdx: (int) 0,
  LeftIdx: (int) 48,
  RightIdx: (int) 47,
```

So I think it's correct to make this check respect both left and right
side.

services/gitdiff/gitdiff.go

index 740c748347dc11e3befea03c59dc08cf23cbe6b8..b05c210a0cf5c201cc465e8d5ab6d86cebb01c4c 100644 (file)
@@ -154,7 +154,7 @@ func (d *DiffLine) GetBlobExcerptQuery() string {
 
 // GetExpandDirection gets DiffLineExpandDirection
 func (d *DiffLine) GetExpandDirection() DiffLineExpandDirection {
-       if d.Type != DiffLineSection || d.SectionInfo == nil || d.SectionInfo.RightIdx-d.SectionInfo.LastRightIdx <= 1 {
+       if d.Type != DiffLineSection || d.SectionInfo == nil || d.SectionInfo.LeftIdx-d.SectionInfo.LastLeftIdx <= 1 || d.SectionInfo.RightIdx-d.SectionInfo.LastRightIdx <= 1 {
                return DiffLineExpandNone
        }
        if d.SectionInfo.LastLeftIdx <= 0 && d.SectionInfo.LastRightIdx <= 0 {