diff options
Diffstat (limited to 'packed_write_pack.go')
| -rw-r--r-- | packed_write_pack.go | 66 |
1 files changed, 8 insertions, 58 deletions
diff --git a/packed_write_pack.go b/packed_write_pack.go index 2d3eb4f6..504c1087 100644 --- a/packed_write_pack.go +++ b/packed_write_pack.go @@ -5,7 +5,6 @@ import ( "encoding/binary" "hash" "io" - "sort" "codeberg.org/lindenii/furgit/internal/zlib" ) @@ -311,12 +310,7 @@ func (repo *Repository) packWrite(w io.Writer, objects []Hash, opts packWriteOpt return Hash{}, ErrInvalidObject } - objInfos, err := repo.packBuildObjectList(objects, opts.EnableDeltas) - if err != nil { - return Hash{}, err - } - - pw, err := newPackWriter(w, repo.hashAlgo, uint32(len(objInfos))) + pw, err := newPackWriter(w, repo.hashAlgo, uint32(len(objects))) if err != nil { return Hash{}, err } @@ -341,16 +335,15 @@ func (repo *Repository) packWrite(w io.Writer, objects []Hash, opts packWriteOpt } } - for _, info := range objInfos { - ty, body, err := repo.ReadObjectTypeRaw(info.id) + for _, id := range objects { + ty, body, err := repo.ReadObjectTypeRaw(id) if err != nil { return Hash{}, err } obj := &objectToPack{ - id: info.id, + id: id, ty: ty, body: body, - size: info.size, inPack: true, } startOffset := pw.bytesWritten @@ -421,59 +414,16 @@ func (repo *Repository) seedDeltaCandidatesFromHaves(ctx *deltaContext, haves [] return err } candidate := &objectToPack{ - id: obj.ID, - ty: ty, - body: body, - size: len(body), - inPack: false, - preferred: true, + id: obj.ID, + ty: ty, + body: body, + inPack: false, } ctx.addCandidate(candidate) } return walk.Err() } -type packObjectInfo struct { - id Hash - ty ObjectType - size int - index int -} - -func (repo *Repository) packBuildObjectList(objects []Hash, enableDeltas bool) ([]packObjectInfo, error) { - if repo == nil { - return nil, ErrInvalidObject - } - infos := make([]packObjectInfo, 0, len(objects)) - for i, id := range objects { - ty, size, err := repo.ReadObjectTypeSize(id) - if err != nil { - return nil, err - } - infos = append(infos, packObjectInfo{ - id: id, - ty: ty, - size: int(size), - index: i, - }) - } - if !enableDeltas { - return infos, nil - } - sort.SliceStable(infos, func(i, j int) bool { - ai := infos[i] - aj := infos[j] - if ai.ty != aj.ty { - return ai.ty < aj.ty - } - if ai.size != aj.size { - return ai.size > aj.size - } - return ai.index < aj.index - }) - return infos, nil -} - type packWriteOptions struct { EnableDeltas bool EnableThinPack bool |
