From 24d66ad693eee6df6df37be8b64d594221a6221e Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Wed, 12 Feb 2025 01:42:38 +0800 Subject: repo_commit: Fix format_patch handling of root commits --- handle_repo_commit.go | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'handle_repo_commit.go') 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 -- cgit v1.2.3