aboutsummaryrefslogtreecommitdiff
path: root/handle_repo_commit.go
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 /handle_repo_commit.go
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
Diffstat (limited to '')
-rw-r--r--handle_repo_commit.go28
1 files changed, 28 insertions, 0 deletions
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",
+}