MCPcopy Create free account
hub / github.com/gogs/gogs / ComputedInlineDiffFor

Method ComputedInlineDiffFor

internal/gitutil/diff.go:31–71  ·  view source on GitHub ↗

ComputedInlineDiffFor computes inline diff for the given line.

(line *git.DiffLine)

Source from the content-addressed store, hash-verified

29
30// ComputedInlineDiffFor computes inline diff for the given line.
31func (s *DiffSection) ComputedInlineDiffFor(line *git.DiffLine) template.HTML {
32 fallback := template.HTML(html.EscapeString(line.Content))
33 if conf.Git.DisableDiffHighlight {
34 return fallback
35 }
36
37 // Find equivalent diff line, ignore when not found.
38 var diff1, diff2 string
39 switch line.Type {
40 case git.DiffLineAdd:
41 compareLine := s.Line(git.DiffLineDelete, line.RightLine)
42 if compareLine == nil {
43 return fallback
44 }
45
46 diff1 = compareLine.Content
47 diff2 = line.Content
48
49 case git.DiffLineDelete:
50 compareLine := s.Line(git.DiffLineAdd, line.LeftLine)
51 if compareLine == nil {
52 return fallback
53 }
54
55 diff1 = line.Content
56 diff2 = compareLine.Content
57
58 default:
59 return fallback
60 }
61
62 s.initOnce.Do(func() {
63 s.dmp = diffmatchpatch.New()
64 s.dmp.DiffEditCost = 100
65 })
66
67 diffs := s.dmp.DiffMain(diff1[1:], diff2[1:], true)
68 diffs = s.dmp.DiffCleanupEfficiency(diffs)
69
70 return diffsToHTML(diffs, line.Type)
71}
72
73func diffsToHTML(diffs []diffmatchpatch.Diff, lineType git.DiffLineType) template.HTML {
74 buf := bytes.NewBuffer(nil)

Callers

nothing calls this directly

Calls 2

diffsToHTMLFunction · 0.85
HTMLMethod · 0.80

Tested by

no test coverage detected