@@ -14,6 +14,9 @@ import ( |
| 14 | 14 | "github.com/go-chi/chi/v5" |
| 15 | 15 | |
| 16 | 16 | "github.com/tenseleyFlow/shithub/internal/auth/policy" |
| 17 | + diffparse "github.com/tenseleyFlow/shithub/internal/repos/diff/parse" |
| 18 | + diffrender "github.com/tenseleyFlow/shithub/internal/repos/diff/render" |
| 19 | + diffsource "github.com/tenseleyFlow/shithub/internal/repos/diff/source" |
| 17 | 20 | "github.com/tenseleyFlow/shithub/internal/repos/git" |
| 18 | 21 | repogit "github.com/tenseleyFlow/shithub/internal/repos/git" |
| 19 | 22 | "github.com/tenseleyFlow/shithub/internal/repos/identity" |
@@ -159,15 +162,39 @@ func (h *Handlers) commitView(w http.ResponseWriter, r *http.Request) { |
| 159 | 162 | author := resolver.Resolve(r.Context(), detail.AuthorEmail) |
| 160 | 163 | committer := resolver.Resolve(r.Context(), detail.CommitterEmail) |
| 161 | 164 | |
| 165 | + // S19 diff render: source the patch from the SHA and inline-render. |
| 166 | + mode := diffrender.ModeUnified |
| 167 | + if r.URL.Query().Get("diff") == "split" { |
| 168 | + mode = diffrender.ModeSplit |
| 169 | + } |
| 170 | + hideWS := r.URL.Query().Get("w") == "1" |
| 171 | + patch, perr := diffsource.FromCommit(r.Context(), gitDir, detail.OID, diffsource.Options{ |
| 172 | + IgnoreWhitespace: hideWS, FindRenames: true, |
| 173 | + }) |
| 174 | + var diffHTML template.HTML |
| 175 | + if perr != nil { |
| 176 | + h.d.Logger.WarnContext(r.Context(), "commit: diff source", "error", perr) |
| 177 | + } else { |
| 178 | + parsed, perr2 := diffparse.ParseBytes(patch) |
| 179 | + if perr2 != nil { |
| 180 | + h.d.Logger.WarnContext(r.Context(), "commit: diff parse", "error", perr2) |
| 181 | + } else { |
| 182 | + diffHTML = template.HTML(diffrender.Diff(parsed, diffrender.Options{Mode: mode})) //nolint:gosec // escapes inside |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 162 | 186 | h.d.Render.RenderPage(w, r, "repo/commit", map[string]any{ |
| 163 | | - "Title": detail.Subject + " · " + row.Name, |
| 164 | | - "CSRFToken": middleware.CSRFTokenForRequest(r), |
| 165 | | - "Owner": owner.Username, |
| 166 | | - "Repo": row, |
| 167 | | - "Detail": detail, |
| 168 | | - "Author": author, |
| 169 | | - "Committer": committer, |
| 170 | | - "BodyHTML": template.HTML(linkifyCommitBody(detail.Body)), //nolint:gosec // escaped inside |
| 187 | + "Title": detail.Subject + " · " + row.Name, |
| 188 | + "CSRFToken": middleware.CSRFTokenForRequest(r), |
| 189 | + "Owner": owner.Username, |
| 190 | + "Repo": row, |
| 191 | + "Detail": detail, |
| 192 | + "Author": author, |
| 193 | + "Committer": committer, |
| 194 | + "BodyHTML": template.HTML(linkifyCommitBody(detail.Body)), //nolint:gosec // escaped inside |
| 195 | + "DiffHTML": diffHTML, |
| 196 | + "DiffMode": string(mode), |
| 197 | + "HideWS": hideWS, |
| 171 | 198 | }) |
| 172 | 199 | } |
| 173 | 200 | |