shithub: furgit

Download patch

ref: b022f7f8f3515e81d584048b4d953966dd0eb3f2
parent: bb5b5334c74026c0a46f48cf2418038e0d909e9b
author: Runxi Yu <me@runxiyu.org>
date: Fri Feb 20 17:37:22 EST 2026

object: I guess these checks are unnecessary

--- a/object/commit_parse.go
+++ b/object/commit_parse.go
@@ -10,10 +10,6 @@
 
 // ParseCommit decodes a commit object body.
 func ParseCommit(body []byte, algo oid.Algorithm) (*Commit, error) {
-	if algo.Size() == 0 {
-		return nil, fmt.Errorf("object: commit: invalid hash algorithm %q", algo)
-	}
-
 	c := new(Commit)
 	i := 0
 	for i < len(body) {
--- a/object/tag_parse.go
+++ b/object/tag_parse.go
@@ -11,10 +11,6 @@
 
 // ParseTag decodes a tag object body.
 func ParseTag(body []byte, algo oid.Algorithm) (*Tag, error) {
-	if algo.Size() == 0 {
-		return nil, fmt.Errorf("object: tag: invalid hash algorithm %q", algo)
-	}
-
 	t := new(Tag)
 	i := 0
 	var haveTarget, haveType bool
--- a/object/tree.go
+++ b/object/tree.go
@@ -2,7 +2,6 @@
 
 import (
 	"bytes"
-	"errors"
 	"fmt"
 	"sort"
 
@@ -73,9 +72,6 @@
 
 // InsertEntry inserts a tree entry while preserving Git ordering.
 func (tree *Tree) InsertEntry(newEntry TreeEntry) error {
-	if tree == nil {
-		return errors.New("object: tree: insert on nil tree")
-	}
 	if tree.entry(newEntry.Name, true) != nil || tree.entry(newEntry.Name, false) != nil {
 		return fmt.Errorf("object: tree: entry %q already exists", newEntry.Name)
 	}
@@ -91,9 +87,6 @@
 
 // RemoveEntry removes a tree entry by name.
 func (tree *Tree) RemoveEntry(name []byte) error {
-	if tree == nil {
-		return errors.New("object: tree: remove on nil tree")
-	}
 	if len(tree.Entries) == 0 {
 		return fmt.Errorf("object: tree: entry %q not found", name)
 	}
--- a/object/tree_parse.go
+++ b/object/tree_parse.go
@@ -10,10 +10,6 @@
 
 // ParseTree decodes a tree object body.
 func ParseTree(body []byte, algo oid.Algorithm) (*Tree, error) {
-	if algo.Size() == 0 {
-		return nil, fmt.Errorf("object: tree: invalid hash algorithm %q", algo)
-	}
-
 	var entries []TreeEntry
 	i := 0
 	for i < len(body) {
--