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