aboutsummaryrefslogtreecommitdiff
path: root/handle_repo_commit.go
diff options
context:
space:
mode:
Diffstat (limited to 'handle_repo_commit.go')
-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