@@ -76,6 +76,7 @@ type DiffLine struct {
76
76
Content string
77
77
Comments []* models.Comment
78
78
SectionInfo * DiffLineSectionInfo
79
+ NEOF bool
79
80
}
80
81
81
82
// DiffLineSectionInfo represents diff line section meta data
@@ -180,6 +181,7 @@ var (
180
181
addedCodePrefix = []byte (`<span class="added-code">` )
181
182
removedCodePrefix = []byte (`<span class="removed-code">` )
182
183
codeTagSuffix = []byte (`</span>` )
184
+ neofSuffix = []byte (`⍉⏎` )
183
185
)
184
186
var trailingSpanRegex = regexp .MustCompile (`<span\s*[[:alpha:]="]*?[>]?$` )
185
187
@@ -290,10 +292,28 @@ func init() {
290
292
diffMatchPatch .DiffEditCost = 100
291
293
}
292
294
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
+
293
313
// GetComputedInlineDiffFor computes inline diff for the given line.
294
314
func (diffSection * DiffSection ) GetComputedInlineDiffFor (diffLine * DiffLine ) template.HTML {
295
315
if setting .Git .DisableDiffHighlight {
296
- return template .HTML (getLineContent (diffLine . Content [ 1 :] ))
316
+ return template .HTML (getDiffLineContentForDisplay (diffLine ))
297
317
}
298
318
299
319
var (
@@ -305,29 +325,29 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) tem
305
325
// try to find equivalent diff line. ignore, otherwise
306
326
switch diffLine .Type {
307
327
case DiffLineSection :
308
- return template .HTML (getLineContent (diffLine .Content [ 1 :] ))
328
+ return template .HTML (getLineContent (diffLine .Content ))
309
329
case DiffLineAdd :
310
330
compareDiffLine = diffSection .GetLine (DiffLineDel , diffLine .RightIdx )
311
331
if compareDiffLine == nil {
312
- return template .HTML (highlight .Code (diffSection .FileName , diffLine . Content [ 1 :] ))
332
+ return template .HTML (highlight .Code (diffSection .FileName , getDiffLineContentForDisplay ( diffLine ) ))
313
333
}
314
- diff1 = compareDiffLine . Content
315
- diff2 = diffLine . Content
334
+ diff1 = getDiffLineContentForDiff ( compareDiffLine )
335
+ diff2 = getDiffLineContentForDiff ( diffLine )
316
336
case DiffLineDel :
317
337
compareDiffLine = diffSection .GetLine (DiffLineAdd , diffLine .LeftIdx )
318
338
if compareDiffLine == nil {
319
- return template .HTML (highlight .Code (diffSection .FileName , diffLine . Content [ 1 :] ))
339
+ return template .HTML (highlight .Code (diffSection .FileName , getDiffLineContentForDisplay ( diffLine ) ))
320
340
}
321
- diff1 = diffLine . Content
322
- diff2 = compareDiffLine . Content
341
+ diff1 = getDiffLineContentForDiff ( diffLine )
342
+ diff2 = getDiffLineContentForDiff ( compareDiffLine )
323
343
default :
324
344
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 ) ))
326
346
}
327
347
return template .HTML (highlight .Code (diffSection .FileName , diffLine .Content ))
328
348
}
329
349
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 )
331
351
diffRecord = diffMatchPatch .DiffCleanupEfficiency (diffRecord )
332
352
return diffToHTML (diffSection .FileName , diffRecord , diffLine .Type )
333
353
}
@@ -707,8 +727,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
707
727
err = fmt .Errorf ("Unexpected line in hunk: %s" , string (lineBytes ))
708
728
return
709
729
}
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
712
731
continue
713
732
case '+' :
714
733
curFileLinesCount ++
0 commit comments