MCPcopy
hub / github.com/git-lfs/git-lfs / SearchLocksVerifiable

Method SearchLocksVerifiable

locking/locks.go:242–320  ·  view source on GitHub ↗
(limit int, cached bool)

Source from the content-addressed store, hash-verified

240}
241
242func (c *Client) SearchLocksVerifiable(limit int, cached bool) (ourLocks, theirLocks []Lock, err error) {
243 ourLocks = make([]Lock, 0, limit)
244 theirLocks = make([]Lock, 0, limit)
245
246 if cached {
247 if limit != 0 {
248 return []Lock{}, []Lock{}, errors.New(tr.Tr.Get("can't search cached locks when limit is set"))
249 }
250
251 locks := &lockVerifiableList{}
252 err := c.readLocksFromCacheFile("verifiable", func(decoder *json.Decoder) error {
253 return decoder.Decode(&locks)
254 })
255 return locks.Ours, locks.Theirs, err
256 } else {
257 var requestRef *lockRef
258 if c.RemoteRef != nil {
259 requestRef = &lockRef{Name: c.RemoteRef.Refspec()}
260 }
261
262 body := &lockVerifiableRequest{
263 Ref: requestRef,
264 Limit: limit,
265 }
266
267 c.cache.Clear()
268
269 for {
270 list, status, err := c.client.SearchVerifiable(c.Remote, body)
271 switch status {
272 case http.StatusNotFound, http.StatusNotImplemented:
273 return ourLocks, theirLocks, errors.NewNotImplementedError(err)
274 case http.StatusForbidden:
275 return ourLocks, theirLocks, errors.NewAuthError(err)
276 }
277
278 if err != nil {
279 return ourLocks, theirLocks, err
280 }
281
282 if list.Message != "" {
283 if len(list.RequestID) > 0 {
284 tracerx.Printf("Server Request ID: %s", list.RequestID)
285 }
286 return ourLocks, theirLocks, errors.New(tr.Tr.Get("server error searching locks: %s", list.Message))
287 }
288
289 for _, l := range list.Ours {
290 c.cache.Add(l)
291 ourLocks = append(ourLocks, l)
292 if limit > 0 && (len(ourLocks)+len(theirLocks)) >= limit {
293 return ourLocks, theirLocks, nil
294 }
295 }
296
297 for _, l := range list.Theirs {
298 c.cache.Add(l)
299 theirLocks = append(theirLocks, l)

Callers 4

TestRefreshCacheFunction · 0.95
locksCommandFunction · 0.80
VerifyMethod · 0.80

Calls 11

writeLocksToCacheFileMethod · 0.95
EncodeLocksVerifiableMethod · 0.95
NewFunction · 0.92
NewNotImplementedErrorFunction · 0.92
NewAuthErrorFunction · 0.92
RefspecMethod · 0.80
GetMethod · 0.65
ClearMethod · 0.65
SearchVerifiableMethod · 0.65
AddMethod · 0.65

Tested by 2

TestRefreshCacheFunction · 0.76