mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.2 KiB
55 lines
1.2 KiB
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
//go:build !gogit
|
|
|
|
package git
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// CacheCommit will cache the commit from the gitRepository
|
|
func (c *Commit) CacheCommit(ctx context.Context) error {
|
|
if c.repo.LastCommitCache == nil {
|
|
return nil
|
|
}
|
|
return c.recursiveCache(ctx, &c.Tree, "", 1)
|
|
}
|
|
|
|
func (c *Commit) recursiveCache(ctx context.Context, tree *Tree, treePath string, level int) error {
|
|
if level == 0 {
|
|
return nil
|
|
}
|
|
|
|
entries, err := tree.ListEntries()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
entryPaths := make([]string, len(entries))
|
|
for i, entry := range entries {
|
|
entryPaths[i] = entry.Name()
|
|
}
|
|
|
|
_, err = WalkGitLog(ctx, c.repo, c, treePath, entryPaths...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, treeEntry := range entries {
|
|
// entryMap won't contain "" therefore skip this.
|
|
if treeEntry.IsDir() {
|
|
subTree, err := tree.SubTree(treeEntry.Name())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := c.recursiveCache(ctx, subTree, treeEntry.Name(), level-1); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|