@@ -6,6 +6,8 @@ package git
6
6
7
7
import (
8
8
"io/ioutil"
9
+
10
+ "gopkg.in/src-d/go-git.v4/plumbing/object"
9
11
)
10
12
11
13
// 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 {
25
27
return err
26
28
}
27
29
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
+ }
31
48
}
32
49
33
- blob := entry .Blob ()
34
- dataRc , err := blob .DataAsync ()
50
+ blob := file .Blob
51
+ dataRc , err := blob .Reader ()
35
52
if err != nil {
36
53
return err
37
54
}
@@ -43,26 +60,21 @@ func GetNote(repo *Repository, commitID string, note *Note) error {
43
60
}
44
61
note .Message = d
45
62
46
- commit , err := repo .gogitRepo .CommitObject (notes .ID )
47
- if err != nil {
48
- return err
49
- }
50
-
51
63
commitNodeIndex , commitGraphFile := repo .CommitNodeIndex ()
52
64
if commitGraphFile != nil {
53
65
defer commitGraphFile .Close ()
54
66
}
55
67
56
- commitNode , err := commitNodeIndex .Get (commit . Hash )
68
+ commitNode , err := commitNodeIndex .Get (notes . ID )
57
69
if err != nil {
58
- return nil
70
+ return err
59
71
}
60
72
61
- lastCommits , err := getLastCommitForPaths (commitNode , "" , []string {commitID })
73
+ lastCommits , err := getLastCommitForPaths (commitNode , "" , []string {path })
62
74
if err != nil {
63
75
return err
64
76
}
65
- note .Commit = convertCommit (lastCommits [commitID ])
77
+ note .Commit = convertCommit (lastCommits [path ])
66
78
67
79
return nil
68
80
}
0 commit comments