Skip to content

Commit

Permalink
Make commit_info cancellable
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed May 30, 2021
1 parent a4839a0 commit 47c6c41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions modules/git/commit_info_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ func GetLastCommitForPaths(ctx context.Context, c cgobject.CommitNode, treePath
heap.Push(&commitAndPaths{c, paths, initialHashes})

for {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
cIn, ok := heap.Pop()
if !ok {
break
Expand Down
10 changes: 9 additions & 1 deletion modules/git/commit_info_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func GetLastCommitForPaths(ctx context.Context, commit *Commit, treePath string,

go func() {
stderr := strings.Builder{}
err := NewCommand("rev-list", "--format=%T", commit.ID.String()).RunInDirPipeline(commit.repo.Path, revListWriter, &stderr)
err := NewCommand("rev-list", "--format=%T", commit.ID.String()).SetParentContext(ctx).RunInDirPipeline(commit.repo.Path, revListWriter, &stderr)
if err != nil {
_ = revListWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
} else {
Expand Down Expand Up @@ -203,6 +203,11 @@ revListLoop:

treeReadingLoop:
for {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
_, _, size, err := ReadBatchLine(batchReader)
if err != nil {
return nil, err
Expand Down Expand Up @@ -322,6 +327,9 @@ revListLoop:
}
}
}
if scan.Err() != nil {
return nil, scan.Err()
}

commitsMap := make(map[string]*Commit, len(commits))
commitsMap[commit.ID.String()] = commit
Expand Down

0 comments on commit 47c6c41

Please sign in to comment.