MCPcopy Create free account
hub / github.com/JanSmrcka/differ / renderCommitDiff

Function renderCommitDiff

internal/ui/log.go:137–167  ·  view source on GitHub ↗

renderCommitDiff renders a full commit diff (may contain multiple files).

(raw string, styles Styles, t theme.Theme, width int)

Source from the content-addressed store, hash-verified

135
136// renderCommitDiff renders a full commit diff (may contain multiple files).
137func renderCommitDiff(raw string, styles Styles, t theme.Theme, width int) string {
138 initChromaStyle(t.ChromaStyle)
139
140 var b strings.Builder
141 // Split by file boundaries and render each section
142 currentFile := ""
143 var currentLines []string
144
145 for _, line := range strings.Split(raw, "\n") {
146 if strings.HasPrefix(line, "diff --git") {
147 // Flush previous file
148 if len(currentLines) > 0 {
149 parsed := ParseDiff(strings.Join(currentLines, "\n"))
150 b.WriteString(RenderDiff(parsed, currentFile, styles, t, width))
151 }
152 currentFile = extractFilename(line)
153 // Add file separator
154 b.WriteString(styles.HeaderBar.Width(width).Render(" " + currentFile))
155 b.WriteByte('\n')
156 currentLines = []string{line}
157 } else {
158 currentLines = append(currentLines, line)
159 }
160 }
161 // Flush last file
162 if len(currentLines) > 0 {
163 parsed := ParseDiff(strings.Join(currentLines, "\n"))
164 b.WriteString(RenderDiff(parsed, currentFile, styles, t, width))
165 }
166 return b.String()
167}
168
169// extractFilename pulls the b/ path from "diff --git a/foo b/foo".
170func extractFilename(diffHeader string) string {

Callers 1

loadCommitDiffMethod · 0.85

Calls 4

initChromaStyleFunction · 0.85
ParseDiffFunction · 0.85
RenderDiffFunction · 0.85
extractFilenameFunction · 0.85

Tested by

no test coverage detected