Skip to content

Commit 4a8637f

Browse files
committed
Fix gogit build
1 parent 38b8d17 commit 4a8637f

File tree

9 files changed

+43
-39
lines changed

9 files changed

+43
-39
lines changed

modules/git/commit_convert_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func convertPGPSignature(c *object.Commit) *CommitSignature {
6666
func convertCommit(c *object.Commit) *Commit {
6767
return &Commit{
6868
ID: ParseGogitHash(c.Hash),
69+
TreeID: ParseGogitHash(c.TreeHash),
6970
CommitMessage: c.Message,
7071
Committer: &c.Committer,
7172
Author: &c.Author,

modules/git/commit_info_gogit.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import (
1616
)
1717

1818
// GetCommitsInfo gets information of all commits that are corresponding to these entries
19-
func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *Commit, treePath string) ([]CommitInfo, *Commit, error) {
19+
func (tes Entries) GetCommitsInfo(ctx context.Context, gitRepo *Repository, repoLink string, commit *Commit, treePath string) ([]CommitInfo, *Commit, error) {
2020
entryPaths := make([]string, len(tes)+1)
2121
// Get the commit for the treePath itself
2222
entryPaths[0] = ""
2323
for i, entry := range tes {
2424
entryPaths[i+1] = entry.Name()
2525
}
2626

27-
commitNodeIndex, commitGraphFile := commit.repo.CommitNodeIndex()
27+
commitNodeIndex, commitGraphFile := gitRepo.CommitNodeIndex()
2828
if commitGraphFile != nil {
2929
defer commitGraphFile.Close()
3030
}
@@ -35,14 +35,14 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
3535
}
3636

3737
var revs map[string]*Commit
38-
if commit.repo.LastCommitCache != nil {
38+
if gitRepo.LastCommitCache != nil {
3939
var unHitPaths []string
40-
revs, unHitPaths, err = getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths, commit.repo.LastCommitCache)
40+
revs, unHitPaths, err = getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths, gitRepo.LastCommitCache)
4141
if err != nil {
4242
return nil, nil, err
4343
}
4444
if len(unHitPaths) > 0 {
45-
revs2, err := GetLastCommitForPaths(ctx, commit.repo.LastCommitCache, c, treePath, unHitPaths)
45+
revs2, err := GetLastCommitForPaths(ctx, gitRepo.LastCommitCache, c, treePath, unHitPaths)
4646
if err != nil {
4747
return nil, nil, err
4848
}
@@ -58,7 +58,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
5858
return nil, nil, err
5959
}
6060

61-
commit.repo.gogitStorage.Close()
61+
gitRepo.gogitStorage.Close()
6262

6363
commitsInfo := make([]CommitInfo, len(tes))
6464
for i, entry := range tes {
@@ -73,7 +73,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
7373

7474
// If the entry is a submodule, add a submodule file for this
7575
if entry.IsSubModule() {
76-
commitsInfo[i].SubmoduleFile, err = GetCommitInfoSubmoduleFile(repoLink, path.Join(treePath, entry.Name()), commit, entry.ID)
76+
commitsInfo[i].SubmoduleFile, err = GetCommitInfoSubmoduleFile(gitRepo, repoLink, path.Join(treePath, entry.Name()), commit.TreeID, entry.ID)
7777
if err != nil {
7878
return nil, nil, err
7979
}
@@ -84,11 +84,8 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
8484
// get it for free during the tree traversal and it's used for listing
8585
// pages to display information about newest commit for a given path.
8686
var treeCommit *Commit
87-
var ok bool
8887
if treePath == "" {
8988
treeCommit = commit
90-
} else if treeCommit, ok = revs[""]; ok {
91-
treeCommit.repo = commit.repo
9289
}
9390
return commitsInfo, treeCommit, nil
9491
}

modules/git/last_commit_cache_gogit.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ import (
1313
)
1414

1515
// CacheCommit will cache the commit from the gitRepository
16-
func (c *Commit) CacheCommit(ctx context.Context) error {
17-
if c.repo.LastCommitCache == nil {
16+
func (repo *Repository) CacheCommit(ctx context.Context, c *Commit) error {
17+
if repo.LastCommitCache == nil {
1818
return nil
1919
}
20-
commitNodeIndex, _ := c.repo.CommitNodeIndex()
20+
commitNodeIndex, _ := repo.CommitNodeIndex()
2121

2222
index, err := commitNodeIndex.Get(plumbing.Hash(c.ID.RawValue()))
2323
if err != nil {
2424
return err
2525
}
2626

27-
return c.recursiveCache(ctx, index, &c.Tree, "", 1)
27+
return repo.recursiveCache(ctx, c, index, NewTree(repo, c.TreeID), "", 1)
2828
}
2929

30-
func (c *Commit) recursiveCache(ctx context.Context, index cgobject.CommitNode, tree *Tree, treePath string, level int) error {
30+
func (repo *Repository) recursiveCache(ctx context.Context, c *Commit, index cgobject.CommitNode, tree *Tree, treePath string, level int) error {
3131
if level == 0 {
3232
return nil
3333
}
@@ -44,7 +44,7 @@ func (c *Commit) recursiveCache(ctx context.Context, index cgobject.CommitNode,
4444
entryMap[entry.Name()] = entry
4545
}
4646

47-
commits, err := GetLastCommitForPaths(ctx, c.repo.LastCommitCache, index, treePath, entryPaths)
47+
commits, err := GetLastCommitForPaths(ctx, repo.LastCommitCache, index, treePath, entryPaths)
4848
if err != nil {
4949
return err
5050
}
@@ -55,7 +55,7 @@ func (c *Commit) recursiveCache(ctx context.Context, index cgobject.CommitNode,
5555
if err != nil {
5656
return err
5757
}
58-
if err := c.recursiveCache(ctx, index, subTree, entry, level-1); err != nil {
58+
if err := repo.recursiveCache(ctx, c, index, subTree, entry, level-1); err != nil {
5959
return err
6060
}
6161
}

modules/git/notes_gogit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
3030

3131
remainingCommitID := commitID
3232
path := ""
33-
currentTree := notes.Tree.gogitTree
33+
tree := NewTree(repo, notes.TreeID)
34+
currentTree := tree.gogitTree
3435
log.Trace("Found tree with ID %q while searching for git note corresponding to the commit %q", currentTree.Entries[0].Name, commitID)
3536
var file *object.File
3637
for len(remainingCommitID) > 2 {

modules/git/repo_commit_gogit.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,5 @@ func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {
103103
return nil, err
104104
}
105105

106-
commit := convertCommit(gogitCommit)
107-
commit.repo = repo
108-
109-
tree, err := gogitCommit.Tree()
110-
if err != nil {
111-
return nil, err
112-
}
113-
114-
commit.Tree.ID = ParseGogitHash(tree.Hash)
115-
commit.Tree.gogitTree = tree
116-
117-
return commit, nil
106+
return convertCommit(gogitCommit), nil
118107
}

modules/git/tree.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ import (
1212
"code.gitea.io/gitea/modules/util"
1313
)
1414

15-
// NewTree create a new tree according the repository and tree id
16-
func NewTree(repo *Repository, id ObjectID) *Tree {
17-
return &Tree{
18-
ID: id,
19-
repo: repo,
20-
}
21-
}
22-
2315
// SubTree get a subtree by the sub dir path
2416
func (t *Tree) SubTree(rpath string) (*Tree, error) {
2517
if len(rpath) == 0 {

modules/git/tree_gogit.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ type Tree struct {
2323

2424
// parent tree
2525
ptree *Tree
26+
27+
submoduleCache *ObjectCache[*SubModule]
28+
}
29+
30+
// NewTree create a new tree according the repository and tree id
31+
func NewTree(repo *Repository, id ObjectID) *Tree {
32+
tree, err := object.GetTree(repo.gogitRepo.Storer, plumbing.Hash(id.RawValue()))
33+
if err != nil {
34+
return nil
35+
}
36+
37+
return &Tree{
38+
ID: id,
39+
repo: repo,
40+
gogitTree: tree,
41+
}
2642
}
2743

2844
func (t *Tree) loadTreeObject() error {

modules/git/tree_nogogit.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ type Tree struct {
2828
submoduleCache *ObjectCache[*SubModule]
2929
}
3030

31+
// NewTree create a new tree according the repository and tree id
32+
func NewTree(repo *Repository, id ObjectID) *Tree {
33+
return &Tree{
34+
ID: id,
35+
repo: repo,
36+
}
37+
}
38+
3139
// ListEntries returns all entries of current tree.
3240
func (t *Tree) ListEntries() (Entries, error) {
3341
if t.entriesParsed {

routers/web/repo/wiki.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
369369
ctx.ServerError("CommitsByFileAndRange", err)
370370
return nil, nil
371371
}
372-
ctx.Data["Commits"], err = git_service.ConvertFromGitCommit(ctx, commitsHistory, ctx.Repo.Repository, ctx.Repo.GitRepo)
372+
ctx.Data["Commits"], err = git_service.ConvertFromGitCommit(ctx, commitsHistory, ctx.Repo.Repository, wikiGitRepo)
373373
if err != nil {
374374
ctx.ServerError("ConvertFromGitCommit", err)
375375
return nil, nil

0 commit comments

Comments
 (0)