Skip to content

Commit 7205a53

Browse files
authored
add InitInMemory and OpenOrInitOnDisk (#18)
1 parent 26f2fa3 commit 7205a53

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

git/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func switchToBranch(ctx context.Context, repo *Repository, branch Branch) {
4444
}
4545
}
4646

47-
func openOrInitOnDisk(ctx context.Context, path URL, bare bool) *Repository {
47+
func OpenOrInitOnDisk(ctx context.Context, path URL, bare bool) *Repository {
4848
repo, err := git.PlainOpen(string(path))
4949
if err == nil {
5050
return repo

git/embed_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestEmbed(t *testing.T) {
3030
InitPlain(ctx, dir3, true)
3131

3232
embed := func() {
33-
r := initInMemory(ctx)
33+
r := InitInMemory(ctx)
3434
PullAll(ctx, r, URL(dir1))
3535

3636
EmbedOnBranch(
@@ -96,14 +96,14 @@ func populate(ctx context.Context, r *git.Repository, nonce string) {
9696
}
9797

9898
func populateRemote(ctx context.Context, p string, nonce string) {
99-
r := initInMemory(ctx)
99+
r := InitInMemory(ctx)
100100
PullAll(ctx, r, URL(p))
101101
populate(ctx, r, nonce)
102102
PushAll(ctx, r, URL(p))
103103
}
104104

105105
func findFileRemote(ctx context.Context, p string, filepath string) {
106-
r := initInMemory(ctx)
106+
r := InitInMemory(ctx)
107107
PullAll(ctx, r, URL(p))
108108
w := Worktree(ctx, r)
109109
err := w.Checkout(&git.CheckoutOptions{Branch: plumbing.NewBranchReferenceName(string(testEmbedBranch))})

git/nocache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ func (x NoCache) CloneAll(ctx context.Context, addr Address) Cloned {
3030
func (x NoCache) clone(ctx context.Context, addr Address, all bool) Cloned {
3131
var repo *Repository
3232
if x.dir == "" {
33-
repo = initInMemory(ctx)
33+
repo = InitInMemory(ctx)
3434
} else {
3535
p := URL(filepath.Join(x.dir, nonceName()))
3636
base.Infof("materializing repo %v on disk %v\n", addr.Repo, p)
37-
repo = openOrInitOnDisk(ctx, p, false)
37+
repo = OpenOrInitOnDisk(ctx, p, false)
3838
}
3939
c := &clonedNoCache{all: all, addr: addr, repo: repo}
4040
c.Pull(ctx)

git/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Cloned interface {
2525
Tree() *Tree
2626
}
2727

28-
func initInMemory(ctx context.Context) *Repository {
28+
func InitInMemory(ctx context.Context) *Repository {
2929
repo, err := git.Init(memory.NewStorage(), memfs.New())
3030
must.NoError(ctx, err)
3131
return repo

git/replica.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func newReplicaClone(ctx context.Context, cacheDir string, address Address, allB
3131
address: address,
3232
allBranches: allBranches,
3333
ttl: ttl,
34-
diskRepo: openOrInitOnDisk(ctx, replicaPathURL(cacheDir, address), true), // cache must be bare, otherwise checkout branch cannot be pushed,
35-
memRepo: initInMemory(ctx),
34+
diskRepo: OpenOrInitOnDisk(ctx, replicaPathURL(cacheDir, address), true), // cache must be bare, otherwise checkout branch cannot be pushed,
35+
memRepo: InitInMemory(ctx),
3636
}
3737
}
3838

0 commit comments

Comments
 (0)