Skip to content

Commit 47c6c41

Browse files
committed
Make commit_info cancellable
Signed-off-by: Andrew Thornton <[email protected]>
1 parent a4839a0 commit 47c6c41

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

modules/git/commit_info_gogit.go

+5
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ func GetLastCommitForPaths(ctx context.Context, c cgobject.CommitNode, treePath
193193
heap.Push(&commitAndPaths{c, paths, initialHashes})
194194

195195
for {
196+
select {
197+
case <-ctx.Done():
198+
return nil, ctx.Err()
199+
default:
200+
}
196201
cIn, ok := heap.Pop()
197202
if !ok {
198203
break

modules/git/commit_info_nogogit.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func GetLastCommitForPaths(ctx context.Context, commit *Commit, treePath string,
137137

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

204204
treeReadingLoop:
205205
for {
206+
select {
207+
case <-ctx.Done():
208+
return nil, ctx.Err()
209+
default:
210+
}
206211
_, _, size, err := ReadBatchLine(batchReader)
207212
if err != nil {
208213
return nil, err
@@ -322,6 +327,9 @@ revListLoop:
322327
}
323328
}
324329
}
330+
if scan.Err() != nil {
331+
return nil, scan.Err()
332+
}
325333

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

0 commit comments

Comments
 (0)