From 8a1c175d2c903ac27eecd5ba07c59e59005f589a Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 7 Jun 2026 12:36:30 +0000 Subject: object/tree: Add Find --- object/tree/insert.go | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'object/tree/insert.go') diff --git a/object/tree/insert.go b/object/tree/insert.go index b5227938..5e519069 100644 --- a/object/tree/insert.go +++ b/object/tree/insert.go @@ -26,7 +26,7 @@ func (tree *Tree) Insert(entry Entry) error { return fmt.Errorf("%w: entry %q has invalid mode", ErrInvalidTree, entry.Name) } - if _, found := tree.find(entry.Name); found { + if _, found := tree.Find(entry.Name); found { return fmt.Errorf("%w: entry %q already exists", ErrInvalidTree, entry.Name) } @@ -41,23 +41,6 @@ func (tree *Tree) Insert(entry Entry) error { return nil } -// find returns the index of the entry with the given name, if present. -// -// A name conflicts whether stored as a blob-like or as a subtree entry, -// so both orderings are searched. -func (tree *Tree) find(name string) (int, bool) { - for _, searchIsTree := range [...]bool{true, false} { - index, ok := slices.BinarySearchFunc(tree.entries, name, func(existing Entry, target string) int { - return nameCompare(existing.Name, existing.Mode == mode.Directory, target, searchIsTree) - }) - if ok && tree.entries[index].Name == name { - return index, true - } - } - - return 0, false -} - // validateName checks that name is a structurally valid tree entry name. func validateName(name string) error { if name == "" { -- cgit v1.3.1-10-gc9f91