aboutsummaryrefslogtreecommitdiff
path: root/http_handle_repo_commit.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-19 08:45:09 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-19 08:49:05 +0800
commitded9d435b081ab552d8c5d4e1f655e7b26a8be0a (patch)
tree6c5698994b393d9b10c53550ce379ef8ce403565 /http_handle_repo_commit.go
parenthttp: Add blank contrib/%d template (diff)
downloadforge-ded9d435b081ab552d8c5d4e1f655e7b26a8be0a.tar.gz
forge-ded9d435b081ab552d8c5d4e1f655e7b26a8be0a.tar.zst
forge-ded9d435b081ab552d8c5d4e1f655e7b26a8be0a.zip
repo/contrib: Display merge request diffs
Diffstat (limited to 'http_handle_repo_commit.go')
-rw-r--r--http_handle_repo_commit.go59
1 files changed, 32 insertions, 27 deletions
diff --git a/http_handle_repo_commit.go b/http_handle_repo_commit.go
index 11f16e4..25802ed 100644
--- a/http_handle_repo_commit.go
+++ b/http_handle_repo_commit.go
@@ -62,9 +62,39 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[strin
params["parent_commit_hash"] = parent_commit_hash.String()
params["patch"] = patch
+ params["file_patches"] = make_usable_file_patches(patch)
+
+ render_template(w, "repo_commit", params)
+}
+
+type fake_diff_file struct {
+ hash plumbing.Hash
+ mode filemode.FileMode
+ path string
+}
+
+func (f fake_diff_file) Hash() plumbing.Hash {
+ return f.hash
+}
+
+func (f fake_diff_file) Mode() filemode.FileMode {
+ return f.mode
+}
+
+func (f fake_diff_file) Path() string {
+ return f.path
+}
+
+var fake_diff_file_null = fake_diff_file{
+ hash: plumbing.NewHash("0000000000000000000000000000000000000000"),
+ mode: misc.First_or_panic(filemode.New("100644")),
+ path: "",
+}
+
+func make_usable_file_patches(patch diff.Patch) (usable_file_patches []usable_file_patch) {
// TODO: Remove unnecessary context
// TODO: Prepend "+"/"-"/" " instead of solely distinguishing based on color
- usable_file_patches := make([]usable_file_patch, 0)
+ usable_file_patches = make([]usable_file_patch, 0)
for _, file_patch := range patch.FilePatches() {
from, to := file_patch.Files()
if from == nil {
@@ -91,31 +121,6 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[strin
}
usable_file_patches = append(usable_file_patches, usable_file_patch)
}
- params["file_patches"] = usable_file_patches
-
- render_template(w, "repo_commit", params)
-}
-
-type fake_diff_file struct {
- hash plumbing.Hash
- mode filemode.FileMode
- path string
-}
-
-func (f fake_diff_file) Hash() plumbing.Hash {
- return f.hash
+ return
}
-func (f fake_diff_file) Mode() filemode.FileMode {
- return f.mode
-}
-
-func (f fake_diff_file) Path() string {
- return f.path
-}
-
-var fake_diff_file_null = fake_diff_file{
- hash: plumbing.NewHash("0000000000000000000000000000000000000000"),
- mode: misc.First_or_panic(filemode.New("100644")),
- path: "",
-}