Skip to content

Commit e53eca7

Browse files
committed
bundles: add 'bundle.heuristic' to bundle list
Include the 'bundle.heuristic' config (value "creationToken" to denote use of the creation token heuristic [1]) in the bundle list. Without this, Git will not use the creation token heuristic to apply incremental bundle updates on fetches after an initial clone. Signed-off-by: Victoria Dye <[email protected]>
1 parent 62f35ce commit e53eca7

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

internal/bundles/bundles.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,19 @@ func NewBundle(repo *core.Repository, timestamp int64) Bundle {
5959
}
6060

6161
type BundleList struct {
62-
Version int
63-
Mode string
64-
Bundles map[int64]Bundle
62+
Version int
63+
Mode string
64+
Heuristic string
65+
Bundles map[int64]Bundle
66+
}
67+
68+
func NewBundleList() *BundleList {
69+
return &BundleList{
70+
Version: 1,
71+
Mode: "any",
72+
Heuristic: "creationToken",
73+
Bundles: make(map[int64]Bundle),
74+
}
6575
}
6676

6777
func (list *BundleList) addBundle(bundle Bundle) {
@@ -125,11 +135,9 @@ func (b *bundleProvider) createDistinctBundle(repo *core.Repository, list *Bundl
125135
}
126136

127137
func (b *bundleProvider) CreateSingletonList(ctx context.Context, bundle Bundle) *BundleList {
128-
list := BundleList{1, "all", make(map[int64]Bundle)}
129-
138+
list := NewBundleList()
130139
list.addBundle(bundle)
131-
132-
return &list
140+
return list
133141
}
134142

135143
// Given a BundleList, write the bundle list content to the web directory.
@@ -161,8 +169,8 @@ func (b *bundleProvider) WriteBundleList(ctx context.Context, list *BundleList,
161169
defer out.Flush()
162170

163171
fmt.Fprintf(
164-
out, "[bundle]\n\tversion = %d\n\tmode = %s\n\n",
165-
list.Version, list.Mode)
172+
out, "[bundle]\n\tversion = %d\n\tmode = %s\n\theuristic = %s\n\n",
173+
list.Version, list.Mode, list.Heuristic)
166174

167175
uriBase := path.Dir(requestUri) + "/"
168176
for _, token := range keys {

internal/bundles/bundles_test.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ var writeBundleListTests = []struct {
3131
{
3232
"Empty bundle list",
3333
&bundles.BundleList{
34-
Version: 1,
35-
Mode: "all",
36-
Bundles: map[int64]bundles.Bundle{},
34+
Version: 1,
35+
Mode: "all",
36+
Heuristic: "creationToken",
37+
Bundles: map[int64]bundles.Bundle{},
3738
},
3839
&core.Repository{
3940
Route: "test/repo",
@@ -44,21 +45,24 @@ var writeBundleListTests = []struct {
4445
`[bundle]`,
4546
` version = 1`,
4647
` mode = all`,
48+
` heuristic = creationToken`,
4749
``,
4850
},
4951
[]string{
5052
`[bundle]`,
5153
` version = 1`,
5254
` mode = all`,
55+
` heuristic = creationToken`,
5356
``,
5457
},
5558
false,
5659
},
5760
{
5861
"Single bundle list",
5962
&bundles.BundleList{
60-
Version: 1,
61-
Mode: "all",
63+
Version: 1,
64+
Mode: "all",
65+
Heuristic: "creationToken",
6266
Bundles: map[int64]bundles.Bundle{
6367
1: {
6468
URI: "/test/myrepo/bundle-1.bundle",
@@ -76,6 +80,7 @@ var writeBundleListTests = []struct {
7680
`[bundle]`,
7781
` version = 1`,
7882
` mode = all`,
83+
` heuristic = creationToken`,
7984
``,
8085
`[bundle "1"]`,
8186
` uri = bundle-1.bundle`,
@@ -86,6 +91,7 @@ var writeBundleListTests = []struct {
8691
`[bundle]`,
8792
` version = 1`,
8893
` mode = all`,
94+
` heuristic = creationToken`,
8995
``,
9096
`[bundle "1"]`,
9197
` uri = myrepo/bundle-1.bundle`,
@@ -97,8 +103,9 @@ var writeBundleListTests = []struct {
97103
{
98104
"Multi-bundle list is sorted by creationToken",
99105
&bundles.BundleList{
100-
Version: 1,
101-
Mode: "all",
106+
Version: 1,
107+
Mode: "all",
108+
Heuristic: "creationToken",
102109
Bundles: map[int64]bundles.Bundle{
103110
2: {
104111
URI: "/test/myrepo/bundle-2.bundle",
@@ -126,6 +133,7 @@ var writeBundleListTests = []struct {
126133
`[bundle]`,
127134
` version = 1`,
128135
` mode = all`,
136+
` heuristic = creationToken`,
129137
``,
130138
`[bundle "1"]`,
131139
` uri = bundle-1.bundle`,
@@ -144,6 +152,7 @@ var writeBundleListTests = []struct {
144152
`[bundle]`,
145153
` version = 1`,
146154
` mode = all`,
155+
` heuristic = creationToken`,
147156
``,
148157
`[bundle "1"]`,
149158
` uri = myrepo/bundle-1.bundle`,

0 commit comments

Comments
 (0)