Monorepo for Tangled tangled.org
2

Configure Feed

Select the types of activity you want to include in your feed.

1package gitea 2 3import ( 4 "context" 5 "fmt" 6 "path/filepath" 7 8 "github.com/go-git/go-git/v5/plumbing/object" 9) 10 11func GetEntry(ctx context.Context, repoPath, ref, path string) (*object.TreeEntry, error) { 12 if ref == "" { 13 ref = "HEAD" 14 } 15 16 head, err := GetCommit(ctx, repoPath, ref) 17 if err != nil { 18 return nil, fmt.Errorf("get head commit: %w", err) 19 } 20 21 return GetEntryFromCommit(ctx, repoPath, head, path) 22} 23 24func GetEntryFromCommit(ctx context.Context, repoPath string, commit *object.Commit, path string) (*object.TreeEntry, error) { 25 treePath := filepath.Dir(path) 26 name := filepath.Base(path) 27 28 // find subTree 29 subRev := commit.Hash.String() + "^{tree}" 30 if treePath != "." { 31 subRev = commit.Hash.String() + ":" + treePath 32 } 33 subTree, err := GetTree(ctx, repoPath, subRev) 34 if err != nil { 35 return nil, fmt.Errorf("get subtree %s: %w", subRev, err) 36 } 37 38 // find entry 39 entry, err := func(subTree *object.Tree) (*object.TreeEntry, error) { 40 for _, entry := range subTree.Entries { 41 if entry.Name == name { 42 return &entry, nil 43 } 44 } 45 return nil, fmt.Errorf("object doesn't exist") 46 }(subTree) 47 if err != nil { 48 return nil, fmt.Errorf("get file: %w", err) 49 } 50 51 return entry, nil 52}