| 1 | package kvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/gobscip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/" |
| 5 | "ioscip-go gomod github.com/golang/go/src go1.25.0 io/" |
| 6 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 7 | "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/" |
| 8 | |
| 9 | "github.com/git-lfs/git-lfs/v3/errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/" |
| 10 | "github.com/git-lfs/git-lfs/v3/trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/" |
| 11 | ) |
| 12 | |
| 13 | // Store provides an in-memory key/value store which is persisted to |
| 14 | // a file. The file handle itself is not kept locked for the duration; it is |
| 15 | // only locked during load and save, to make it concurrency friendly. When |
| 16 | // saving, the store uses optimistic locking to determine whether the db on disk |
| 17 | // has been modified by another process; in which case it loads the latest |
| 18 | // version and re-applies modifications made during this session. This means |
| 19 | // the Lost Update db concurrency issue is possible; so don't use this if you |
| 20 | // need more DB integrity than Read Committed isolation levels. |
| 21 | type Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store# struct { |
| 22 | // Locks the entire store |
| 23 | muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu. syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.RWMutexscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex# |
| 24 | filenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#filename. string |
| 25 | logscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#log. []changescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/change# |
| 26 | |
| 27 | // This is the persistent data |
| 28 | // version for optimistic locking, this field is incremented with every Save() |
| 29 | versionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#version. int64 |
| 30 | dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#db. map[string]interface{} |
| 31 | } |
| 32 | |
| 33 | // Type of operation; set or remove |
| 34 | type operationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/operation# int |
| 35 | |
| 36 | const ( |
| 37 | // Set a value for a key |
| 38 | setOperationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/setOperation. = operationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/operation#(iota) |
| 39 | // Removed a value for a key |
| 40 | removeOperationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/removeOperation. = operationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/operation#(iota) |
| 41 | ) |
| 42 | |
| 43 | type changescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/change# struct { |
| 44 | opscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/change#op. operationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/operation# |
| 45 | keyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/change#key. string |
| 46 | valuescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/change#value. interface{} |
| 47 | } |
| 48 | |
| 49 | // NewStore creates a new key/value store and initialises it with contents from |
| 50 | // the named file, if it exists |
| 51 | func NewStorescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/NewStore().(filepath string) (*Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#, error) { |
| 52 | kv := &Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#{filenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#filename.: filepath, dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#db.: make(map[string]interface{})} |
| 53 | return kv, kv.loadAndMergeIfNeededscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#loadAndMergeIfNeeded().() |
| 54 | } |
| 55 | |
| 56 | // Set updates the key/value store in memory |
| 57 | // Changes are not persisted until you call Save() |
| 58 | func (k *Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#) Setscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Set().(key string, value interface{}) { |
| 59 | k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 60 | defer k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().() |
| 61 | |
| 62 | k.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#db.[key] = value |
| 63 | k.logChangescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#logChange().(setOperationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/setOperation., key, value) |
| 64 | } |
| 65 | |
| 66 | // Remove removes the key and its value from the store in memory |
| 67 | // Changes are not persisted until you call Save() |
| 68 | func (k *Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#) Removescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Remove().(key string) { |
| 69 | k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 70 | defer k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().() |
| 71 | |
| 72 | delete(k.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#db., key) |
| 73 | k.logChangescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#logChange().(removeOperationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/removeOperation., key, nil) |
| 74 | } |
| 75 | |
| 76 | // RemoveAll removes all entries from the store |
| 77 | // These changes are not persisted until you call Save() |
| 78 | func (k *Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#) RemoveAllscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#RemoveAll().() { |
| 79 | k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 80 | defer k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().() |
| 81 | |
| 82 | // Log all changes |
| 83 | for key, _ := range k.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#db. { |
| 84 | k.logChangescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#logChange().(removeOperationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/removeOperation., key, nil) |
| 85 | } |
| 86 | k.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#db. = make(map[string]interface{}) |
| 87 | } |
| 88 | |
| 89 | // Visit walks through the entire store via a function; return false from |
| 90 | // your visitor function to halt the walk |
| 91 | func (k *Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#) Visitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Visit().(cb func(string, interface{}) bool) { |
| 92 | // Read-only lock |
| 93 | k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().() |
| 94 | defer k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().() |
| 95 | |
| 96 | for k, v := range k.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#db. { |
| 97 | if !cb(k, v) { |
| 98 | break |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // Append a change to the log; mutex must already be locked |
| 104 | func (k *Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#) logChangescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#logChange().(op operationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/operation#, key string, value interface{}) { |
| 105 | k.logscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#log. = append(k.logscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#log., changescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/change#{op, key, value}) |
| 106 | } |
| 107 | |
| 108 | // Get retrieves a value from the store, or nil if it is not present |
| 109 | func (k *Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#) Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Get().(key string) interface{} { |
| 110 | // Read-only lock |
| 111 | k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().() |
| 112 | defer k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().() |
| 113 | |
| 114 | // zero value of interface{} is nil so this does what we want |
| 115 | return k.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#db.[key] |
| 116 | } |
| 117 | |
| 118 | // Save persists the changes made to disk |
| 119 | // If any changes have been written by other code they will be merged |
| 120 | func (k *Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#) Savescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#Save().() error { |
| 121 | k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 122 | defer k.muscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#mu..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().() |
| 123 | |
| 124 | // Short-circuit if we have no changes |
| 125 | if len(k.logscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#log.) == 0 { |
| 126 | return nil |
| 127 | } |
| 128 | |
| 129 | // firstly peek at version; open read/write to keep lock between check & write |
| 130 | f, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.OpenFilescip-go gomod github.com/golang/go/src go1.25.0 os/OpenFile().(k.filenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#filename., osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_RDWRscip-go gomod github.com/golang/go/src go1.25.0 os/O_RDWR.|osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_CREATEscip-go gomod github.com/golang/go/src go1.25.0 os/O_CREATE., 0664) |
| 131 | if err != nil { |
| 132 | return err |
| 133 | } |
| 134 | |
| 135 | defer f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 136 | |
| 137 | // Only try to merge if > 0 bytes, ignore empty files (decoder will fail) |
| 138 | if stat, _ := f.Statscip-go gomod github.com/golang/go/src go1.25.0 os/File#Stat().(); stat.Sizescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Size().() > 0 { |
| 139 | k.loadAndMergeReaderIfNeededscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#loadAndMergeReaderIfNeeded().(f) |
| 140 | // Now we overwrite the file |
| 141 | f.Seekscip-go gomod github.com/golang/go/src go1.25.0 os/File#Seek().(0, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.SeekStartscip-go gomod github.com/golang/go/src go1.25.0 io/SeekStart.) |
| 142 | f.Truncatescip-go gomod github.com/golang/go/src go1.25.0 os/File#Truncate().(0) |
| 143 | } |
| 144 | |
| 145 | k.versionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#version.++ |
| 146 | |
| 147 | enc := gobscip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/.NewEncoderscip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/NewEncoder().(f) |
| 148 | if err := enc.Encodescip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/Encoder#Encode().(k.versionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#version.); err != nil { |
| 149 | return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("error while writing version data to %v: %v", k.filenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#filename., err)) |
| 150 | } |
| 151 | if err := enc.Encodescip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/Encoder#Encode().(k.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#db.); err != nil { |
| 152 | return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("error while writing new key/value data to %v: %v", k.filenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#filename., err)) |
| 153 | } |
| 154 | // Clear log now that it's saved |
| 155 | k.logscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#log. = nil |
| 156 | |
| 157 | return nil |
| 158 | } |
| 159 | |
| 160 | // Reads as little as possible from the passed in file to determine if the |
| 161 | // contents are different from the version already held. If so, reads the |
| 162 | // contents and merges with any outstanding changes. If not, stops early without |
| 163 | // reading the rest of the file |
| 164 | func (k *Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#) loadAndMergeIfNeededscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#loadAndMergeIfNeeded().() error { |
| 165 | stat, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(k.filenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#filename.) |
| 166 | if err != nil { |
| 167 | if osscip-go gomod github.com/golang/go/src go1.25.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/IsNotExist().(err) { |
| 168 | return nil // missing is OK |
| 169 | } |
| 170 | return err |
| 171 | } |
| 172 | // Do nothing if empty file |
| 173 | if stat.Sizescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Size().() == 0 { |
| 174 | return nil |
| 175 | } |
| 176 | |
| 177 | f, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.OpenFilescip-go gomod github.com/golang/go/src go1.25.0 os/OpenFile().(k.filenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#filename., osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_RDONLYscip-go gomod github.com/golang/go/src go1.25.0 os/O_RDONLY., 0664) |
| 178 | if err == nil { |
| 179 | defer f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 180 | return k.loadAndMergeReaderIfNeededscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#loadAndMergeReaderIfNeeded().(f) |
| 181 | } else { |
| 182 | return err |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // As loadAndMergeIfNeeded but lets caller decide how to manage file handles |
| 187 | func (k *Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#) loadAndMergeReaderIfNeededscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#loadAndMergeReaderIfNeeded().(f ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#) error { |
| 188 | var versionOnDisk int64 |
| 189 | // Decode *only* the version field to check whether anyone else has |
| 190 | // modified the db; gob serializes structs in order so it will always be 1st |
| 191 | dec := gobscip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/.NewDecoderscip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/NewDecoder().(f) |
| 192 | err := dec.Decodescip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/Decoder#Decode().(&versionOnDisk) |
| 193 | if err != nil { |
| 194 | return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("problem checking version of key/value data from %v: %v", k.filenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#filename., err)) |
| 195 | } |
| 196 | // Totally uninitialised Version == 0, saved versions are always >=1 |
| 197 | if versionOnDisk != k.versionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#version. { |
| 198 | // Reload data & merge |
| 199 | var dbOnDisk map[string]interface{} |
| 200 | err = dec.Decodescip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/Decoder#Decode().(&dbOnDisk) |
| 201 | if err != nil { |
| 202 | return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("problem reading updated key/value data from %v: %v", k.filenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#filename., err)) |
| 203 | } |
| 204 | k.reapplyChangesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#reapplyChanges().(dbOnDisk) |
| 205 | k.versionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#version. = versionOnDisk |
| 206 | } |
| 207 | return nil |
| 208 | } |
| 209 | |
| 210 | // reapplyChanges replays the changes made since the last load onto baseDb |
| 211 | // and stores the result as our own DB |
| 212 | func (k *Storescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#) reapplyChangesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#reapplyChanges().(baseDb map[string]interface{}) { |
| 213 | for _, change := range k.logscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#log. { |
| 214 | switch change.opscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/change#op. { |
| 215 | case setOperationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/setOperation.: |
| 216 | baseDb[change.keyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/change#key.] = change.valuescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/change#value. |
| 217 | case removeOperationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/removeOperation.: |
| 218 | delete(baseDb, change.keyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/change#key.) |
| 219 | } |
| 220 | } |
| 221 | // Note, log is not cleared here, that only happens on Save since it's a |
| 222 | // list of unsaved changes |
| 223 | k.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/Store#db. = baseDb |
| 224 | |
| 225 | } |
| 226 | |
| 227 | // RegisterTypeForStorage registers a custom type (e.g. a struct) for |
| 228 | // use in the key value store. This is necessary if you intend to pass custom |
| 229 | // structs to Store.Set() rather than primitive types. |
| 230 | func RegisterTypeForStoragescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools/kv`/RegisterTypeForStorage().(val interface{}) { |
| 231 | gobscip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/.Registerscip-go gomod github.com/golang/go/src go1.25.0 `encoding/gob`/Register().(val) |
| 232 | } |