MCPcopy
hub / github.com/go-git/go-git / buildTestPack

Function buildTestPack

plumbing/format/packfile/internal_test.go:76–110  ·  view source on GitHub ↗

buildTestPack assembles a pack with the given objects, returning the raw pack bytes. Object offsets are not exposed because the only caller does not need them.

(t *testing.T, objects ...testPackObject)

Source from the content-addressed store, hash-verified

74// pack bytes. Object offsets are not exposed because the only caller does
75// not need them.
76func buildTestPack(t *testing.T, objects ...testPackObject) []byte {
77 t.Helper()
78
79 var body bytes.Buffer
80 body.WriteString("PACK")
81 require.NoError(t, binary.Write(&body, binary.BigEndian, uint32(2)))
82 require.NoError(t, binary.Write(&body, binary.BigEndian, uint32(len(objects))))
83
84 offsets := make([]int64, 0, len(objects))
85 for _, obj := range objects {
86 offsets = append(offsets, int64(body.Len()))
87 declaredSize := obj.declaredSize
88 if declaredSize == 0 && len(obj.content) > 0 {
89 declaredSize = int64(len(obj.content))
90 }
91
92 writeTestObjectHeader(&body, obj.typ, declaredSize)
93 switch obj.typ {
94 case plumbing.REFDeltaObject:
95 body.Write(obj.reference[:])
96 case plumbing.OFSDeltaObject:
97 distance := obj.offsetDeltaDistance
98 if distance == -1 {
99 // Reference the immediately preceding object.
100 distance = offsets[len(offsets)-1] - offsets[len(offsets)-2]
101 }
102 require.NoError(t, gogitbinary.WriteVariableWidthInt(&body, distance))
103 }
104 body.Write(zlibCompress(t, obj.content))
105 }
106
107 sum := sha1.Sum(body.Bytes())
108 body.Write(sum[:])
109 return body.Bytes()
110}
111
112func writeTestObjectHeader(w io.ByteWriter, typ plumbing.ObjectType, size int64) {
113 remaining := uint64(size)

Callers 1

Calls 7

WriteFunction · 0.92
writeTestObjectHeaderFunction · 0.85
zlibCompressFunction · 0.85
SumMethod · 0.80
LenMethod · 0.45
WriteMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…