Skip to content

Commit ac21d4f

Browse files
committed
Fix reading notes from nested trees
The GIT documentation for notes states "Permitted pathnames have the form ab/cd/ef/.../abcdef...: a sequence of directory names of two hexadecimal digits each followed by a filename with the rest of the object ID."
1 parent 187ae10 commit ac21d4f

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

modules/git/notes.go

+26-14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package git
66

77
import (
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
}

vendor/modules.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ github.com/willf/bitset
336336
github.com/xanzy/ssh-agent
337337
# github.com/yohcop/openid-go v0.0.0-20160914080427-2c050d2dae53
338338
github.com/yohcop/openid-go
339-
# golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586
339+
# golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
340340
golang.org/x/crypto/acme/autocert
341341
golang.org/x/crypto/argon2
342342
golang.org/x/crypto/bcrypt

0 commit comments

Comments
 (0)