aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-11 23:35:53 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-11 23:35:53 +0800
commit1df3884b55dc3b8d045e9322225c102b551a2a51 (patch)
treedfe7bcfec0a0935e89080d807a330e03877d8a3f
parent*.go: Reformat (diff)
downloadforge-1df3884b55dc3b8d045e9322225c102b551a2a51.tar.gz
forge-1df3884b55dc3b8d045e9322225c102b551a2a51.tar.zst
forge-1df3884b55dc3b8d045e9322225c102b551a2a51.zip
repo_commit: Don't crash on null from/to files
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--handle_repo_commit.go28
3 files changed, 31 insertions, 1 deletions
diff --git a/go.mod b/go.mod
index 558d57e..e428ed4 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@ require (
github.com/go-git/go-git/v5 v5.13.2
github.com/microcosm-cc/bluemonday v1.0.27
github.com/yuin/goldmark v1.7.8
- go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250211092902-f64ead6a659e
+ go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250211153243-8946fae17bd0
)
require (
diff --git a/go.sum b/go.sum
index 33449a9..21235e3 100644
--- a/go.sum
+++ b/go.sum
@@ -87,6 +87,8 @@ github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250211092902-f64ead6a659e h1:Gb58k5z3NjOWdYMBvZaTLG4IWY6HcCVkwPz/J0lFKT0=
go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250211092902-f64ead6a659e/go.mod h1:bOxuuGXA3UpbLb1lKohr2j2MVcGGLcqfAprGx9VCkMA=
+go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250211153243-8946fae17bd0 h1:NxXd9AOAMNKm2+WThVWqd41IqAKC3bKBvZMIUqAdT40=
+go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250211153243-8946fae17bd0/go.mod h1:bOxuuGXA3UpbLb1lKohr2j2MVcGGLcqfAprGx9VCkMA=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
diff --git a/handle_repo_commit.go b/handle_repo_commit.go
index 56103e7..d45fd1d 100644
--- a/handle_repo_commit.go
+++ b/handle_repo_commit.go
@@ -5,7 +5,9 @@ import (
"strings"
"github.com/go-git/go-git/v5/plumbing"
+ "github.com/go-git/go-git/v5/plumbing/filemode"
"github.com/go-git/go-git/v5/plumbing/format/diff"
+ "go.lindenii.runxiyu.org/lindenii-common/misc"
)
type usable_file_patch struct {
@@ -67,6 +69,12 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request) {
usable_file_patches := make([]usable_file_patch, 0)
for _, file_patch := range patch.FilePatches() {
from, to := file_patch.Files()
+ if from == nil {
+ from = fake_diff_file_null
+ }
+ if to == nil {
+ to = fake_diff_file_null
+ }
usable_file_patch := usable_file_patch{
Chunks: file_patch.Chunks(),
From: from,
@@ -82,3 +90,23 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request) {
return
}
}
+
+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("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"),
+ mode: misc.First_or_panic(filemode.New("100644")),
+ path: "NULL",
+}