@@ -76,6 +76,7 @@ type DiffLine struct {
7676 Content string
7777 Comments []* models.Comment
7878 SectionInfo * DiffLineSectionInfo
79+ NEOF bool
7980}
8081
8182// DiffLineSectionInfo represents diff line section meta data
@@ -180,6 +181,7 @@ var (
180181 addedCodePrefix = []byte (`<span class="added-code">` )
181182 removedCodePrefix = []byte (`<span class="removed-code">` )
182183 codeTagSuffix = []byte (`</span>` )
184+ neofSuffix = []byte (`⍉⏎` )
183185)
184186var trailingSpanRegex = regexp .MustCompile (`<span\s*[[:alpha:]="]*?[>]?$` )
185187
@@ -290,10 +292,28 @@ func init() {
290292 diffMatchPatch .DiffEditCost = 100
291293}
292294
295+ func getDiffLineContentForDisplay (diffLine * DiffLine ) string {
296+ content := getLineContent (diffLine .Content [1 :])
297+ if diffLine .NEOF {
298+ content += string (neofSuffix )
299+ }
300+
301+ return content
302+ }
303+
304+ func getDiffLineContentForDiff (diffLine * DiffLine ) string {
305+ content := diffLine .Content [1 :]
306+ if diffLine .NEOF {
307+ content += string (neofSuffix )
308+ }
309+
310+ return content
311+ }
312+
293313// GetComputedInlineDiffFor computes inline diff for the given line.
294314func (diffSection * DiffSection ) GetComputedInlineDiffFor (diffLine * DiffLine ) template.HTML {
295315 if setting .Git .DisableDiffHighlight {
296- return template .HTML (getLineContent (diffLine . Content [ 1 :] ))
316+ return template .HTML (getDiffLineContentForDisplay (diffLine ))
297317 }
298318
299319 var (
@@ -305,29 +325,29 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) tem
305325 // try to find equivalent diff line. ignore, otherwise
306326 switch diffLine .Type {
307327 case DiffLineSection :
308- return template .HTML (getLineContent (diffLine .Content [ 1 :] ))
328+ return template .HTML (getLineContent (diffLine .Content ))
309329 case DiffLineAdd :
310330 compareDiffLine = diffSection .GetLine (DiffLineDel , diffLine .RightIdx )
311331 if compareDiffLine == nil {
312- return template .HTML (highlight .Code (diffSection .FileName , diffLine . Content [ 1 :] ))
332+ return template .HTML (highlight .Code (diffSection .FileName , getDiffLineContentForDisplay ( diffLine ) ))
313333 }
314- diff1 = compareDiffLine . Content
315- diff2 = diffLine . Content
334+ diff1 = getDiffLineContentForDiff ( compareDiffLine )
335+ diff2 = getDiffLineContentForDiff ( diffLine )
316336 case DiffLineDel :
317337 compareDiffLine = diffSection .GetLine (DiffLineAdd , diffLine .LeftIdx )
318338 if compareDiffLine == nil {
319- return template .HTML (highlight .Code (diffSection .FileName , diffLine . Content [ 1 :] ))
339+ return template .HTML (highlight .Code (diffSection .FileName , getDiffLineContentForDisplay ( diffLine ) ))
320340 }
321- diff1 = diffLine . Content
322- diff2 = compareDiffLine . Content
341+ diff1 = getDiffLineContentForDiff ( diffLine )
342+ diff2 = getDiffLineContentForDiff ( compareDiffLine )
323343 default :
324344 if strings .IndexByte (" +-" , diffLine .Content [0 ]) > - 1 {
325- return template .HTML (highlight .Code (diffSection .FileName , diffLine . Content [ 1 :] ))
345+ return template .HTML (highlight .Code (diffSection .FileName , getDiffLineContentForDiff ( diffLine ) ))
326346 }
327347 return template .HTML (highlight .Code (diffSection .FileName , diffLine .Content ))
328348 }
329349
330- diffRecord := diffMatchPatch .DiffMain (highlight .Code (diffSection .FileName , diff1 [ 1 :] ), highlight .Code (diffSection .FileName , diff2 [ 1 :] ), true )
350+ diffRecord := diffMatchPatch .DiffMain (highlight .Code (diffSection .FileName , diff1 ), highlight .Code (diffSection .FileName , diff2 ), true )
331351 diffRecord = diffMatchPatch .DiffCleanupEfficiency (diffRecord )
332352 return diffToHTML (diffSection .FileName , diffRecord , diffLine .Type )
333353}
@@ -707,8 +727,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
707727 err = fmt .Errorf ("Unexpected line in hunk: %s" , string (lineBytes ))
708728 return
709729 }
710- // Technically this should be the end the file!
711- // FIXME: we should be putting a marker at the end of the file if there is no terminal new line
730+ curSection .Lines [len (curSection .Lines )- 1 ].NEOF = true
712731 continue
713732 case '+' :
714733 curFileLinesCount ++
0 commit comments