aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-11 20:50:17 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-11 20:50:17 +0800
commit7491c424a00f0824f1d45b33d3b3f55fb0a7c4d8 (patch)
tree7a97d02446ebe590b0ae06d6435be8e8297eba0b
parentrepo_index.html, style.css: CSS state machines (diff)
downloadforge-7491c424a00f0824f1d45b33d3b3f55fb0a7c4d8.tar.gz
forge-7491c424a00f0824f1d45b33d3b3f55fb0a7c4d8.tar.zst
forge-7491c424a00f0824f1d45b33d3b3f55fb0a7c4d8.zip
repo_commit: Show chunks
Diffstat (limited to '')
-rw-r--r--handle_repo_commit.go22
-rw-r--r--static/style.css14
-rw-r--r--templates/repo_commit.html.tmpl19
3 files changed, 46 insertions, 9 deletions
diff --git a/handle_repo_commit.go b/handle_repo_commit.go
index c7bdf9f..3a63201 100644
--- a/handle_repo_commit.go
+++ b/handle_repo_commit.go
@@ -4,8 +4,15 @@ import (
"net/http"
"github.com/go-git/go-git/v5/plumbing"
+ "github.com/go-git/go-git/v5/plumbing/format/diff"
)
+type usable_file_patch struct {
+ From diff.File
+ To diff.File
+ Chunks []diff.Chunk
+}
+
func handle_repo_commit(w http.ResponseWriter, r *http.Request) {
data := make(map[string]any)
// TODO: Sanitize path values
@@ -38,12 +45,17 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request) {
}
data["patch"] = patch
- /*
- for _, file_patch := range patch.FilePatches() {
- for _, chunk := range file_patch.Chunks() {
- }
+ usable_file_patches := make([]usable_file_patch, 0)
+ for _, file_patch := range patch.FilePatches() {
+ from, to := file_patch.Files()
+ usable_file_patch := usable_file_patch{
+ Chunks: file_patch.Chunks(),
+ From: from,
+ To: to,
}
- */
+ usable_file_patches = append(usable_file_patches, usable_file_patch)
+ }
+ data["file_patches"] = usable_file_patches
err = templates.ExecuteTemplate(w, "repo_commit", data)
if err != nil {
diff --git a/static/style.css b/static/style.css
index af5a9b3..e37ad0d 100644
--- a/static/style.css
+++ b/static/style.css
@@ -88,7 +88,7 @@ td#readme > *:first-child {
.commit-id {
font-family: monospace;
}
-pre, .scroll {
+.scroll {
overflow-x: auto;
}
.toggle-table-off, .toggle-table-on {
@@ -112,3 +112,15 @@ pre, .scroll {
.toggle-table-on:checked + table > tbody {
display: table-row-group;
}
+.chunk-unchanged {
+ color: grey;
+}
+.chunk-addition {
+ color: green;
+}
+.chunk-deletion {
+ color: red;
+}
+.chunk-unknown {
+ color: yellow;
+}
diff --git a/templates/repo_commit.html.tmpl b/templates/repo_commit.html.tmpl
index c480c92..edc4bc3 100644
--- a/templates/repo_commit.html.tmpl
+++ b/templates/repo_commit.html.tmpl
@@ -42,9 +42,22 @@
</table>
</div>
<div class="padding-wrapper scroll">
- <pre>{{ .patch }}</pre>
- <p>
- </p>
+ {{ range .file_patches }}
+ <div class="file-patch">
+ {{ .From.Path }} {{ .From.Mode }} &rarr; {{ .To.Path }} {{ .To.Mode }}
+ {{ range .Chunks }}
+ {{ if eq .Type 0 }}
+ <pre class="chunk chunk-unchanged">{{ .Content }}</pre>
+ {{ else if eq .Type 1 }}
+ <pre class="chunk chunk-addition">{{ .Content }}</pre>
+ {{ else if eq .Type 2 }}
+ <pre class="chunk chunk-deletion">{{ .Content }}</pre>
+ {{ else }}
+ <pre class="chunk chunk-unknown">{{ .Content }}</pre>
+ {{ end }}
+ {{ end }}
+ </div>
+ {{ end }}
</div>
<footer>
{{ template "footer" . }}