* 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." * Add test case * Fix new linestags/v1.10.0-rc1
import ( | import ( | ||||
"io/ioutil" | "io/ioutil" | ||||
"gopkg.in/src-d/go-git.v4/plumbing/object" | |||||
) | ) | ||||
// NotesRef is the git ref where Gitea will look for git-notes data. | // NotesRef is the git ref where Gitea will look for git-notes data. | ||||
return err | 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 { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
} | } | ||||
note.Message = d | note.Message = d | ||||
commit, err := repo.gogitRepo.CommitObject(notes.ID) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
commitNodeIndex, commitGraphFile := repo.CommitNodeIndex() | commitNodeIndex, commitGraphFile := repo.CommitNodeIndex() | ||||
if commitGraphFile != nil { | if commitGraphFile != nil { | ||||
defer commitGraphFile.Close() | defer commitGraphFile.Close() | ||||
} | } | ||||
commitNode, err := commitNodeIndex.Get(commit.Hash) | |||||
commitNode, err := commitNodeIndex.Get(notes.ID) | |||||
if err != nil { | if err != nil { | ||||
return nil | |||||
return err | |||||
} | } | ||||
lastCommits, err := getLastCommitForPaths(commitNode, "", []string{commitID}) | |||||
lastCommits, err := getLastCommitForPaths(commitNode, "", []string{path}) | |||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
note.Commit = convertCommit(lastCommits[commitID]) | |||||
note.Commit = convertCommit(lastCommits[path]) | |||||
return nil | return nil | ||||
} | } |
assert.Equal(t, []byte("Note contents\n"), note.Message) | assert.Equal(t, []byte("Note contents\n"), note.Message) | ||||
assert.Equal(t, "Vladimir Panteleev", note.Commit.Author.Name) | assert.Equal(t, "Vladimir Panteleev", note.Commit.Author.Name) | ||||
} | } | ||||
func TestGetNestedNotes(t *testing.T) { | |||||
repoPath := filepath.Join(testReposDir, "repo3_notes") | |||||
repo, err := OpenRepository(repoPath) | |||||
assert.NoError(t, err) | |||||
note := Note{} | |||||
err = GetNote(repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", ¬e) | |||||
assert.NoError(t, err) | |||||
assert.Equal(t, []byte("Note 2"), note.Message) | |||||
err = GetNote(repo, "ba0a96fa63532d6c5087ecef070b0250ed72fa47", ¬e) | |||||
assert.NoError(t, err) | |||||
assert.Equal(t, []byte("Note 1"), note.Message) | |||||
} |
2 |
ref: refs/heads/master |
[core] | |||||
repositoryformatversion = 0 | |||||
filemode = false | |||||
bare = false | |||||
logallrefupdates = true | |||||
symlinks = false | |||||
ignorecase = true |
Unnamed repository; edit this file 'description' to name the repository. |
0000000000000000000000000000000000000000 ba0a96fa63532d6c5087ecef070b0250ed72fa47 Filip Navara <filip.navara@gmail.com> 1567767895 +0200 commit (initial): 1 | |||||
ba0a96fa63532d6c5087ecef070b0250ed72fa47 3e668dbfac39cbc80a9ff9c61eb565d944453ba4 Filip Navara <filip.navara@gmail.com> 1567767909 +0200 commit: 2 |
0000000000000000000000000000000000000000 ba0a96fa63532d6c5087ecef070b0250ed72fa47 Filip Navara <filip.navara@gmail.com> 1567767895 +0200 commit (initial): 1 | |||||
ba0a96fa63532d6c5087ecef070b0250ed72fa47 3e668dbfac39cbc80a9ff9c61eb565d944453ba4 Filip Navara <filip.navara@gmail.com> 1567767909 +0200 commit: 2 |
xťŽ;Â0@™s | |||||
ďH•ă&v*!ÄÄČś4�JôŁ(p~ | |||||
G`|oxziťç©‘;´š3Đ –ÂČŢ÷6 ś$`¦"NRäŃşXlałiÍK�¨¨ĺŢ÷4rň$§\P0"yĚŁPQ'F_í±V¸NĎi�›ľµ*śĘ—şĺG—ű¬ÓłKë|ëY„eŔŽH�f·űfË™ÜăEm |
xќЌ;В0©}Љн‘"Зїu$„RQr‡•ЩK1F–Йщ1ЃnfЉчR-%w�Сzcбґ{д%7Аўh#Сx¶€ЙQ¤айfXС»?jѓKЮт®ґS#8ЙЧ¦зПЦ{ЎјM©–3М> †Ёќ…Ј6Z«QЗmзїФя8В |
3e668dbfac39cbc80a9ff9c61eb565d944453ba4 |
654c8b6b63c08bf37f638d3f521626b7fbbd4d37 |