@@ -39,10 +39,21 @@ type BundleList struct {
39
39
Bundles map [int64 ]Bundle
40
40
}
41
41
42
- func addBundleToList ( bundle Bundle , list * BundleList ) {
42
+ func ( list * BundleList ) addBundle ( bundle Bundle ) {
43
43
list .Bundles [bundle .CreationToken ] = bundle
44
44
}
45
45
46
+ func (list * BundleList ) sortedCreationTokens () []int64 {
47
+ keys := make ([]int64 , 0 , len (list .Bundles ))
48
+ for timestamp := range list .Bundles {
49
+ keys = append (keys , timestamp )
50
+ }
51
+
52
+ sort .Slice (keys , func (i , j int ) bool { return keys [i ] < keys [j ] })
53
+
54
+ return keys
55
+ }
56
+
46
57
type BundleProvider interface {
47
58
CreateInitialBundle (ctx context.Context , repo * core.Repository ) Bundle
48
59
CreateIncrementalBundle (ctx context.Context , repo * core.Repository , list * BundleList ) (* Bundle , error )
@@ -79,7 +90,7 @@ func (b *bundleProvider) CreateInitialBundle(ctx context.Context, repo *core.Rep
79
90
func (b * bundleProvider ) createDistinctBundle (repo * core.Repository , list * BundleList ) Bundle {
80
91
timestamp := time .Now ().UTC ().Unix ()
81
92
82
- keys := b . getSortedCreationTokens ( list )
93
+ keys := list . sortedCreationTokens ( )
83
94
84
95
maxTimestamp := keys [len (keys )- 1 ]
85
96
if timestamp <= maxTimestamp {
@@ -100,7 +111,7 @@ func (b *bundleProvider) createDistinctBundle(repo *core.Repository, list *Bundl
100
111
func (b * bundleProvider ) CreateSingletonList (ctx context.Context , bundle Bundle ) * BundleList {
101
112
list := BundleList {1 , "all" , make (map [int64 ]Bundle )}
102
113
103
- addBundleToList (bundle , & list )
114
+ list . addBundle (bundle )
104
115
105
116
return & list
106
117
}
@@ -122,7 +133,7 @@ func (b *bundleProvider) WriteBundleList(ctx context.Context, list *BundleList,
122
133
out , "[bundle]\n \t version = %d\n \t mode = %s\n \n " ,
123
134
list .Version , list .Mode )
124
135
125
- keys := b . getSortedCreationTokens ( list )
136
+ keys := list . sortedCreationTokens ( )
126
137
127
138
for _ , token := range keys {
128
139
bundle := list .Bundles [token ]
@@ -298,7 +309,7 @@ func (b *bundleProvider) CollapseList(ctx context.Context, repo *core.Repository
298
309
return nil
299
310
}
300
311
301
- keys := b . getSortedCreationTokens ( list )
312
+ keys := list . sortedCreationTokens ( )
302
313
303
314
refs := make (map [string ]string )
304
315
@@ -349,14 +360,3 @@ func (b *bundleProvider) CollapseList(ctx context.Context, repo *core.Repository
349
360
list .Bundles [maxTimestamp ] = bundle
350
361
return nil
351
362
}
352
-
353
- func (b * bundleProvider ) getSortedCreationTokens (list * BundleList ) []int64 {
354
- keys := make ([]int64 , 0 , len (list .Bundles ))
355
- for timestamp := range list .Bundles {
356
- keys = append (keys , timestamp )
357
- }
358
-
359
- sort .Slice (keys , func (i , j int ) bool { return keys [i ] < keys [j ] })
360
-
361
- return keys
362
- }
0 commit comments