src-d / go-git

Project has been moved to: https://github.com/go-git/go-git
https://github.com/go-git/go-git
Apache License 2.0
4.9k stars 540 forks source link

Made idxfile safe for concurrent access so that users can run blame concurrently #1270

Open lxjhk opened 4 years ago

lxjhk commented 4 years ago

Signed-off-by: lxjhk lxjpub@gmail.com

Issue Addressed

Git blame takes a long time to run. A natural optimization is to run git blame on multiple files concurrently. However, the existing implementation for idxfile uses Go's standard map data type which will cause "concurrent read and write to a map" run-time panic because of race conditions.

Ref Issues

https://github.com/zricethezav/gitleaks/issues/124#issue-373459034 https://github.com/src-d/go-git/issues/457#issue-239967754

Changes Made

Changed map[int64]plumbing.Hash to sync.Map