Skip to content

Commit 7e70af8

Browse files
committed
bundles: consolidate 'Bundle' creation logic
Create a 'NewBundle()' function, which creates a new 'Bundle' instance from a given repository and timestamp. Replace all manual creation of 'Bundle{}'. Note that this includes a minor functional change - previously, the base bundle created by 'CollapseList()' was named 'base-<timestamp>.bundle'; now, that bundle will be named 'bundle-<timestamp>.bundle', consistent with all other instances of bundle creation. The name doesn't have any bearing on bundle server functionality, so the naming convention can be updated without breaking any existing bundle servers. Signed-off-by: Victoria Dye <[email protected]>
1 parent 184dbfd commit 7e70af8

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

internal/bundles/bundles.go

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"encoding/json"
77
"fmt"
88
"os"
9+
"path"
10+
"path/filepath"
911
"sort"
1012
"strconv"
1113
"strings"
@@ -33,6 +35,15 @@ type Bundle struct {
3335
CreationToken int64
3436
}
3537

38+
func NewBundle(repo *core.Repository, timestamp int64) Bundle {
39+
bundleName := fmt.Sprintf("bundle-%d.bundle", timestamp)
40+
return Bundle{
41+
URI: path.Join(".", bundleName),
42+
Filename: filepath.Join(repo.WebDir, bundleName),
43+
CreationToken: timestamp,
44+
}
45+
}
46+
3647
type BundleList struct {
3748
Version int
3849
Mode string
@@ -80,16 +91,7 @@ func NewBundleProvider(
8091
}
8192

8293
func (b *bundleProvider) CreateInitialBundle(ctx context.Context, repo *core.Repository) Bundle {
83-
timestamp := time.Now().UTC().Unix()
84-
bundleName := "bundle-" + fmt.Sprint(timestamp) + ".bundle"
85-
bundleFile := repo.WebDir + "/" + bundleName
86-
bundle := Bundle{
87-
URI: "./" + bundleName,
88-
Filename: bundleFile,
89-
CreationToken: timestamp,
90-
}
91-
92-
return bundle
94+
return NewBundle(repo, time.Now().UTC().Unix())
9395
}
9496

9597
func (b *bundleProvider) createDistinctBundle(repo *core.Repository, list *BundleList) Bundle {
@@ -102,15 +104,7 @@ func (b *bundleProvider) createDistinctBundle(repo *core.Repository, list *Bundl
102104
timestamp = maxTimestamp + 1
103105
}
104106

105-
bundleName := "bundle-" + fmt.Sprint(timestamp) + ".bundle"
106-
bundleFile := repo.WebDir + "/" + bundleName
107-
bundle := Bundle{
108-
URI: "./" + bundleName,
109-
Filename: bundleFile,
110-
CreationToken: timestamp,
111-
}
112-
113-
return bundle
107+
return NewBundle(repo, timestamp)
114108
}
115109

116110
func (b *bundleProvider) CreateSingletonList(ctx context.Context, bundle Bundle) *BundleList {
@@ -365,11 +359,7 @@ func (b *bundleProvider) CollapseList(ctx context.Context, repo *core.Repository
365359
// branches that were never merged and may have been force-pushed or
366360
// deleted.
367361

368-
bundle := Bundle{
369-
CreationToken: maxTimestamp,
370-
Filename: fmt.Sprintf("%s/base-%d.bundle", repo.WebDir, maxTimestamp),
371-
URI: fmt.Sprintf("./base-%d.bundle", maxTimestamp),
372-
}
362+
bundle := NewBundle(repo, maxTimestamp)
373363

374364
err := b.gitHelper.CreateBundleFromRefs(ctx, repo.RepoDir, bundle.Filename, refs)
375365
if err != nil {

0 commit comments

Comments
 (0)