Skip to content

Commit

Permalink
fix data race.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav committed Jul 29, 2023
1 parent 10b6e28 commit c6fa8f0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/sources/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"runtime"
"strconv"
"strings"
"sync/atomic"
"time"

diskbufferreader "github.com/bill-rich/disk-buffer-reader"
Expand Down Expand Up @@ -56,7 +57,7 @@ type Git struct {
}

type metrics struct {
commitsScanned int
commitsScanned uint64
}

func NewGit(sourceType sourcespb.SourceType, jobID, sourceID int64, sourceName string, verify bool, concurrency int,
Expand Down Expand Up @@ -344,8 +345,8 @@ func CloneRepoUsingSSH(ctx context.Context, gitUrl string, args ...string) (stri
return CloneRepo(ctx, userInfo, gitUrl, args...)
}

func (s *Git) CommitsScanned() int {
return s.metrics.commitsScanned
func (s *Git) CommitsScanned() uint64 {
return atomic.LoadUint64(&s.metrics.commitsScanned)
}

func (s *Git) ScanCommits(ctx context.Context, repo *git.Repository, path string, scanOptions *ScanOptions, chunksChan chan *sources.Chunk) error {
Expand Down Expand Up @@ -380,7 +381,7 @@ func (s *Git) ScanCommits(ctx context.Context, repo *git.Repository, path string
break
}
depth++
s.metrics.commitsScanned++
atomic.AddUint64(&s.metrics.commitsScanned, 1)
logger.V(5).Info("scanning commit", "commit", commit.Hash)
for _, diff := range commit.Diffs {
if !scanOptions.Filter.Pass(diff.PathB) {
Expand Down

0 comments on commit c6fa8f0

Please sign in to comment.