This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 8
8
)
9
9
10
10
const (
11
+ // How far back in the sorted list to search for deltas. 10 is
12
+ // the default in command line git.
13
+ deltaWindowSize = 10
11
14
// deltas based on deltas, how many steps we can do.
12
15
// 50 is the default value used in JGit
13
16
maxDepth = int64 (50 )
@@ -184,7 +187,7 @@ func (dw *deltaSelector) walk(objectsToPack []*ObjectToPack) error {
184
187
continue
185
188
}
186
189
187
- for j := i - 1 ; j >= 0 ; j -- {
190
+ for j := i - 1 ; j >= 0 && i - j < deltaWindowSize ; j -- {
188
191
base := objectsToPack [j ]
189
192
// Objects must use only the same type as their delta base.
190
193
// Since objectsToPack is sorted by type and size, once we find
Original file line number Diff line number Diff line change @@ -196,6 +196,25 @@ func (s *DeltaSelectorSuite) TestObjectsToPack(c *C) {
196
196
c .Assert (otp [2 ].Original , Equals , s .store .Objects [s .hashes ["o3" ]])
197
197
c .Assert (otp [2 ].IsDelta (), Equals , true )
198
198
c .Assert (otp [2 ].Depth , Equals , 2 )
199
+
200
+ // Check that objects outside of the sliding window don't produce
201
+ // a delta.
202
+ hashes = make ([]plumbing.Hash , 0 , deltaWindowSize + 2 )
203
+ hashes = append (hashes , s .hashes ["base" ])
204
+ for i := 0 ; i < deltaWindowSize ; i ++ {
205
+ hashes = append (hashes , s .hashes ["smallTarget" ])
206
+ }
207
+ hashes = append (hashes , s .hashes ["target" ])
208
+
209
+ // Don't sort so we can easily check the sliding window without
210
+ // creating a bunch of new objects.
211
+ otp , err = s .ds .objectsToPack (hashes )
212
+ c .Assert (err , IsNil )
213
+ err = s .ds .walk (otp )
214
+ c .Assert (err , IsNil )
215
+ c .Assert (len (otp ), Equals , deltaWindowSize + 2 )
216
+ targetIdx := len (otp ) - 1
217
+ c .Assert (otp [targetIdx ].IsDelta (), Equals , false )
199
218
}
200
219
201
220
func (s * DeltaSelectorSuite ) TestMaxDepth (c * C ) {
You can’t perform that action at this time.
0 commit comments