locking

package
v2.5.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2018 License: MIT Imports: 15 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMatchingLocks is an error returned when no matching locks were
	// able to be resolved
	ErrNoMatchingLocks = errors.New("lfs: no matching locks found")
	// ErrLockAmbiguous is an error returned when multiple matching locks
	// were found
	ErrLockAmbiguous = errors.New("lfs: multiple locks found; ambiguous")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Remote    string
	RemoteRef *git.Ref

	LocalWorkingDir          string
	LocalGitDir              string
	SetLockableFilesReadOnly bool
	// contains filtered or unexported fields
}

Client is the main interface object for the locking package

func NewClient

func NewClient(remote string, lfsClient *lfsapi.Client) (*Client, error)

NewClient creates a new locking client with the given configuration You must call the returned object's `Close` method when you are finished with it

func (*Client) Close

func (c *Client) Close() error

Close this client instance; must be called to dispose of resources

func (*Client) FixAllLockableFileWriteFlags

func (c *Client) FixAllLockableFileWriteFlags() error

FixAllLockableFileWriteFlags recursively scans the repo looking for files which are lockable, and makes sure their write flags are set correctly based on whether they are currently locked or unlocked. Files which are unlocked are made read-only, files which are locked are made writeable. This function can be used after a clone or checkout to ensure that file state correctly reflects the locking state

func (*Client) FixFileWriteFlagsInDir

func (c *Client) FixFileWriteFlagsInDir(dir string, lockablePatterns, unlockablePatterns []string) error

FixFileWriteFlagsInDir scans dir (which can either be a relative dir from the root of the repo, or an absolute dir within the repo) looking for files to change permissions for. If lockablePatterns is non-nil, then any file matching those patterns will be checked to see if it is currently locked by the current committer, and if so it will be writeable, and if not locked it will be read-only. If unlockablePatterns is non-nil, then any file matching those patterns will be made writeable if it is not already. This can be used to reset files to writeable when their 'lockable' attribute is turned off.

func (*Client) FixLockableFileWriteFlags

func (c *Client) FixLockableFileWriteFlags(files []string) error

FixLockableFileWriteFlags checks each file in the provided list, and for those which are lockable, makes sure their write flags are set correctly based on whether they are currently locked or unlocked. Files which are unlocked are made read-only, files which are locked are made writeable. Files which are not lockable are ignored. This function can be used after a clone or checkout to ensure that file state correctly reflects the locking state, and is more efficient than FixAllLockableFileWriteFlags when you know which files changed

func (*Client) GetLockablePatterns

func (c *Client) GetLockablePatterns() []string

GetLockablePatterns returns a list of patterns in .gitattributes which are marked as lockable

func (*Client) IsFileLockable

func (c *Client) IsFileLockable(path string) bool

IsFileLockable returns whether a specific file path is marked as Lockable, ie has the 'lockable' attribute in .gitattributes Lockable patterns are cached once for performance, unless you call RefreshLockablePatterns path should be relative to repository root

func (*Client) IsFileLockedByCurrentCommitter

func (c *Client) IsFileLockedByCurrentCommitter(path string) bool

IsFileLockedByCurrentCommitter returns whether a file is locked by the current user, as cached locally

func (*Client) LockFile

func (c *Client) LockFile(path string) (Lock, error)

LockFile attempts to lock a file on the current remote path must be relative to the root of the repository Returns the lock id if successful, or an error

func (*Client) SearchLocks

func (c *Client) SearchLocks(filter map[string]string, limit int, localOnly bool) ([]Lock, error)

SearchLocks returns a channel of locks which match the given name/value filter If limit > 0 then search stops at that number of locks If localOnly = true, don't query the server & report only own local locks

func (*Client) SetupFileCache

func (c *Client) SetupFileCache(path string) error

func (*Client) UnlockFile

func (c *Client) UnlockFile(path string, force bool) error

UnlockFile attempts to unlock a file on the current remote path must be relative to the root of the repository Force causes the file to be unlocked from other users as well

func (*Client) UnlockFileById

func (c *Client) UnlockFileById(id string, force bool) error

UnlockFileById attempts to unlock a lock with a given id on the current remote Force causes the file to be unlocked from other users as well

func (*Client) VerifiableLocks

func (c *Client) VerifiableLocks(ref *git.Ref, limit int) (ourLocks, theirLocks []Lock, err error)

type Lock

type Lock struct {
	// Id is the unique identifier corresponding to this particular Lock. It
	// must be consistent with the local copy, and the server's copy.
	Id string `json:"id"`
	// Path is an absolute path to the file that is locked as a part of this
	// lock.
	Path string `json:"path"`
	// Owner is the identity of the user that created this lock.
	Owner *User `json:"owner,omitempty"`
	// LockedAt is the time at which this lock was acquired.
	LockedAt time.Time `json:"locked_at"`
}

Lock is a record of a locked file

type LockCache

type LockCache struct {
	// contains filtered or unexported fields
}

func NewLockCache

func NewLockCache(filepath string) (*LockCache, error)

func (*LockCache) Add

func (c *LockCache) Add(l Lock) error

Cache a successful lock for faster local lookup later

func (*LockCache) Clear

func (c *LockCache) Clear()

Clear the cache

func (*LockCache) Locks

func (c *LockCache) Locks() []Lock

Get the list of cached locked files

func (*LockCache) RemoveById

func (c *LockCache) RemoveById(id string) error

Remove a cached lock by id because it's been relinquished

func (*LockCache) RemoveByPath

func (c *LockCache) RemoveByPath(filePath string) error

Remove a cached lock by path becuase it's been relinquished

func (*LockCache) Save

func (c *LockCache) Save() error

Save the cache

type LockCacher

type LockCacher interface {
	Add(l Lock) error
	RemoveByPath(filePath string) error
	RemoveById(id string) error
	Locks() []Lock
	Clear()
	Save() error
}

type User

type User struct {
	// Name is the name of the individual who would like to obtain the
	// lock, for instance: "Rick Sanchez".
	Name string `json:"name"`
}

User represents the owner of a lock.

func NewUser

func NewUser(name string) *User

func (*User) String

func (u *User) String() string

String implements the fmt.Stringer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL