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

Method encodeEntryNameV4

plumbing/format/index/encoder.go:160–182  ·  view source on GitHub ↗
(entry *Entry)

Source from the content-addressed store, hash-verified

158}
159
160func (e *Encoder) encodeEntryNameV4(entry *Entry) error {
161 // V4 prefix compression: find the longest common prefix between the
162 // previous entry's name and the current one. The strip length tells
163 // the decoder how many bytes to remove from the end of the previous
164 // name, and the suffix is the remainder of the current name.
165 prefix := 0
166 if e.lastEntry != nil {
167 prefix = commonPrefixLen(e.lastEntry.Name, entry.Name)
168 }
169 stripLen := 0
170 if e.lastEntry != nil {
171 stripLen = len(e.lastEntry.Name) - prefix
172 }
173
174 e.lastEntry = entry
175
176 if err := binary.WriteVariableWidthInt(e.w, int64(stripLen)); err != nil {
177 return err
178 }
179
180 suffix := entry.Name[prefix:]
181 return binary.Write(e.w, append([]byte(suffix), '\x00'))
182}
183
184// commonPrefixLen returns the length of the longest common byte prefix
185// between a and b.

Callers 1

encodeEntryMethod · 0.95

Calls 3

WriteVariableWidthIntFunction · 0.92
WriteFunction · 0.92
commonPrefixLenFunction · 0.85

Tested by

no test coverage detected