2020-12-17 19:30:47 +05:30
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-17 19:30:47 +05:30
|
|
|
|
2021-08-24 22:17:09 +05:30
|
|
|
//go:build !gogit
|
2020-12-17 19:30:47 +05:30
|
|
|
|
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
2021-06-07 05:14:58 +05:30
|
|
|
"context"
|
2020-12-17 19:30:47 +05:30
|
|
|
)
|
|
|
|
|
2022-07-25 21:09:42 +05:30
|
|
|
// CacheCommit will cache the commit from the gitRepository
|
|
|
|
func (c *Commit) CacheCommit(ctx context.Context) error {
|
|
|
|
if c.repo.LastCommitCache == nil {
|
2020-12-17 19:30:47 +05:30
|
|
|
return nil
|
|
|
|
}
|
2022-07-25 21:09:42 +05:30
|
|
|
return c.recursiveCache(ctx, &c.Tree, "", 1)
|
2020-12-17 19:30:47 +05:30
|
|
|
}
|
|
|
|
|
2022-07-25 21:09:42 +05:30
|
|
|
func (c *Commit) recursiveCache(ctx context.Context, tree *Tree, treePath string, level int) error {
|
2020-12-17 19:30:47 +05:30
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2022-07-25 21:09:42 +05:30
|
|
|
_, err = WalkGitLog(ctx, c.repo, c, treePath, entryPaths...)
|
2020-12-17 19:30:47 +05:30
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-08 18:38:22 +05:30
|
|
|
for _, treeEntry := range entries {
|
2021-06-30 01:42:43 +05:30
|
|
|
// entryMap won't contain "" therefore skip this.
|
2021-10-08 18:38:22 +05:30
|
|
|
if treeEntry.IsDir() {
|
|
|
|
subTree, err := tree.SubTree(treeEntry.Name())
|
2020-12-17 19:30:47 +05:30
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-07-25 21:09:42 +05:30
|
|
|
if err := c.recursiveCache(ctx, subTree, treeEntry.Name(), level-1); err != nil {
|
2020-12-17 19:30:47 +05:30
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|