Make commit info cancelable (#16032)

* Make modules/context.Context a context.Context

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Simplify context calls

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Set the base context for requests to the HammerContext

Signed-off-by: Andrew Thornton <art27@cantab.net>

* pass context into get-last-commit

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Make commit_info cancellable

Signed-off-by: Andrew Thornton <art27@cantab.net>

* use context as context

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
zeripath 2021-06-07 00:44:58 +01:00 committed by GitHub
parent b6762e2306
commit 51775f65bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 57 additions and 35 deletions

View file

@ -7,6 +7,7 @@
package git
import (
"context"
"path"
"github.com/go-git/go-git/v5/plumbing/object"
@ -60,7 +61,7 @@ func (c *LastCommitCache) Get(ref, entryPath string) (interface{}, error) {
}
// CacheCommit will cache the commit from the gitRepository
func (c *LastCommitCache) CacheCommit(commit *Commit) error {
func (c *LastCommitCache) CacheCommit(ctx context.Context, commit *Commit) error {
commitNodeIndex, _ := commit.repo.CommitNodeIndex()
@ -69,10 +70,10 @@ func (c *LastCommitCache) CacheCommit(commit *Commit) error {
return err
}
return c.recursiveCache(index, &commit.Tree, "", 1)
return c.recursiveCache(ctx, index, &commit.Tree, "", 1)
}
func (c *LastCommitCache) recursiveCache(index cgobject.CommitNode, tree *Tree, treePath string, level int) error {
func (c *LastCommitCache) recursiveCache(ctx context.Context, index cgobject.CommitNode, tree *Tree, treePath string, level int) error {
if level == 0 {
return nil
}
@ -89,7 +90,7 @@ func (c *LastCommitCache) recursiveCache(index cgobject.CommitNode, tree *Tree,
entryMap[entry.Name()] = entry
}
commits, err := GetLastCommitForPaths(index, treePath, entryPaths)
commits, err := GetLastCommitForPaths(ctx, index, treePath, entryPaths)
if err != nil {
return err
}
@ -103,7 +104,7 @@ func (c *LastCommitCache) recursiveCache(index cgobject.CommitNode, tree *Tree,
if err != nil {
return err
}
if err := c.recursiveCache(index, subTree, entry, level-1); err != nil {
if err := c.recursiveCache(ctx, index, subTree, entry, level-1); err != nil {
return err
}
}