1
// Copyright 2019 The Gitea Authors. All rights reserved.
2
// SPDX-License-Identifier: MIT
13
"code.gitea.io/gitea/modules/log"
16
// GetNote retrieves the git-notes data for a given commit.
17
// FIXME: Add LastCommitCache support
18
func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note) error {
19
log.Trace("Searching for git note corresponding to the commit %q in the repository %q", commitID, repo.Path)
20
notes, err := repo.GetCommit(NotesRef)
22
if IsErrNotExist(err) {
25
log.Error("Unable to get commit from ref %q. Error: %v", NotesRef, err)
32
log.Trace("Found tree with ID %q while searching for git note corresponding to the commit %q", tree.ID, commitID)
35
originalCommitID := commitID
36
for len(commitID) > 2 {
37
entry, err = tree.GetTreeEntryByPath(commitID)
42
if IsErrNotExist(err) {
43
tree, err = tree.SubTree(commitID[0:2])
44
path += commitID[0:2] + "/"
45
commitID = commitID[2:]
48
// Err may have been updated by the SubTree we need to recheck if it's again an ErrNotExist
49
if !IsErrNotExist(err) {
50
log.Error("Unable to find git note corresponding to the commit %q. Error: %v", originalCommitID, err)
57
dataRc, err := blob.DataAsync()
59
log.Error("Unable to read blob with ID %q. Error: %v", blob.ID, err)
68
d, err := io.ReadAll(dataRc)
70
log.Error("Unable to read blob with ID %q. Error: %v", blob.ID, err)
78
if idx := strings.LastIndex(path, "/"); idx > -1 {
83
lastCommits, err := GetLastCommitForPaths(ctx, notes, treePath, []string{path})
85
log.Error("Unable to get the commit for the path %q. Error: %v", treePath, err)
88
note.Commit = lastCommits[path]