| 1 | package lockingscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/ |
| 2 | |
| 3 | import ( |
| 4 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 5 | |
| 6 | "github.com/git-lfs/git-lfs/v3/tools/kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/" |
| 7 | ) |
| 8 | |
| 9 | const ( |
| 10 | // We want to use a single cache file for integrity, but to make it easy to |
| 11 | // list all locks, prefix the id->path map in a way we can identify (something |
| 12 | // that won't be in a path) |
| 13 | idKeyPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/idKeyPrefix. string = "*id*://" |
| 14 | ) |
| 15 | |
| 16 | type LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache# struct { |
| 17 | kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv. *kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/.Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store# |
| 18 | } |
| 19 | |
| 20 | func NewLockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/NewLockCache().(filepath string) (*LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#, error) { |
| 21 | kv, err := kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/.NewStorescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/NewStore().(filepath) |
| 22 | if err != nil { |
| 23 | return nil, err |
| 24 | } |
| 25 | return &LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#{kv}, nil |
| 26 | } |
| 27 | |
| 28 | // Cache a successful lock for faster local lookup later |
| 29 | func (c *LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#) Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#Add().(l Lockscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock#) error { |
| 30 | // Store reference in both directions |
| 31 | // Path -> Lock |
| 32 | c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..Setscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Set().(l.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock#Path., &l) |
| 33 | // EncodedId -> Lock (encoded so we can easily identify) |
| 34 | c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..Setscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Set().(c.encodeIdKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#encodeIdKey().(l.Idscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock#Id.), &l) |
| 35 | return nil |
| 36 | } |
| 37 | |
| 38 | // Remove a cached lock by path because it's been relinquished |
| 39 | func (c *LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#) RemoveByPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#RemoveByPath().(filePath string) error { |
| 40 | ilock := c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Get().(filePath) |
| 41 | if lock, ok := ilock.(*Lockscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock#); ok && lock != nil { |
| 42 | c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..Removescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Remove().(lock.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock#Path.) |
| 43 | // Id as key is encoded |
| 44 | c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..Removescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Remove().(c.encodeIdKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#encodeIdKey().(lock.Idscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock#Id.)) |
| 45 | } |
| 46 | return nil |
| 47 | } |
| 48 | |
| 49 | // Remove a cached lock by id because it's been relinquished |
| 50 | func (c *LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#) RemoveByIdscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#RemoveById().(id string) error { |
| 51 | // Id as key is encoded |
| 52 | idkey := c.encodeIdKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#encodeIdKey().(id) |
| 53 | ilock := c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Get().(idkey) |
| 54 | if lock, ok := ilock.(*Lockscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock#); ok && lock != nil { |
| 55 | c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..Removescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Remove().(idkey) |
| 56 | c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..Removescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Remove().(lock.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock#Path.) |
| 57 | } |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | // Get the list of cached locked files |
| 62 | func (c *LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#) Locksscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#Locks().() []Lockscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock# { |
| 63 | var locks []Lockscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock# |
| 64 | c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..Visitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Visit().(func(key string, val interface{}) bool { |
| 65 | // Only report file->id entries not reverse |
| 66 | if !c.isIdKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#isIdKey().(key) { |
| 67 | lock := val.(*Lockscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Lock#) |
| 68 | locks = append(locks, *lock) |
| 69 | } |
| 70 | return true // continue |
| 71 | }) |
| 72 | return locks |
| 73 | } |
| 74 | |
| 75 | // Clear the cache |
| 76 | func (c *LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#) Clearscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#Clear().() { |
| 77 | c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..RemoveAllscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#RemoveAll().() |
| 78 | } |
| 79 | |
| 80 | // Save the cache |
| 81 | func (c *LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#) Savescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#Save().() error { |
| 82 | return c.kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#kv..Savescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Save().() |
| 83 | } |
| 84 | |
| 85 | func (c *LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#) encodeIdKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#encodeIdKey().(id string) string { |
| 86 | // Safety against accidents |
| 87 | if !c.isIdKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#isIdKey().(id) { |
| 88 | return idKeyPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/idKeyPrefix. + id |
| 89 | } |
| 90 | return id |
| 91 | } |
| 92 | |
| 93 | func (c *LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#) decodeIdKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#decodeIdKey().(key string) string { |
| 94 | // Safety against accidents |
| 95 | if c.isIdKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#isIdKey().(key) { |
| 96 | return key[len(idKeyPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/idKeyPrefix.):] |
| 97 | } |
| 98 | return key |
| 99 | } |
| 100 | |
| 101 | func (c *LockCachescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#) isIdKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/LockCache#isIdKey().(key string) bool { |
| 102 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(key, idKeyPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/idKeyPrefix.) |
| 103 | } |