diff options
| author | 2026-02-21 20:21:55 +0800 | |
|---|---|---|
| committer | 2026-02-21 20:21:55 +0800 | |
| commit | b480c5c4dfaddb9b137f50b1a7651e3bce2ecb98 (patch) | |
| tree | 4952eb430959bbfb5eb95fe0bbcf1675fff02d34 /objectstore/packed/delta_plan.go | |
| parent | objectstore/packed: Best-effort touchCandidate (diff) | |
| signature | No signature | |
objectstore/packed: Improve delta base caching
Diffstat (limited to 'objectstore/packed/delta_plan.go')
| -rw-r--r-- | objectstore/packed/delta_plan.go | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/objectstore/packed/delta_plan.go b/objectstore/packed/delta_plan.go index 07dd5c77..f1a3b9b0 100644 --- a/objectstore/packed/delta_plan.go +++ b/objectstore/packed/delta_plan.go @@ -8,76 +8,76 @@ import ( "codeberg.org/lindenii/furgit/objecttype" ) -// deltaFrame describes one delta payload to apply during reconstruction. -type deltaFrame struct { - // packName identifies where the delta payload lives. - packName string +// deltaNode describes one delta object in a reconstruction chain. +type deltaNode struct { + // loc identifies the delta object's pack location. + loc location // dataOffset points to the start of the delta zlib payload in pack. dataOffset int } -// deltaPlan describes how to reconstruct one requested object. -type deltaPlan struct { +// deltaChain describes how to reconstruct one requested object. +type deltaChain struct { // declaredSize is the target object's declared content size. declaredSize int64 // baseLoc points to the innermost base object. baseLoc location // baseType is the canonical object type resolved from baseLoc. baseType objecttype.Type - // frames contains deltas from target down toward base. - frames []deltaFrame + // deltas contains delta objects from target down toward base. + deltas []deltaNode } -// deltaPlanFor walks one object's chain and builds a delta reconstruction plan. -func (store *Store) deltaPlanFor(start location) (deltaPlan, error) { +// deltaBuildChain walks one object's chain and builds a reconstruction chain. +func (store *Store) deltaBuildChain(start location) (deltaChain, error) { visited := make(map[location]struct{}) current := start - var plan deltaPlan - plan.declaredSize = -1 + var chain deltaChain + chain.declaredSize = -1 for { if _, ok := visited[current]; ok { - return deltaPlan{}, fmt.Errorf("objectstore/packed: delta cycle while resolving object") + return deltaChain{}, fmt.Errorf("objectstore/packed: delta cycle while resolving object") } visited[current] = struct{}{} pack, meta, err := store.entryMetaAt(current) if err != nil { - return deltaPlan{}, err + return deltaChain{}, err } - if plan.declaredSize < 0 { + if chain.declaredSize < 0 { if packfmt.IsBaseObjectType(meta.ty) { - plan.declaredSize = meta.size + chain.declaredSize = meta.size } else { declaredSize, err := deltaDeclaredSizeAt(pack, meta.dataOffset) if err != nil { - return deltaPlan{}, err + return deltaChain{}, err } - plan.declaredSize = declaredSize + chain.declaredSize = declaredSize } } if packfmt.IsBaseObjectType(meta.ty) { - plan.baseLoc = current - plan.baseType = meta.ty - return plan, nil + chain.baseLoc = current + chain.baseType = meta.ty + return chain, nil } switch meta.ty { case objecttype.TypeRefDelta: - plan.frames = append(plan.frames, deltaFrame{ - packName: current.packName, + chain.deltas = append(chain.deltas, deltaNode{ + loc: current, dataOffset: meta.dataOffset, }) next, err := store.lookup(meta.baseRefID) if err != nil { - return deltaPlan{}, err + return deltaChain{}, err } current = next case objecttype.TypeOfsDelta: - plan.frames = append(plan.frames, deltaFrame{ - packName: current.packName, + chain.deltas = append(chain.deltas, deltaNode{ + loc: current, dataOffset: meta.dataOffset, }) current = location{ @@ -85,11 +85,11 @@ func (store *Store) deltaPlanFor(start location) (deltaPlan, error) { offset: meta.baseOfs, } case objecttype.TypeCommit, objecttype.TypeTree, objecttype.TypeBlob, objecttype.TypeTag: - return deltaPlan{}, fmt.Errorf("objectstore/packed: internal invariant violation for base type %d", meta.ty) + return deltaChain{}, fmt.Errorf("objectstore/packed: internal invariant violation for base type %d", meta.ty) case objecttype.TypeInvalid, objecttype.TypeFuture: - return deltaPlan{}, fmt.Errorf("objectstore/packed: unsupported pack type %d", meta.ty) + return deltaChain{}, fmt.Errorf("objectstore/packed: unsupported pack type %d", meta.ty) default: - return deltaPlan{}, fmt.Errorf("objectstore/packed: unsupported pack type %d", meta.ty) + return deltaChain{}, fmt.Errorf("objectstore/packed: unsupported pack type %d", meta.ty) } } } |
