diff options
| author | 2026-06-07 12:36:30 +0000 | |
|---|---|---|
| committer | 2026-06-07 12:36:30 +0000 | |
| commit | 8a1c175d2c903ac27eecd5ba07c59e59005f589a (patch) | |
| tree | cff453f4549bdd60e7bb8e5c72ccf53032ed9689 /object/tree/insert.go | |
| parent | REFACTOR: blob, tag, and tree are done! (diff) | |
| signature | No signature | |
object/tree: Add Find
Diffstat (limited to 'object/tree/insert.go')
| -rw-r--r-- | object/tree/insert.go | 19 |
1 files changed, 1 insertions, 18 deletions
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 == "" { |
