localstorage: remove global Objects()

This commit is contained in:
rick olson 2017-10-25 11:51:01 -06:00
parent f09480e812
commit 5033c1a57b
6 changed files with 12 additions and 15 deletions

@ -22,10 +22,6 @@ var (
checkedTempDir string
)
func Objects() *LocalStorage {
return objects
}
func InitStorage(cfg *config.Configuration) error {
if len(cfg.LocalGitStorageDir()) == 0 || len(cfg.LocalGitDir()) == 0 {
return notInRepoErr

@ -7,6 +7,7 @@ import (
"strings"
"sync"
"github.com/git-lfs/git-lfs/fs"
"github.com/git-lfs/git-lfs/lfsapi"
"github.com/rubyist/tracerx"
)
@ -15,6 +16,7 @@ import (
// process transfers with N workers handling an oid each, and which wait for
// authentication to succeed on one worker before proceeding
type adapterBase struct {
fs *fs.Filesystem
name string
direction Direction
transferImpl transferImplementation
@ -49,8 +51,9 @@ type transferImplementation interface {
DoTransfer(ctx interface{}, t *Transfer, cb ProgressCallback, authOkFunc func()) error
}
func newAdapterBase(name string, dir Direction, ti transferImplementation) *adapterBase {
func newAdapterBase(f *fs.Filesystem, name string, dir Direction, ti transferImplementation) *adapterBase {
return &adapterBase{
fs: f,
name: name,
direction: dir,
transferImpl: ti,

@ -10,7 +10,6 @@ import (
"strconv"
"github.com/git-lfs/git-lfs/errors"
"github.com/git-lfs/git-lfs/localstorage"
"github.com/git-lfs/git-lfs/tools"
"github.com/rubyist/tracerx"
)
@ -28,7 +27,7 @@ func (a *basicDownloadAdapter) tempDir() string {
// Must be dedicated to this adapter as deleted by ClearTempStorage
// Also make local to this repo not global, and separate to localstorage temp,
// which gets cleared at the end of every invocation
d := filepath.Join(localstorage.Objects().RootDir, "incomplete")
d := filepath.Join(a.fs.LFSStorageDir, "incomplete")
if err := os.MkdirAll(d, 0755); err != nil {
return os.TempDir()
}
@ -222,7 +221,7 @@ func configureBasicDownloadAdapter(m *Manifest) {
m.RegisterNewAdapterFunc(BasicAdapterName, Download, func(name string, dir Direction) Adapter {
switch dir {
case Download:
bd := &basicDownloadAdapter{newAdapterBase(name, dir, nil)}
bd := &basicDownloadAdapter{newAdapterBase(m.fs, name, dir, nil)}
// self implements impl
bd.transferImpl = bd
return bd

@ -161,7 +161,7 @@ func configureBasicUploadAdapter(m *Manifest) {
m.RegisterNewAdapterFunc(BasicAdapterName, Upload, func(name string, dir Direction) Adapter {
switch dir {
case Upload:
bu := &basicUploadAdapter{newAdapterBase(name, dir, nil)}
bu := &basicUploadAdapter{newAdapterBase(m.fs, name, dir, nil)}
// self implements impl
bu.transferImpl = bu
return bu

@ -12,6 +12,7 @@ import (
"time"
"github.com/git-lfs/git-lfs/errors"
"github.com/git-lfs/git-lfs/fs"
"github.com/git-lfs/git-lfs/tools"
"github.com/git-lfs/git-lfs/subprocess"
@ -124,7 +125,6 @@ func (a *customAdapter) ClearTempStorage() error {
}
func (a *customAdapter) WorkerStarting(workerNum int) (interface{}, error) {
// Start a process per worker
// If concurrent = false we have already dialled back workers to 1
a.Trace("xfer: starting up custom transfer process %q for worker %d", a.name, workerNum)
@ -202,7 +202,6 @@ func (a *customAdapter) readResponse(ctx *customAdapterWorkerContext) (*customAd
// exchangeMessage sends a message to a process and reads a response if resp != nil
// Only fatal errors to communicate return an error, errors may be embedded in reply
func (a *customAdapter) exchangeMessage(ctx *customAdapterWorkerContext, req interface{}) (*customAdapterResponseMessage, error) {
err := a.sendMessage(ctx, req)
if err != nil {
return nil, err
@ -341,8 +340,8 @@ func (a *customAdapter) DoTransfer(ctx interface{}, t *Transfer, cb ProgressCall
return nil
}
func newCustomAdapter(name string, dir Direction, path, args string, concurrent, standalone bool) *customAdapter {
c := &customAdapter{newAdapterBase(name, dir, nil), path, args, concurrent, 3, standalone}
func newCustomAdapter(f *fs.Filesystem, name string, dir Direction, path, args string, concurrent, standalone bool) *customAdapter {
c := &customAdapter{newAdapterBase(f, name, dir, nil), path, args, concurrent, 3, standalone}
// self implements impl
c.transferImpl = c
return c
@ -372,7 +371,7 @@ func configureCustomAdapters(git Env, m *Manifest) {
// Separate closure for each since we need to capture vars above
newfunc := func(name string, dir Direction) Adapter {
standalone := m.standaloneTransferAgent != ""
return newCustomAdapter(name, dir, path, args, concurrent, standalone)
return newCustomAdapter(m.fs, name, dir, path, args, concurrent, standalone)
}
if direction == "download" || direction == "both" {

@ -165,7 +165,7 @@ func configureTusAdapter(m *Manifest) {
m.RegisterNewAdapterFunc(TusAdapterName, Upload, func(name string, dir Direction) Adapter {
switch dir {
case Upload:
bu := &tusUploadAdapter{newAdapterBase(name, dir, nil)}
bu := &tusUploadAdapter{newAdapterBase(m.fs, name, dir, nil)}
// self implements impl
bu.transferImpl = bu
return bu