aboutsummaryrefslogtreecommitdiff
path: root/handle_repo_commit.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-12 01:42:38 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-12 01:42:38 +0800
commit24d66ad693eee6df6df37be8b64d594221a6221e (patch)
treeaf10bb567bca9b443a0e9721f38cad0f69f1653d /handle_repo_commit.go
parentREADME.md: Update URL structure (diff)
downloadforge-24d66ad693eee6df6df37be8b64d594221a6221e.tar.gz
forge-24d66ad693eee6df6df37be8b64d594221a6221e.tar.zst
forge-24d66ad693eee6df6df37be8b64d594221a6221e.zip
repo_commit: Fix format_patch handling of root commits
Diffstat (limited to '')
-rw-r--r--handle_repo_commit.go29
1 files changed, 2 insertions, 27 deletions
diff --git a/handle_repo_commit.go b/handle_repo_commit.go
index 03a7cd4..aeea380 100644
--- a/handle_repo_commit.go
+++ b/handle_repo_commit.go
@@ -1,14 +1,12 @@
package main
import (
- "errors"
"net/http"
"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"
- "github.com/go-git/go-git/v5/plumbing/object"
"go.lindenii.runxiyu.org/lindenii-common/misc"
)
@@ -53,31 +51,8 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request) {
data["commit_object"] = commit_object
data["commit_id"] = commit_id_string
- var patch *object.Patch
- parent_commit_object, err := commit_object.Parent(0)
- if errors.Is(err, object.ErrParentNotFound) {
- commit_tree, err := commit_object.Tree()
- if err != nil {
- _, _ = w.Write([]byte("Error getting commit tree (for comparing against an empty tree): " + err.Error()))
- return
- }
- patch, err = (&object.Tree{}).Patch(commit_tree)
- if err != nil {
- _, _ = w.Write([]byte("Error getting patch of commit: " + err.Error()))
- return
- }
- } else if err != nil {
- _, _ = w.Write([]byte("Error getting parent commit object: " + err.Error()))
- return
- } else {
- data["parent_commit_hash"] = parent_commit_object.Hash.String()
-
- patch, err = parent_commit_object.Patch(commit_object)
- if err != nil {
- _, _ = w.Write([]byte("Error getting patch of commit: " + err.Error()))
- return
- }
- }
+ parent_commit_hash, patch, err := get_patch_from_commit(commit_object)
+ data["parent_commit_hash"] = parent_commit_hash.String()
data["patch"] = patch
// TODO: Remove unnecessary context