Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #565 from strib/delta-sliding-window
Browse files Browse the repository at this point in the history
plumbing: use sliding window in delta calculations, like git CL
  • Loading branch information
mcuadros authored Aug 28, 2017
2 parents bff1d06 + cdddb7a commit cb32722
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion plumbing/format/packfile/delta_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
)

const (
// How far back in the sorted list to search for deltas. 10 is
// the default in command line git.
deltaWindowSize = 10
// deltas based on deltas, how many steps we can do.
// 50 is the default value used in JGit
maxDepth = int64(50)
Expand Down Expand Up @@ -184,7 +187,7 @@ func (dw *deltaSelector) walk(objectsToPack []*ObjectToPack) error {
continue
}

for j := i - 1; j >= 0; j-- {
for j := i - 1; j >= 0 && i-j < deltaWindowSize; j-- {
base := objectsToPack[j]
// Objects must use only the same type as their delta base.
// Since objectsToPack is sorted by type and size, once we find
Expand Down
19 changes: 19 additions & 0 deletions plumbing/format/packfile/delta_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,25 @@ func (s *DeltaSelectorSuite) TestObjectsToPack(c *C) {
c.Assert(otp[2].Original, Equals, s.store.Objects[s.hashes["o3"]])
c.Assert(otp[2].IsDelta(), Equals, true)
c.Assert(otp[2].Depth, Equals, 2)

// Check that objects outside of the sliding window don't produce
// a delta.
hashes = make([]plumbing.Hash, 0, deltaWindowSize+2)
hashes = append(hashes, s.hashes["base"])
for i := 0; i < deltaWindowSize; i++ {
hashes = append(hashes, s.hashes["smallTarget"])
}
hashes = append(hashes, s.hashes["target"])

// Don't sort so we can easily check the sliding window without
// creating a bunch of new objects.
otp, err = s.ds.objectsToPack(hashes)
c.Assert(err, IsNil)
err = s.ds.walk(otp)
c.Assert(err, IsNil)
c.Assert(len(otp), Equals, deltaWindowSize+2)
targetIdx := len(otp) - 1
c.Assert(otp[targetIdx].IsDelta(), Equals, false)
}

func (s *DeltaSelectorSuite) TestMaxDepth(c *C) {
Expand Down

0 comments on commit cb32722

Please sign in to comment.