Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

upstream fixes: Delta references and Concurrency #13

Merged
merged 4 commits into from Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/git.yml
Expand Up @@ -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
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -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=
Expand Down
13 changes: 12 additions & 1 deletion plumbing/format/idxfile/idxfile.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io"
"sort"
"sync"

encbin "encoding/binary"

Expand Down Expand Up @@ -58,6 +59,7 @@ type MemoryIndex struct {

offsetHash map[int64]plumbing.Hash
offsetHashIsFull bool
offsetHashMutex sync.RWMutex
}

var _ Index = (*MemoryIndex)(nil)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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 {
Expand All @@ -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++ {
Expand All @@ -215,6 +225,7 @@ func (idx *MemoryIndex) genOffsetHash() error {
secondLevel++
}
}
idx.offsetHashMutex.Unlock()

return nil
}
Expand Down
9 changes: 9 additions & 0 deletions plumbing/format/packfile/parser.go
Expand Up @@ -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
}
Expand Down