From 634eaec7b0abe83fd7765571bf30ab45856867eb Mon Sep 17 00:00:00 2001 From: ZauberNerd Date: Tue, 15 Mar 2022 17:02:30 +0000 Subject: [PATCH 1/4] plumbing: resolve non-external delta references In a self-contained pack file delta references might point to base objects stored later in the file. In this case we need to replace placeholders for external refs with the actual base object and update the children references. Fixes: #484 Co-authored-by: Markus Wolf --- plumbing/format/packfile/parser.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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 } From d0949a031704dd999a3760a2af65888df774a21a Mon Sep 17 00:00:00 2001 From: Dustin Date: Wed, 30 Sep 2020 18:43:29 -0700 Subject: [PATCH 2/4] Fix MemoryIndex concurrent map access --- plumbing/format/idxfile/idxfile.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 } From 8584a22132bddca3b67311c1776bddd6f906f7a2 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Fri, 2 Dec 2022 15:38:58 +0000 Subject: [PATCH 3/4] build: Add CI check for CGO_ENABLED=0 Some applications that depend on go-git may not need to build using CGO. The new test ensures no new regressions going forwards. Signed-off-by: Paulo Gomes --- .github/workflows/git.yml | 5 +++++ 1 file changed, 5 insertions(+) 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 From 3d60fbc9ab5d644962e56292585b80ef13894a64 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Sat, 3 Dec 2022 13:19:01 +0000 Subject: [PATCH 4/4] build: Bump github.com/pjbgf/sha1cd to v0.2.3 Fixes regression in which applications that depend on go-git could no longer build with CGO_ENABLED=0. Signed-off-by: Paulo Gomes --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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=