diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-10-11 10:27:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-10-11 10:27:00 +0000 |
commit | 65aa53fc52ff15efe54df4147564828d535837f8 (patch) | |
tree | 31c51dad04fdcca80e6d3043c8bd49d2f1a51f83 /modules/git/tree_blob.go | |
parent | Initial commit. (diff) | |
download | forgejo-65aa53fc52ff15efe54df4147564828d535837f8.tar.xz forgejo-65aa53fc52ff15efe54df4147564828d535837f8.zip |
Adding upstream version 8.0.3.HEADupstream/8.0.3upstreamdebian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'modules/git/tree_blob.go')
-rw-r--r-- | modules/git/tree_blob.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/modules/git/tree_blob.go b/modules/git/tree_blob.go new file mode 100644 index 00000000..e60c1f91 --- /dev/null +++ b/modules/git/tree_blob.go @@ -0,0 +1,40 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. +// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import "strings" + +// GetBlobByPath get the blob object according the path +func (t *Tree) GetBlobByPath(relpath string) (*Blob, error) { + entry, err := t.GetTreeEntryByPath(relpath) + if err != nil { + return nil, err + } + + if !entry.IsDir() && !entry.IsSubModule() { + return entry.Blob(), nil + } + + return nil, ErrNotExist{"", relpath} +} + +// GetBlobByFoldedPath returns the blob object at relpath, regardless of the +// case of relpath. If there are multiple files with the same case-insensitive +// name, the first one found will be returned. +func (t *Tree) GetBlobByFoldedPath(relpath string) (*Blob, error) { + entries, err := t.ListEntries() + if err != nil { + return nil, err + } + + for _, entry := range entries { + if strings.EqualFold(entry.Name(), relpath) { + return t.GetBlobByPath(entry.Name()) + } + } + + return nil, ErrNotExist{"", relpath} +} |