Store working/git dirs in lock client to avoid using config in many places
`locking` still depends on `config` but will be refactored out later
This commit is contained in:
parent
43acc16196
commit
6f3aa52fc7
@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/git-lfs/git-lfs/config"
|
||||
"github.com/git-lfs/git-lfs/errors"
|
||||
"github.com/git-lfs/git-lfs/filepathfilter"
|
||||
"github.com/git-lfs/git-lfs/git"
|
||||
@ -43,7 +42,7 @@ func (c *Client) refreshLockablePatterns() {
|
||||
// Always make non-nil even if empty
|
||||
c.lockablePatterns = make([]string, 0, 10)
|
||||
|
||||
paths := git.GetAttributePaths(config.LocalWorkingDir, config.LocalGitDir)
|
||||
paths := git.GetAttributePaths(c.LocalWorkingDir, c.LocalGitDir)
|
||||
for _, p := range paths {
|
||||
if p.Lockable {
|
||||
c.lockablePatterns = append(c.lockablePatterns, p.Path)
|
||||
@ -68,7 +67,7 @@ func (c *Client) IsFileLockable(path string) bool {
|
||||
// This function can be used after a clone or checkout to ensure that file
|
||||
// state correctly reflects the locking state
|
||||
func (c *Client) FixAllLockableFileWriteFlags() error {
|
||||
return c.fixFileWriteFlags(config.LocalWorkingDir, config.LocalWorkingDir, c.getLockableFilter(), nil)
|
||||
return c.fixFileWriteFlags(c.LocalWorkingDir, c.LocalWorkingDir, c.getLockableFilter(), nil)
|
||||
}
|
||||
|
||||
// FixFileWriteFlagsInDir scans dir (which can either be a relative dir
|
||||
@ -89,7 +88,7 @@ func (c *Client) FixFileWriteFlagsInDir(dir string, lockablePatterns, unlockable
|
||||
|
||||
absPath := dir
|
||||
if !filepath.IsAbs(dir) {
|
||||
absPath = filepath.Join(config.LocalWorkingDir, dir)
|
||||
absPath = filepath.Join(c.LocalWorkingDir, dir)
|
||||
}
|
||||
stat, err := os.Stat(absPath)
|
||||
if err != nil {
|
||||
@ -108,7 +107,7 @@ func (c *Client) FixFileWriteFlagsInDir(dir string, lockablePatterns, unlockable
|
||||
unlockableFilter = filepathfilter.New(unlockablePatterns, nil)
|
||||
}
|
||||
|
||||
return c.fixFileWriteFlags(absPath, config.LocalWorkingDir, lockableFilter, unlockableFilter)
|
||||
return c.fixFileWriteFlags(absPath, c.LocalWorkingDir, lockableFilter, unlockableFilter)
|
||||
}
|
||||
|
||||
// Internal implementation of fixing file write flags with precompiled filters
|
||||
|
@ -35,6 +35,9 @@ type Client struct {
|
||||
lockablePatterns []string
|
||||
lockableFilter *filepathfilter.Filter
|
||||
lockableMutex sync.Mutex
|
||||
|
||||
LocalWorkingDir string
|
||||
LocalGitDir string
|
||||
}
|
||||
|
||||
// NewClient creates a new locking client with the given configuration
|
||||
@ -54,7 +57,13 @@ func NewClient(cfg *config.Configuration) (*Client, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Client{cfg: cfg, apiClient: apiClient, cache: cache}, nil
|
||||
|
||||
return &Client{
|
||||
cfg: cfg,
|
||||
apiClient: apiClient,
|
||||
cache: cache,
|
||||
LocalWorkingDir: config.LocalWorkingDir,
|
||||
LocalGitDir: config.LocalGitDir}, nil
|
||||
}
|
||||
|
||||
// Close this client instance; must be called to dispose of resources
|
||||
|
Loading…
Reference in New Issue
Block a user