@@ -6,6 +6,8 @@ package git
66
77import (
88 "io/ioutil"
9+
10+ "gopkg.in/src-d/go-git.v4/plumbing/object"
911)
1012
1113// NotesRef is the git ref where Gitea will look for git-notes data.
@@ -25,13 +27,28 @@ func GetNote(repo *Repository, commitID string, note *Note) error {
2527 return err
2628 }
2729
28- entry , err := notes .GetTreeEntryByPath (commitID )
29- if err != nil {
30- return err
30+ remainingCommitID := commitID
31+ path := ""
32+ currentTree := notes .Tree .gogitTree
33+ var file * object.File
34+ for len (remainingCommitID ) > 2 {
35+ file , err = currentTree .File (remainingCommitID )
36+ if err == nil {
37+ path += remainingCommitID
38+ break
39+ }
40+ if err == object .ErrFileNotFound {
41+ currentTree , err = currentTree .Tree (remainingCommitID [0 :2 ])
42+ path += remainingCommitID [0 :2 ] + "/"
43+ remainingCommitID = remainingCommitID [2 :]
44+ }
45+ if err != nil {
46+ return err
47+ }
3148 }
3249
33- blob := entry .Blob ()
34- dataRc , err := blob .DataAsync ()
50+ blob := file .Blob
51+ dataRc , err := blob .Reader ()
3552 if err != nil {
3653 return err
3754 }
@@ -43,26 +60,21 @@ func GetNote(repo *Repository, commitID string, note *Note) error {
4360 }
4461 note .Message = d
4562
46- commit , err := repo .gogitRepo .CommitObject (notes .ID )
47- if err != nil {
48- return err
49- }
50-
5163 commitNodeIndex , commitGraphFile := repo .CommitNodeIndex ()
5264 if commitGraphFile != nil {
5365 defer commitGraphFile .Close ()
5466 }
5567
56- commitNode , err := commitNodeIndex .Get (commit . Hash )
68+ commitNode , err := commitNodeIndex .Get (notes . ID )
5769 if err != nil {
58- return nil
70+ return err
5971 }
6072
61- lastCommits , err := getLastCommitForPaths (commitNode , "" , []string {commitID })
73+ lastCommits , err := getLastCommitForPaths (commitNode , "" , []string {path })
6274 if err != nil {
6375 return err
6476 }
65- note .Commit = convertCommit (lastCommits [commitID ])
77+ note .Commit = convertCommit (lastCommits [path ])
6678
6779 return nil
6880}
0 commit comments