diff --git a/.github/workflows/git.yml b/.github/workflows/git.yml index b10b14b23..84100539d 100644 --- a/.github/workflows/git.yml +++ b/.github/workflows/git.yml @@ -38,3 +38,8 @@ jobs: - name: Test run: make test-coverage + + - name: Build go-git with CGO disabled + run: go build ./... + env: + CGO_ENABLED: 0 diff --git a/go.mod b/go.mod index 5903873de..9672762ea 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 github.com/jessevdk/go-flags v1.5.0 github.com/kevinburke/ssh_config v1.2.0 - github.com/pjbgf/sha1cd v0.2.1 + github.com/pjbgf/sha1cd v0.2.3 github.com/pkg/errors v0.9.1 // indirect github.com/sergi/go-diff v1.1.0 github.com/skeema/knownhosts v1.1.0 diff --git a/go.sum b/go.sum index f632d700f..b859ce808 100644 --- a/go.sum +++ b/go.sum @@ -45,8 +45,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/pjbgf/sha1cd v0.2.1 h1:g8hkbV5Cpj24YVSZ4MCAnecIBwsg0bQrvP6xkPUVit4= -github.com/pjbgf/sha1cd v0.2.1/go.mod h1:HOK9QrgzdHpbc2Kzip0Q1yi3M2MFGPADtR6HjG65m5M= +github.com/pjbgf/sha1cd v0.2.3 h1:uKQP/7QOzNtKYH7UTohZLcjF5/55EnTw0jO/Ru4jZwI= +github.com/pjbgf/sha1cd v0.2.3/go.mod h1:HOK9QrgzdHpbc2Kzip0Q1yi3M2MFGPADtR6HjG65m5M= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/plumbing/format/idxfile/idxfile.go b/plumbing/format/idxfile/idxfile.go index 45bb594c1..6cc2e96a7 100644 --- a/plumbing/format/idxfile/idxfile.go +++ b/plumbing/format/idxfile/idxfile.go @@ -4,6 +4,7 @@ import ( "bytes" "io" "sort" + "sync" encbin "encoding/binary" @@ -58,6 +59,7 @@ type MemoryIndex struct { offsetHash map[int64]plumbing.Hash offsetHashIsFull bool + offsetHashMutex sync.RWMutex } var _ Index = (*MemoryIndex)(nil) @@ -130,7 +132,9 @@ func (idx *MemoryIndex) FindOffset(h plumbing.Hash) (int64, error) { if idx.offsetHash == nil { idx.offsetHash = make(map[int64]plumbing.Hash) } + idx.offsetHashMutex.Lock() idx.offsetHash[int64(offset)] = h + idx.offsetHashMutex.Unlock() } return int64(offset), nil @@ -173,7 +177,10 @@ func (idx *MemoryIndex) FindHash(o int64) (plumbing.Hash, error) { var ok bool if idx.offsetHash != nil { - if hash, ok = idx.offsetHash[o]; ok { + idx.offsetHashMutex.RLock() + hash, ok = idx.offsetHash[o] + idx.offsetHashMutex.RUnlock() + if ok { return hash, nil } } @@ -184,7 +191,9 @@ func (idx *MemoryIndex) FindHash(o int64) (plumbing.Hash, error) { return plumbing.ZeroHash, err } + idx.offsetHashMutex.RLock() hash, ok = idx.offsetHash[o] + idx.offsetHashMutex.RUnlock() } if !ok { @@ -206,6 +215,7 @@ func (idx *MemoryIndex) genOffsetHash() error { var hash plumbing.Hash i := uint32(0) + idx.offsetHashMutex.Lock() for firstLevel, fanoutValue := range idx.Fanout { mappedFirstLevel := idx.FanoutMapping[firstLevel] for secondLevel := uint32(0); i < fanoutValue; i++ { @@ -215,6 +225,7 @@ func (idx *MemoryIndex) genOffsetHash() error { secondLevel++ } } + idx.offsetHashMutex.Unlock() return nil } diff --git a/plumbing/format/packfile/parser.go b/plumbing/format/packfile/parser.go index 22e8810d1..8ded21a61 100644 --- a/plumbing/format/packfile/parser.go +++ b/plumbing/format/packfile/parser.go @@ -237,6 +237,15 @@ func (p *Parser) indexObjects() error { return err } + // move children of placeholder parent into actual parent in case this was + // a non-external delta reference + if placeholder, ok := p.oiByHash[sha1]; ok { + ota.Children = placeholder.Children + for _, c := range ota.Children { + c.Parent = ota + } + } + ota.SHA1 = sha1 p.oiByHash[ota.SHA1] = ota }