diff options
Diffstat (limited to 'plumbing/format/packfile/delta_index.go')
-rw-r--r-- | plumbing/format/packfile/delta_index.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/plumbing/format/packfile/delta_index.go b/plumbing/format/packfile/delta_index.go index fad9dc8..349bedf 100644 --- a/plumbing/format/packfile/delta_index.go +++ b/plumbing/format/packfile/delta_index.go @@ -19,7 +19,19 @@ func (idx *deltaIndex) init(buf []byte) { idx.copyEntries(scanner) } +// findMatch returns the offset of src where the block starting at tgtOffset +// is and the length of the match. A length of 0 means there was no match. A +// length of -1 means the src length is lower than the blksz and whatever +// other positive length is the length of the match in bytes. func (idx *deltaIndex) findMatch(src, tgt []byte, tgtOffset int) (srcOffset, l int) { + if len(tgt) < tgtOffset+s { + return 0, len(tgt) - tgtOffset + } + + if len(src) < blksz { + return 0, -1 + } + if len(tgt) >= tgtOffset+s && len(src) >= blksz { h := hashBlock(tgt, tgtOffset) tIdx := h & idx.mask @@ -36,6 +48,17 @@ func (idx *deltaIndex) findMatch(src, tgt []byte, tgtOffset int) (srcOffset, l i return } +func matchLength(src, tgt []byte, otgt, osrc int) (l int) { + lensrc := len(src) + lentgt := len(tgt) + for (osrc < lensrc && otgt < lentgt) && src[osrc] == tgt[otgt] { + l++ + osrc++ + otgt++ + } + return +} + func countEntries(scan *deltaIndexScanner) (cnt int) { // Figure out exactly how many entries we need. As we do the // enumeration truncate any delta chains longer than what we |