Skip to content

Fix reading git notes from nested trees #8026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 12, 2019
40 changes: 26 additions & 14 deletions modules/git/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package git

import (
"io/ioutil"

"gopkg.in/src-d/go-git.v4/plumbing/object"
)

// NotesRef is the git ref where Gitea will look for git-notes data.
Expand All @@ -25,13 +27,28 @@ func GetNote(repo *Repository, commitID string, note *Note) error {
return err
}

entry, err := notes.GetTreeEntryByPath(commitID)
if err != nil {
return err
remainingCommitID := commitID
path := ""
currentTree := notes.Tree.gogitTree
var file *object.File
for len(remainingCommitID) > 2 {
file, err = currentTree.File(remainingCommitID)
if err == nil {
path += remainingCommitID
break
}
if err == object.ErrFileNotFound {
currentTree, err = currentTree.Tree(remainingCommitID[0:2])
path += remainingCommitID[0:2] + "/"
remainingCommitID = remainingCommitID[2:]
}
if err != nil {
return err
}
}

blob := entry.Blob()
dataRc, err := blob.DataAsync()
blob := file.Blob
dataRc, err := blob.Reader()
if err != nil {
return err
}
Expand All @@ -43,26 +60,21 @@ func GetNote(repo *Repository, commitID string, note *Note) error {
}
note.Message = d

commit, err := repo.gogitRepo.CommitObject(notes.ID)
if err != nil {
return err
}

commitNodeIndex, commitGraphFile := repo.CommitNodeIndex()
if commitGraphFile != nil {
defer commitGraphFile.Close()
}

commitNode, err := commitNodeIndex.Get(commit.Hash)
commitNode, err := commitNodeIndex.Get(notes.ID)
if err != nil {
return nil
return err
}

lastCommits, err := getLastCommitForPaths(commitNode, "", []string{commitID})
lastCommits, err := getLastCommitForPaths(commitNode, "", []string{path})
if err != nil {
return err
}
note.Commit = convertCommit(lastCommits[commitID])
note.Commit = convertCommit(lastCommits[path])

return nil
}
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ github.com/willf/bitset
github.com/xanzy/ssh-agent
# github.com/yohcop/openid-go v0.0.0-20160914080427-2c050d2dae53
github.com/yohcop/openid-go
# golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586
# golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
golang.org/x/crypto/acme/autocert
golang.org/x/crypto/argon2
golang.org/x/crypto/bcrypt
Expand Down